25 #ifndef SHARK_OBJECTIVEFUNCTIONS_LOSS_ZEROONELOSS_H
26 #define SHARK_OBJECTIVEFUNCTIONS_LOSS_ZEROONELOSS_H
41 template<
class LabelType =
unsigned int,
class OutputType = LabelType>
56 {
return "ZeroOneLoss"; }
62 std::size_t numInputs =
size(labels);
66 for(std::size_t i = 0; i != numInputs; ++i){
67 error += (predictions(i) != labels(i))?1.0:0.0;
88 m_threshold = threshold;
93 {
return "ZeroOneLoss"; }
106 std::size_t numInputs =
size(labels);
110 for(std::size_t i = 0; i != numInputs; ++i){
111 error+=evalSingle(labels(i),
get(predictions,i));
116 template<
class VectorType>
117 double evalSingle(
unsigned int label,
VectorType const& predictions)
const{
118 std::size_t
size = predictions.size();
121 unsigned int t = (predictions(0) > m_threshold);
122 if (t == label)
return 0.0;
128 double p = predictions(label);
129 for (std::size_t i = 0; i<
size; i++)
131 if (i == label)
continue;
132 if (predictions(i) >= p)
return 1.0;