73 std::size_t numInputs = labels.size();
78 if(predictions.size2() == 1){
79 for(std::size_t i = 0; i != numInputs;++i){
81 double y = 2.0*labels(i)-1.0;
82 error +=
sqr(std::max(0.0,1.0-y*predictions(i,0)));
87 for(std::size_t i = 0; i != numInputs;++i){
89 for(std::size_t o = 0; o != predictions.size2();++o){
90 if( o == labels(i))
continue;
91 error +=
sqr(std::max(0.0,2.0 - predictions(i,labels(i))+predictions(i,o)));
101 std::size_t numInputs = labels.size();
102 std::size_t outputDim = predictions.size2();
105 gradient.resize(numInputs,outputDim);
110 for(std::size_t i = 0; i != numInputs; ++i){
111 double y = 2.0*labels(i)-1.0;
112 double sampleLoss = std::max(0.0,1.0-y*predictions(i,0));
114 gradient(i,0) = -y*sampleLoss;
115 error +=
sqr(sampleLoss);
120 for(std::size_t i = 0; i != numInputs;++i){
122 for(std::size_t o = 0; o != predictions.size2();++o){
123 if( o == labels(i))
continue;
124 double sampleLoss = std::max(0.0,2.0 - predictions(i,labels(i))+predictions(i,o));
126 gradient(i,o) = sampleLoss*0.25;
127 gradient(i,labels(i)) -= sampleLoss*0.25;
129 error+=
sqr(sampleLoss);