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

Public Member Functions

std::string getType ()
 
float getLoss (shared_data *sd, 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 getRevertingWeight (shared_data *sd, float prediction, float eta_t)
 
float getSquareGrad (float prediction, float label)
 
float first_derivative (shared_data *sd, float prediction, float label)
 
float second_derivative (shared_data *sd, float prediction, float)
 
- Public Member Functions inherited from loss_function
virtual ~loss_function ()
 

Detailed Description

Definition at line 15 of file loss_functions.cc.

Member Function Documentation

◆ first_derivative()

float squaredloss::first_derivative ( shared_data sd,
float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 66 of file loss_functions.cc.

References shared_data::max_label, and shared_data::min_label.

Referenced by hingeloss::getSquareGrad(), logloss::getSquareGrad(), and quantileloss::getSquareGrad().

67  {
68  if (prediction < sd->min_label)
69  prediction = sd->min_label;
70  else if (prediction > sd->max_label)
71  prediction = sd->max_label;
72  return 2.f * (prediction - label);
73  }
float min_label
Definition: global_data.h:150
float max_label
Definition: global_data.h:151

◆ getLoss()

float squaredloss::getLoss ( shared_data sd,
float  prediction,
float  label 
)
inlinevirtual

Implements loss_function.

Definition at line 20 of file loss_functions.cc.

References shared_data::max_label, and shared_data::min_label.

21  {
22  if (prediction <= sd->max_label && prediction >= sd->min_label)
23  {
24  float example_loss = (prediction - label) * (prediction - label);
25  return example_loss;
26  }
27  else if (prediction < sd->min_label)
28  if (label == sd->min_label)
29  return 0.;
30  else
31  return (float)((label - sd->min_label) * (label - sd->min_label) +
32  2. * (label - sd->min_label) * (sd->min_label - prediction));
33  else if (label == sd->max_label)
34  return 0.;
35  else
36  return float((sd->max_label - label) * (sd->max_label - label) +
37  2. * (sd->max_label - label) * (prediction - sd->max_label));
38  }
float min_label
Definition: global_data.h:150
float max_label
Definition: global_data.h:151

◆ getRevertingWeight()

float squaredloss::getRevertingWeight ( shared_data sd,
float  prediction,
float  eta_t 
)
inlinevirtual

Implements loss_function.

Definition at line 58 of file loss_functions.cc.

References shared_data::max_label, and shared_data::min_label.

59  {
60  float t = 0.5f * (sd->min_label + sd->max_label);
61  float alternative = (prediction > t) ? sd->min_label : sd->max_label;
62  return log((alternative - prediction) / (alternative - t)) / eta_t;
63  }
float min_label
Definition: global_data.h:150
float max_label
Definition: global_data.h:151

◆ getSquareGrad()

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

Implements loss_function.

Definition at line 65 of file loss_functions.cc.

65 { return 4.f * (prediction - label) * (prediction - label); }

◆ getType()

std::string squaredloss::getType ( )
inlinevirtual

Implements loss_function.

Definition at line 18 of file loss_functions.cc.

18 { return "squared"; }

◆ getUnsafeUpdate()

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

Implements loss_function.

Definition at line 53 of file loss_functions.cc.

54  {
55  return 2.f * (label - prediction) * update_scale;
56  }

◆ getUpdate()

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

Implements loss_function.

Definition at line 40 of file loss_functions.cc.

References correctedExp, and f.

41  {
42  if (update_scale * pred_per_update < 1e-6)
43  {
44  /* When exp(-eta_t)~= 1 we replace 1-exp(-eta_t)
45  * with its first order Taylor expansion around 0
46  * to avoid catastrophic cancellation.
47  */
48  return 2.f * (label - prediction) * update_scale;
49  }
50  return (label - prediction) * (1.f - correctedExp(-2.f * update_scale * pred_per_update)) / pred_per_update;
51  }
#define correctedExp
Definition: correctedMath.h:27
float f
Definition: cache.cc:40

◆ second_derivative()

float squaredloss::second_derivative ( shared_data sd,
float  prediction,
float   
)
inlinevirtual

Implements loss_function.

Definition at line 74 of file loss_functions.cc.

References shared_data::min_label.

75  {
76  if (prediction <= sd->max_label && prediction >= sd->min_label)
77  return 2.;
78  else
79  return 0.;
80  }
float min_label
Definition: global_data.h:150

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