31 #ifndef SHARK_OBJECTIVEFUNCTIONS_LOSS_HUBERLOSS_H 32 #define SHARK_OBJECTIVEFUNCTIONS_LOSS_HUBERLOSS_H 58 {
return "HuberLoss"; }
63 SIZE_CHECK(labels.size1() == predictions.size1());
64 SIZE_CHECK(labels.size2() == predictions.size2());
65 std::size_t numInputs = labels.size1();
68 for(std::size_t i = 0; i != numInputs;++i){
69 double norm2 = norm_sqr(row(predictions,i)-row(labels,i));
72 if(norm2 <=
sqr(m_delta)){
76 error += m_delta*std::sqrt(norm2)-0.5*
sqr(m_delta);
83 SIZE_CHECK(labels.size1() == predictions.size1());
84 SIZE_CHECK(labels.size2() == predictions.size2());
85 std::size_t numInputs = predictions.size1();
86 std::size_t outputDim = predictions.size2();
88 gradient.resize(numInputs,outputDim);
90 for(std::size_t i = 0; i != numInputs;++i){
91 double norm2 = norm_sqr(row(predictions,i)-row(labels,i));
94 if(norm2 <=
sqr(m_delta)){
96 noalias(row(gradient,i)) = row(predictions,i)-row(labels,i);
99 double norm = std::sqrt(norm2);
100 error += m_delta*norm-0.5*
sqr(m_delta);
101 noalias(row(gradient,i)) = m_delta/norm*(row(predictions,i)-row(labels,i));