MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Loss.hpp
Go to the documentation of this file.
1 
25 #ifndef LOSS_HPP_
26 #define LOSS_HPP_
27 
28 #include <types/MatrixTypes.hpp>
29 
30 namespace mic {
31 namespace neural_nets {
32 namespace loss {
33 
40 template <typename dtype=float>
41 class Loss {
42 public:
46  virtual dtype calculateLoss (mic::types::MatrixPtr<dtype> target_y_, mic::types::MatrixPtr<dtype> predicted_y_) = 0;
47 
51  virtual dtype calculateMeanLoss (mic::types::MatrixPtr<dtype> target_y_, mic::types::MatrixPtr<dtype> predicted_y_) {
52  return calculateLoss(target_y_, predicted_y_) / predicted_y_->cols();
53  }
54 
58  virtual mic::types::MatrixPtr<dtype> calculateGradient (mic::types::MatrixPtr<dtype> target_y_, mic::types::MatrixPtr<dtype> predicted_y_) = 0;
59 
60 };
61 
62 } //: loss
63 } //: neural_nets
64 } //: mic
65 
66 #endif /* LOSS_HPP_ */
virtual dtype calculateLoss(mic::types::MatrixPtr< dtype > target_y_, mic::types::MatrixPtr< dtype > predicted_y_)=0
Function calculating loss - abstract.
Abstract class representing a loss function. Defines interfaces.
Definition: Loss.hpp:41
virtual mic::types::MatrixPtr< dtype > calculateGradient(mic::types::MatrixPtr< dtype > target_y_, mic::types::MatrixPtr< dtype > predicted_y_)=0
Function calculating gradient - abstract.
virtual dtype calculateMeanLoss(mic::types::MatrixPtr< dtype > target_y_, mic::types::MatrixPtr< dtype > predicted_y_)
Calculates mean loss (i.e. divides the loss by the size of batch) - ACE for cross-entropy or MSE for ...
Definition: Loss.hpp:51