Vowpal Wabbit
Public Member Functions | List of all members
logloss Class Reference
Inheritance diagram for logloss:
loss_function

Public Member Functions

std::string getType ()
 
float getLoss (shared_data *, float prediction, float label)
 
float getUpdate (float prediction, float label, float update_scale, float pred_per_update)
 
float getUnsafeUpdate (float prediction, float label, float update_scale)
 
float wexpmx (float x)
 
float getRevertingWeight (shared_data *, float prediction, float eta_t)
 
float first_derivative (shared_data *, float prediction, float label)
 
float getSquareGrad (float prediction, float label)
 
float second_derivative (shared_data *, float prediction, float label)
 
- Public Member Functions inherited from loss_function
virtual ~loss_function ()
 

Detailed Description

Definition at line 157 of file loss_functions.cc.

Member Function Documentation

◆ first_derivative()

float logloss::first_derivative ( shared_data ,
float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 211 of file loss_functions.cc.

References correctedExp.

212  {
213  float v = -label / (1 + correctedExp(label * prediction));
214  return v;
215  }
#define correctedExp
Definition: correctedMath.h:27

◆ getLoss()

float logloss::getLoss ( shared_data ,
float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 162 of file loss_functions.cc.

References correctedExp, and f.

163  {
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;
166  return log(1 + correctedExp(-label * prediction));
167  }
#define correctedExp
Definition: correctedMath.h:27
float f
Definition: cache.cc:40

◆ getRevertingWeight()

float logloss::getRevertingWeight ( shared_data ,
float  prediction,
float  eta_t 
)
inlinevirtual

Implements loss_function.

Definition at line 205 of file loss_functions.cc.

References correctedExp.

206  {
207  float z = -fabs(prediction);
208  return (1 - z - correctedExp(z)) / eta_t;
209  }
#define correctedExp
Definition: correctedMath.h:27

◆ getSquareGrad()

float logloss::getSquareGrad ( float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 217 of file loss_functions.cc.

References squaredloss::first_derivative().

218  {
219  float d = first_derivative(nullptr, prediction, label);
220  return d * d;
221  }
float first_derivative(shared_data *, float prediction, float label)

◆ getType()

std::string logloss::getType ( )
inlinevirtual

Implements loss_function.

Definition at line 160 of file loss_functions.cc.

160 { return "logistic"; }

◆ getUnsafeUpdate()

float logloss::getUnsafeUpdate ( float  prediction,
float  label,
float  update_scale 
)
inlinevirtual

Implements loss_function.

Definition at line 185 of file loss_functions.cc.

References correctedExp.

186  {
187  float d = correctedExp(label * prediction);
188  return label * update_scale / (1 + d);
189  }
#define correctedExp
Definition: correctedMath.h:27

◆ getUpdate()

float logloss::getUpdate ( float  prediction,
float  label,
float  update_scale,
float  pred_per_update 
)
inlinevirtual

Implements loss_function.

Definition at line 169 of file loss_functions.cc.

References correctedExp.

170  {
171  float w, x;
172  float d = correctedExp(label * prediction);
173  if (update_scale * pred_per_update < 1e-6)
174  {
175  /* As with squared loss, for small eta_t we replace the update
176  * with its first order Taylor expansion to avoid numerical problems
177  */
178  return label * update_scale / (1 + d);
179  }
180  x = update_scale * pred_per_update + label * prediction + d;
181  w = wexpmx(x);
182  return -(label * w + prediction) / pred_per_update;
183  }
#define correctedExp
Definition: correctedMath.h:27
float wexpmx(float x)

◆ second_derivative()

float logloss::second_derivative ( shared_data ,
float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 223 of file loss_functions.cc.

References correctedExp.

224  {
225  float p = 1 / (1 + correctedExp(label * prediction));
226 
227  return p * (1 - p);
228  }
#define correctedExp
Definition: correctedMath.h:27

◆ wexpmx()

float logloss::wexpmx ( float  x)
inline

Definition at line 191 of file loss_functions.cc.

References correctedExp.

192  {
193  /* This piece of code is approximating W(exp(x))-x.
194  * W is the Lambert W function: W(z)*exp(W(z))=z.
195  * The absolute error of this approximation is less than 9e-5.
196  * Faster/better approximations can be substituted here.
197  */
198  double w = x >= 1. ? 0.86 * x + 0.01 : correctedExp(0.8 * x - 0.65); // initial guess
199  double r = x >= 1. ? x - log(w) - w : 0.2 * x + 0.65 - w; // residual
200  double t = 1. + w;
201  double u = 2. * t * (t + 2. * r / 3.); // magic
202  return (float)(w * (1. + r / t * (u - r) / (u - 2. * r)) - x); // more magic
203  }
#define correctedExp
Definition: correctedMath.h:27

The documentation for this class was generated from the following file: