31 #ifndef SHARK_OBJECTIVEFUNCTIONS_LOSS_HINGELOSS_H 32 #define SHARK_OBJECTIVEFUNCTIONS_LOSS_HINGELOSS_H 67 {
return "HingeLoss"; }
72 std::size_t numInputs = labels.size();
77 if(predictions.size2() == 1){
78 for(std::size_t i = 0; i != numInputs;++i){
80 double y = 2.0*labels(i)-1.0;
81 error += std::max(0.0,1.0-y*predictions(i,0));
86 for(std::size_t i = 0; i != numInputs;++i){
88 for(std::size_t o = 0; o != predictions.size2(); ++o){
89 if(o == labels(i))
continue;
90 error += std::max(0.0,2.0 - predictions(i,labels(i))+predictions(i,o));
100 std::size_t numInputs = labels.size();
101 std::size_t outputDim = predictions.size2();
104 gradient.resize(numInputs,outputDim);
109 for(std::size_t i = 0; i != numInputs; ++i){
110 double y = 2.0*labels(i)-1.0;
111 double sampleLoss = std::max(0.0,1.0-y*predictions(i,0));
119 for(std::size_t i = 0; i != numInputs;++i){
121 for(std::size_t o = 0; o != predictions.size2();++o){
122 if( o == labels(i))
continue;
123 double sampleLoss = std::max(0.0, 2.0 - predictions(i,labels(i)) + predictions(i,o));
126 gradient(i,labels(i)) -= 0.5;