13 #ifndef MLPACK_METHODS_ANN_LOSS_FUNCTION_HINGE_LOSS_IMPL_HPP 14 #define MLPACK_METHODS_ANN_LOSS_FUNCTION_HINGE_LOSS_IMPL_HPP 22 template<
typename InputDataType,
typename OutputDataType>
29 template<
typename InputDataType,
typename OutputDataType>
30 template<
typename PredictionType,
typename TargetType>
31 typename PredictionType::elem_type
33 const PredictionType& prediction,
34 const TargetType& target)
36 TargetType temp = target - (target == 0);
37 TargetType temp_zeros(size(target), arma::fill::zeros);
39 PredictionType loss = arma::max(temp_zeros, 1 - prediction % temp);
41 typename PredictionType::elem_type lossSum = arma::accu(loss);
46 return lossSum / loss.n_elem;
49 template<
typename InputDataType,
typename OutputDataType>
50 template<
typename PredictionType,
typename TargetType,
typename LossType>
52 const PredictionType& prediction,
53 const TargetType& target,
56 TargetType temp = target - (target == 0);
57 loss = (prediction < (1 / temp)) % -temp;
60 loss /= target.n_elem;
63 template<
typename InputDataType,
typename OutputDataType>
64 template<
typename Archive>
69 ar(CEREAL_NVP(reduction));
HingeLoss(const bool reduction=true)
Create HingeLoss object.
Definition: hinge_loss_impl.hpp:23
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void Backward(const PredictionType &prediction, const TargetType &target, LossType &loss)
Ordinary feed backward pass of a neural network.
Definition: hinge_loss_impl.hpp:51
PredictionType::elem_type Forward(const PredictionType &prediction, const TargetType &target)
Computes the Hinge loss function.
Definition: hinge_loss_impl.hpp:32
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: hinge_loss_impl.hpp:65