soft_margin_loss.hpp
Go to the documentation of this file.
1 
16 #ifndef MLPACK_ANN_LOSS_FUNCTION_SOFT_MARGIN_LOSS_HPP
17 #define MLPACK_ANN_LOSS_FUNCTION_SOFT_MARGIN_LOSS_HPP
18 
19 #include <mlpack/prereqs.hpp>
20 
21 namespace mlpack {
22 namespace ann {
23 
30 template <
31  typename InputDataType = arma::mat,
32  typename OutputDataType = arma::mat
33 >
35 {
36  public:
46  SoftMarginLoss(const bool reduction = true);
47 
55  template<typename PredictionType, typename TargetType>
56  typename PredictionType::elem_type Forward(const PredictionType& prediction,
57  const TargetType& target);
58 
67  template<typename PredictionType, typename TargetType, typename LossType>
68  void Backward(const PredictionType& prediction,
69  const TargetType& target,
70  LossType& loss);
71 
73  OutputDataType& OutputParameter() const { return outputParameter; }
75  OutputDataType& OutputParameter() { return outputParameter; }
76 
78  bool Reduction() const { return reduction; }
80  bool& Reduction() { return reduction; }
81 
85  template<typename Archive>
86  void serialize(Archive& ar, const uint32_t version);
87 
88  private:
90  OutputDataType outputParameter;
91 
93  bool reduction;
94 }; // class SoftMarginLoss
95 
96 } // namespace ann
97 } // namespace mlpack
98 
99 // include implementation.
100 #include "soft_margin_loss_impl.hpp"
101 
102 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
void serialize(Archive &ar, const uint32_t version)
Serialize the layer.
The core includes that mlpack expects; standard C++ includes and Armadillo.
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Soft Margin Loss function.
OutputDataType & OutputParameter() const
Get the output parameter.
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
bool Reduction() const
Get the type of reduction used.
bool & Reduction()
Modify the type of reduction used.
SoftMarginLoss(const bool reduction=true)
Create the SoftMarginLoss object.
OutputDataType & OutputParameter()
Modify the output parameter.