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 = labels.size();
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 = labels.size();
119 for(std::size_t i = 0; i != numInputs; ++i){
120 error+=evalSingle(labels(i),row(predictions,i));
131 for(std::size_t j = 0; j != targets.
batch(i).size(); ++j){
132 error+= weights(i) * evalSingle(targets.
batch(i)(j),row(predictions.
batch(i),j));
135 return error / weights.size();
139 template<
class VectorType>
140 double evalSingle(
unsigned int label,
VectorType const& predictions)
const{
141 std::size_t size = predictions.size();
144 unsigned int t = (predictions(0) > m_threshold);
145 if (t == label)
return 0.0;
151 double p = predictions(label);
152 for (std::size_t i = 0; i<size; i++)
154 if (i == label)
continue;
155 if (predictions(i) >= p)
return 1.0;