113 double eval( ConstLabelReference target, ConstOutputReference prediction)
const{
114 if ( prediction.size() == 1 )
117 double label = 2.0 * target - 1;
118 double exponential = std::exp( -label * prediction(0) );
119 return evalError(label,exponential,prediction(0 ));
126 double maximum = max(prediction);
127 double logNorm = sum(exp(prediction-maximum));
128 logNorm = std::log(logNorm) + maximum;
129 return logNorm - prediction(target);
133 double evalDerivative(UIntVector
const& target, BatchOutputType
const& prediction, BatchOutputType& gradient)
const {
134 gradient.resize(prediction.size1(),prediction.size2());
135 if ( prediction.size2() == 1 )
138 for(std::size_t i = 0; i != prediction.size1(); ++i){
140 double label = 2 *
static_cast<double>(target(i)) - 1;
141 double exponential = std::exp ( -label * prediction (i, 0 ) );
142 double sigmoid = 1.0/(1.0+exponential);
143 gradient ( i,0 ) = -label * (1.0 -
sigmoid);
144 error+=evalError(label,exponential,prediction (i, 0 ));
149 for(std::size_t i = 0; i != prediction.size1(); ++i){
151 auto gradRow=row(gradient,i);
158 double maximum = max(row(prediction,i));
159 noalias(gradRow) = exp(row(prediction,i) - maximum);
160 double norm = sum(gradRow);
162 gradient(i,target(i)) -= 1;
163 error+=std::log(norm) - prediction(i,target(i))+maximum;
169 gradient.resize(prediction.size());
170 if ( prediction.size() == 1 ){
172 double label = 2.0 * target - 1;
173 double exponential = std::exp ( - label * prediction(0));
174 double sigmoid = 1.0/(1.0+exponential);
175 gradient(0) = -label * (1.0 -
sigmoid);
176 return evalError(label,exponential,prediction(0));
185 double maximum = max(prediction);
186 noalias(gradient) = exp(prediction - maximum);
187 double norm = sum(gradient);
189 gradient(target) -= 1;
190 return std::log(norm) - prediction(target) + maximum;
195 ConstLabelReference target, ConstOutputReference prediction,
196 BatchOutputType& gradient,MatrixType & hessian
198 gradient.resize(prediction.size());
199 hessian.resize(prediction.size(),prediction.size());
200 if ( prediction.size() == 1 )
203 double label = 2 *
static_cast<double>(target) - 1;
204 double exponential = std::exp ( -label * prediction ( 0 ) );
205 double sigmoid = 1.0/(1.0+exponential);
206 gradient ( 0 ) = -label * (1.0-
sigmoid);
208 return evalError(label,exponential,prediction ( 0 ));
218 double maximum = max(prediction);
219 noalias(gradient) = exp(prediction-maximum);
220 double norm = sum(gradient);
223 noalias(hessian)=-outer_prod(gradient,gradient);
224 noalias(diag(hessian)) += gradient;
225 gradient(target) -= 1;
227 return std::log(norm) - prediction(target) - maximum;