6 #ifndef TURI_FACTORIZATION_LOSS_MODEL_PROFILES_H_ 7 #define TURI_FACTORIZATION_LOSS_MODEL_PROFILES_H_ 9 #include <core/logging/assertions.hpp> 10 #include <core/util/logit_math.hpp> 11 #include <core/util/code_optimization.hpp> 17 namespace turi {
namespace factorization {
34 virtual double loss(
double fx,
double y)
const = 0;
35 virtual double loss_grad(
double fx,
double y)
const = 0;
36 virtual double translate_fx_to_prediction(
double f_x)
const = 0;
37 virtual bool prediction_is_translated()
const = 0;
38 virtual std::string reported_loss_name()
const = 0;
39 virtual double reported_loss_value(
double cumulative_loss_value)
const = 0;
49 static std::string name() {
return "squared_error"; }
63 bool prediction_is_translated()
const {
return false; }
65 std::string reported_loss_name()
const {
return "RMSE"; }
67 double reported_loss_value(
double cumulative_loss_value)
const {
68 return std::sqrt(cumulative_loss_value);
74 void _logistic_loss_value_is_bad(
double) __attribute__((noinline, cold));
81 static std::string name() {
return "logistic"; }
85 _logistic_loss_value_is_bad(y);
87 return (1 - y) * fx +
log1pen(fx);
98 bool prediction_is_translated()
const {
return true; }
100 std::string reported_loss_name()
const {
return "Predictive Error"; }
102 double reported_loss_value(
double cumulative_loss_value)
const {
103 return cumulative_loss_value;
114 static std::string name() {
return "hinge_ranking"; }
117 return std::max(0.0, 1 - fx_diff);
121 return (fx_diff < 1) ? -1 : 0;
128 bool prediction_is_translated()
const {
return false; }
130 std::string reported_loss_name()
const {
return "Hinge Loss"; }
132 double reported_loss_value(
double cumulative_loss_value)
const {
133 return cumulative_loss_value;
142 static std::string name() {
return "logit rank"; }
156 bool prediction_is_translated()
const {
return true; }
158 std::string reported_loss_name()
const {
return "Logistic Rank Loss"; }
160 double reported_loss_value(
double cumulative_loss_value)
const {
161 return cumulative_loss_value;
167 std::shared_ptr<loss_model_profile> get_loss_model_profile(
168 const std::string& name);
static GL_HOT_INLINE_FLATTEN double log1pen_deriviative(double x)
static GL_HOT_INLINE_FLATTEN double sigmoid(double x)
static GL_HOT_INLINE_FLATTEN double log1pen(double x)
#define GL_HOT_INLINE_FLATTEN