34 #ifndef SHARK_OBJECTIVEFUNCTIONS_LOSS_ZEROONELOSS_H 35 #define SHARK_OBJECTIVEFUNCTIONS_LOSS_ZEROONELOSS_H 50 template<
class LabelType =
unsigned int,
class OutputType = LabelType>
65 {
return "ZeroOneLoss"; }
70 double eval(BatchLabelType
const& labels, BatchOutputType
const& predictions)
const{
71 std::size_t numInputs =
size(labels);
75 for(std::size_t i = 0; i != numInputs; ++i){
76 error += (predictions(i) != labels(i))?1.0:0.0;
97 m_threshold = threshold;
102 {
return "ZeroOneLoss"; }
114 double eval(BatchLabelType
const& labels, BatchOutputType
const& predictions)
const{
115 std::size_t numInputs =
size(labels);
119 for(std::size_t i = 0; i != numInputs; ++i){
120 error+=evalSingle(labels(i),
get(predictions,i));
130 for(std::size_t i = 0; i != weights.size(); ++i){
131 error+= weights(i) * evalSingle(targets.
element(i),predictions.
element(i));
133 return error / weights.size();
137 template<
class VectorType>
138 double evalSingle(
unsigned int label,
VectorType const& predictions)
const{
139 std::size_t
size = predictions.size();
142 unsigned int t = (predictions(0) > m_threshold);
143 if (t == label)
return 0.0;
149 double p = predictions(label);
150 for (std::size_t i = 0; i<
size; i++)
152 if (i == label)
continue;
153 if (predictions(i) >= p)
return 1.0;