Feat C++ API
A feature engineering automation tool
metrics.h
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #ifndef METRICS_H
6 #define METRICS_H
7 #include <shogun/labels/Labels.h>
8 #include <shogun/labels/RegressionLabels.h>
9 #include <shogun/labels/MulticlassLabels.h>
10 #include <shogun/labels/BinaryLabels.h>
11 #include "../util/utils.h"
12 namespace sh = shogun;
13 using sh::CLabels;
14 using sh::SGVector;
15 using Eigen::Map;
16 using Eigen::ArrayXf;
17 
18 namespace FT
19 {
20  namespace Eval
21  {
22 
23  /* Scoring functions */
24 
25  // Squared difference
26  VectorXf squared_difference(const VectorXf& y, const VectorXf& yhat);
27 
28  VectorXf squared_difference(const VectorXf& y, shared_ptr<CLabels>& labels,
29  const vector<float>& weights=vector<float>());
30 
31  // Derivative of squared difference with respec to yhat
32  VectorXf d_squared_difference(const VectorXf& y, const VectorXf& yhat);
33 
34  // Derivative of squared difference with respec to yhat
35  VectorXf d_squared_difference(const VectorXf& y, shared_ptr<CLabels>& labels,
36  const vector<float>& weights=vector<float>());
37 
39  float mse(const VectorXf& y, const VectorXf& yhat, VectorXf& loss,
40  const vector<float>& weights=vector<float>() );
41 
42  float mse_label(const VectorXf& y, const shared_ptr<CLabels>& labels, VectorXf& loss,
43  const vector<float>& weights=vector<float>() );
44 
45  VectorXf log_loss(const VectorXf& y, const VectorXf& yhat,
46  const vector<float>& class_weights=vector<float>());
47 
48  VectorXf log_loss(const VectorXf& y, shared_ptr<CLabels>& labels,
49  const vector<float>& class_weights=vector<float>());
50 
52  float mean_log_loss(const VectorXf& y, const VectorXf& yhat, VectorXf& loss,
53  const vector<float>& class_weights = vector<float>());
55  float log_loss_label(const VectorXf& y, const shared_ptr<CLabels>& labels, VectorXf& loss,
56  const vector<float>& class_weights=vector<float>());
57 
58  VectorXf d_log_loss(const VectorXf& y, const VectorXf& yhat,
59  const vector<float>& class_weights=vector<float>());
60 
61  VectorXf d_log_loss(const VectorXf& y, shared_ptr<CLabels>& labels,
62  const vector<float>& class_weights=vector<float>());
63 
64  /* float weighted_average(const VectorXf& y, const VectorXf& w) */
65  /* { */
66  /* w = w.array() / w.sum(); */
67  /* return (y.array() * w.array()).mean(); */
68  /* } */
70  VectorXf multi_log_loss(const VectorXf& y, const ArrayXXf& confidences,
71  const vector<float>& class_weights=vector<float>());
72 
73  float mean_multi_log_loss(const VectorXf& y, const ArrayXXf& confidences, VectorXf& loss,
74  const vector<float>& class_weights=vector<float>());
75 
77  float multi_log_loss_label(const VectorXf& y, const shared_ptr<CLabels>& labels, VectorXf& loss,
78  const vector<float>& class_weights=vector<float>());
79 
80  VectorXf multi_log_loss(const VectorXf& y, shared_ptr<CLabels>& labels,
81  const vector<float>& class_weights=vector<float>());
82 
84  VectorXf d_multi_log_loss(const VectorXf& y, shared_ptr<CLabels>& labels,
85  const vector<float>& class_weights=vector<float>());
86 
88  float bal_zero_one_loss(const VectorXf& y, const VectorXf& yhat, VectorXf& loss,
89  const vector<float>& class_weights=vector<float>() );
90 
91  float bal_zero_one_loss_label(const VectorXf& y, const shared_ptr<CLabels>& labels,
92  VectorXf& loss, const vector<float>& class_weights=vector<float>() );
93 
94  float zero_one_loss(const VectorXf& y, const VectorXf& yhat, VectorXf& loss,
95  const vector<float>& class_weights=vector<float>() );
96 
98  float zero_one_loss_label(const VectorXf& y, const shared_ptr<CLabels>& labels, VectorXf& loss,
99  const vector<float>& class_weights=vector<float>() );
100 
101  /* float bal_log_loss(const VectorXf& y, const shared_ptr<CLabels>& labels, VectorXf& loss, */
102  /* const vector<float>& weights=vector<float>() ) */
103  /* { */
104 
105  /* loss = log_loss(y,yhat); */
106 
107  /* vector<float> uc = unique(y); */
108  /* vector<int> c; */
109  /* for (const auto& i : uc) */
110  /* c.push_back(int(i)); */
111 
112  /* vector<float> class_loss(c.size(),0); */
113 
114  /* for (unsigned i = 0; i < c.size(); ++i) */
115  /* { */
116  /* int n = (y.cast<int>().array() == c[i]).count(); */
117  /* class_loss[i] = (y.cast<int>().array() == c[i]).select(loss.array(),0).sum()/n; */
118 
119  /* } */
120  /* // return balanced class losses */
121  /* Map<ArrayXf> cl(class_loss.data(),class_loss.size()); */
122  /* return cl.mean(); */
123  /* } */
124  float false_positive_loss(const VectorXf& y,
125  const VectorXf& yhat, VectorXf& loss,
126  const vector<float>& class_weights);
127  float false_positive_loss_label(const VectorXf& y,
128  const shared_ptr<CLabels>& labels, VectorXf& loss,
129  const vector<float>& class_weights);
130  } // metrics
131 } // FT
132 
133 #endif
134 
VectorXf multi_log_loss(const VectorXf &y, const ArrayXXf &confidences, const vector< float > &class_weights)
multinomial log loss
Definition: metrics.cc:191
VectorXf d_squared_difference(const VectorXf &y, const VectorXf &yhat)
Definition: metrics.cc:44
float bal_zero_one_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
Definition: metrics.cc:412
float false_positive_loss(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &class_weights)
Definition: metrics.cc:457
float zero_one_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
1 - accuracy
Definition: metrics.cc:444
VectorXf log_loss(const VectorXf &y, const VectorXf &yhat, const vector< float > &class_weights)
Definition: metrics.cc:88
VectorXf squared_difference(const VectorXf &y, const VectorXf &yhat)
Definition: metrics.cc:18
VectorXf d_log_loss(const VectorXf &y, const VectorXf &yhat, const vector< float > &class_weights)
Definition: metrics.cc:159
float mse_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &weights)
Definition: metrics.cc:77
float multi_log_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
multinomial log loss
Definition: metrics.cc:250
float mean_multi_log_loss(const VectorXf &y, const ArrayXXf &confidences, VectorXf &loss, const vector< float > &class_weights)
Definition: metrics.cc:238
float bal_zero_one_loss(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &class_weights)
1 - balanced accuracy
Definition: metrics.cc:366
float mean_log_loss(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &class_weights)
log loss
Definition: metrics.cc:136
float zero_one_loss(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &class_weights)
Definition: metrics.cc:435
float false_positive_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
false positive rate
Definition: metrics.cc:468
float mse(const VectorXf &y, const VectorXf &yhat, VectorXf &loss, const vector< float > &weights)
mean squared error
Definition: metrics.cc:70
float log_loss_label(const VectorXf &y, const shared_ptr< CLabels > &labels, VectorXf &loss, const vector< float > &class_weights)
log loss
Definition: metrics.cc:147
VectorXf d_multi_log_loss(const VectorXf &y, shared_ptr< CLabels > &labels, const vector< float > &class_weights)
derivative of multinomial log loss
Definition: metrics.cc:303
main Feat namespace
Definition: data.cc:13