Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Hofman <hofman@research-mm10.corp.sp1.yahoo.com>2010-12-23 21:39:41 +0300
committerJacob Hofman <hofman@research-mm10.corp.sp1.yahoo.com>2010-12-23 21:39:41 +0300
commitd10feaf53cee63e2884dd6e33f35afb90e1e04c9 (patch)
treec01641b7456ed076a80d688caef4a91499cd9253 /loss_functions.cc
parentc51a800b1930c648faf7d40dc776a4d38e33ce82 (diff)
parenta9ced5d4c75375f5c1a4e4a2ca0020749dd3a358 (diff)
matrix factorization uses new format for weight vector, checking for bugs
Diffstat (limited to 'loss_functions.cc')
-rw-r--r--loss_functions.cc61
1 files changed, 54 insertions, 7 deletions
diff --git a/loss_functions.cc b/loss_functions.cc
index af660f5a..e9d242d4 100644
--- a/loss_functions.cc
+++ b/loss_functions.cc
@@ -44,7 +44,14 @@ public:
float getSquareGrad(float prediction, float label) {
return (prediction - label) * (prediction - label);
}
-
+ float first_derivative(float prediction, float label)
+ {
+ return 2. * (prediction-label);
+ }
+ float second_derivative(float prediction, float label)
+ {
+ return 2.;
+ }
};
class classic_squaredloss : public loss_function {
@@ -71,7 +78,14 @@ public:
float getSquareGrad(float prediction, float label) {
return (prediction - label) * (prediction - label);
}
-
+ float first_derivative(float prediction, float label)
+ {
+ return 2. * (prediction-label);
+ }
+ float second_derivative(float prediction, float label)
+ {
+ return 2.;
+ }
};
@@ -98,7 +112,17 @@ public:
}
float getSquareGrad(float prediction, float label) {
- return (label*prediction >= label*label) ? 0 : 1;
+ return first_derivative(prediction,label);
+ }
+
+ float first_derivative(float prediction, float label)
+ {
+ return (label*prediction >= label*label) ? 0 : -label;
+ }
+
+ float second_derivative(float prediction, float label)
+ {
+ return 0.;
}
};
@@ -144,11 +168,23 @@ public:
return (1-z-exp(z))/eta_t;
}
+ float first_derivative(float prediction, float label)
+ {
+ float v = - label/(1+exp(label * prediction));
+ return v;
+ }
+
float getSquareGrad(float prediction, float label) {
- float d = 1./(1+exp(label * prediction));
+ float d = first_derivative(prediction,label);
return d*d;
}
+ float second_derivative(float prediction, float label)
+ {
+ float e = exp(label*prediction);
+
+ return label*label*e/((1+e)*(1+e));
+ }
};
class quantileloss : public loss_function {
@@ -190,12 +226,23 @@ public:
return (t - prediction)/(eta_t*v);
}
- float getSquareGrad(float prediction, float label) {
+ float first_derivative(float prediction, float label)
+ {
float e = label - prediction;
if(e == 0) return 0;
- return e > 0 ? tau*tau : (1-tau)*(1-tau);
+ return e > 0 ? -tau : (1-tau);
}
-
+
+ float getSquareGrad(float prediction, float label) {
+ float fd = first_derivative(prediction,label);
+ return fd*fd;
+ }
+
+ float second_derivative(float prediction, float label)
+ {
+ return 0.;
+ }
+
double tau;
};