18 std::string
getType() {
return "squared"; }
22 if (prediction <= sd->max_label && prediction >= sd->
min_label)
24 float example_loss = (prediction - label) * (prediction - label);
27 else if (prediction < sd->min_label)
40 float getUpdate(
float prediction,
float label,
float update_scale,
float pred_per_update)
42 if (update_scale * pred_per_update < 1e-6)
48 return 2.f * (label - prediction) * update_scale;
50 return (label - prediction) * (1.f -
correctedExp(-2.
f * update_scale * pred_per_update)) / pred_per_update;
55 return 2.f * (label - prediction) * update_scale;
62 return log((alternative - prediction) / (alternative - t)) / eta_t;
65 float getSquareGrad(
float prediction,
float label) {
return 4.f * (prediction - label) * (prediction - label); }
68 if (prediction < sd->min_label)
72 return 2.f * (prediction - label);
76 if (prediction <= sd->max_label && prediction >= sd->
min_label)
86 std::string
getType() {
return "classic"; }
90 float example_loss = (prediction - label) * (prediction - label);
94 float getUpdate(
float prediction,
float label,
float update_scale,
float )
96 return 2.f * (label - prediction) * update_scale;
101 return 2.f * (label - prediction) * update_scale;
108 return (t - prediction) / ((alternative - prediction) * eta_t);
111 float getSquareGrad(
float prediction,
float label) {
return 4.f * (prediction - label) * (prediction - label); }
123 if (label != -1.
f && label != 1.
f)
124 std::cout <<
"You are using label " << label <<
" not -1 or 1 as loss function expects!" << std::endl;
125 float e = 1 - label * prediction;
126 return (e > 0) ? e : 0;
129 float getUpdate(
float prediction,
float label,
float update_scale,
float pred_per_update)
131 if (label * prediction >= 1)
133 float err = 1 - label * prediction;
134 return label * (update_scale * pred_per_update < err ? update_scale : err / pred_per_update);
139 if (label * prediction >= 1)
141 return label * update_scale;
164 if (label != -1.
f && label != 1.
f)
165 std::cout <<
"You are using label " << label <<
" not -1 or 1 as loss function expects!" << std::endl;
169 float getUpdate(
float prediction,
float label,
float update_scale,
float pred_per_update)
173 if (update_scale * pred_per_update < 1e-6)
178 return label * update_scale / (1 + d);
180 x = update_scale * pred_per_update + label * prediction + d;
182 return -(label * w + prediction) / pred_per_update;
188 return label * update_scale / (1 + d);
198 double w = x >= 1. ? 0.86 * x + 0.01 :
correctedExp(0.8 * x - 0.65);
199 double r = x >= 1. ? x - log(w) - w : 0.2 * x + 0.65 - w;
201 double u = 2. * t * (t + 2. * r / 3.);
202 return (
float)(w * (1. + r / t * (u - r) / (u - 2. * r)) - x);
207 float z = -fabs(prediction);
213 float v = -label / (1 +
correctedExp(label * prediction));
240 float e = label - prediction;
244 return -(1 - tau) * e;
247 float getUpdate(
float prediction,
float label,
float update_scale,
float pred_per_update)
249 float err = label - prediction;
252 float normal = update_scale * pred_per_update;
255 normal = tau * normal;
256 return (normal < err ? tau * update_scale : err / pred_per_update);
260 normal = -(1 - tau) * normal;
261 return (normal > err ? (tau - 1) * update_scale : err / pred_per_update);
267 float err = label - prediction;
271 return tau * update_scale;
272 return -(1 - tau) * update_scale;
283 return (t - prediction) / (eta_t * v);
288 float e = label - prediction;
291 return e > 0 ? -tau : (1 - tau);
313 std::cout <<
"You are using label " << label <<
" but loss function expects label >= 0!" << std::endl;
314 float exp_prediction = expf(prediction);
316 return 2 * (label * (logf(label + 1e-6
f) - prediction) - (label - exp_prediction));
319 float getUpdate(
float prediction,
float label,
float update_scale,
float pred_per_update)
321 float exp_prediction = expf(prediction);
324 return label * update_scale -
325 log1p(exp_prediction * expm1(label * update_scale * pred_per_update) / label) / pred_per_update;
329 return -log1p(exp_prediction * update_scale * pred_per_update) / pred_per_update;
335 float exp_prediction = expf(prediction);
336 return (label - exp_prediction) * update_scale;
341 THROW(
"Active learning not supported by poisson loss");
346 float exp_prediction = expf(prediction);
347 return (exp_prediction - label) * (exp_prediction - label);
352 float exp_prediction = expf(prediction);
353 return (exp_prediction - label);
358 float exp_prediction = expf(prediction);
359 return exp_prediction;
365 if (funcName.compare(
"squared") == 0 || funcName.compare(
"Huber") == 0)
367 else if (funcName.compare(
"classic") == 0)
369 else if (funcName.compare(
"hinge") == 0)
371 else if (funcName.compare(
"logistic") == 0)
380 else if (funcName.compare(
"quantile") == 0 || funcName.compare(
"pinball") == 0 || funcName.compare(
"absolute") == 0)
384 else if (funcName.compare(
"poisson") == 0)
394 THROW(
"Invalid loss function name: \'" << funcName <<
"\' Bailing!");
float getUnsafeUpdate(float prediction, float label, float update_scale)
float getUpdate(float prediction, float label, float update_scale, float pred_per_update)
float second_derivative(shared_data *sd, float prediction, float)
float second_derivative(shared_data *, float prediction, float)
float first_derivative(shared_data *, float prediction, float label)
float getSquareGrad(float prediction, float label)
float second_derivative(shared_data *, float, float)
float getUnsafeUpdate(float prediction, float label, float update_scale)
float first_derivative(shared_data *sd, float prediction, float label)
float getUpdate(float prediction, float label, float update_scale, float pred_per_update)
float getSquareGrad(float prediction, float label)
float getUnsafeUpdate(float prediction, float label, float update_scale)
float first_derivative(shared_data *, float prediction, float label)
float getRevertingWeight(shared_data *, float prediction, float eta_t)
float second_derivative(shared_data *, float, float)
float second_derivative(shared_data *, float prediction, float label)
float getSquareGrad(float prediction, float label)
float getUpdate(float prediction, float label, float update_scale, float pred_per_update)
float getRevertingWeight(shared_data *, float prediction, float eta_t)
float getLoss(shared_data *, float prediction, float label)
void(* set_minmax)(shared_data *sd, float label)
float getUpdate(float prediction, float label, float update_scale, float pred_per_update)
void noop_mm(shared_data *, float)
float getUnsafeUpdate(float prediction, float label, float update_scale)
float getSquareGrad(float prediction, float label)
float getRevertingWeight(shared_data *sd, float prediction, float eta_t)
float getSquareGrad(float prediction, float label)
float getLoss(shared_data *sd, float prediction, float label)
float first_derivative(shared_data *, float prediction, float label)
quantileloss(float &tau_)
float getUnsafeUpdate(float prediction, float label, float update_scale)
float getLoss(shared_data *, float prediction, float label)
float getSquareGrad(float prediction, float label)
float getRevertingWeight(shared_data *, float, float)
float second_derivative(shared_data *, float, float)
float getUpdate(float prediction, float label, float update_scale, float pred_per_update)
float getLoss(shared_data *, float prediction, float label)
float getRevertingWeight(shared_data *sd, float prediction, float eta_t)
float first_derivative(shared_data *, float prediction, float label)
float getRevertingWeight(shared_data *sd, float prediction, float eta_t)
float getLoss(shared_data *, float prediction, float label)
float getLoss(shared_data *, float prediction, float label)
loss_function * getLossFunction(vw &all, std::string funcName, float function_parameter)
float getUpdate(float prediction, float label, float update_scale, float)
float getUnsafeUpdate(float prediction, float label, float update_scale)
float first_derivative(shared_data *, float prediction, float label)