34 #ifndef SHARK_OBJECTIVEFUNCTIONS_NEGATIVE_AUC_H 35 #define SHARK_OBJECTIVEFUNCTIONS_NEGATIVE_AUC_H 51 template<
class LabelType =
unsigned int,
class OutputType = RealVector>
65 {
return "NegativeAUC"; }
78 std::vector<AUCPair> L(elements);
80 for(std::size_t i=0; i!= elements; i++) {
94 std::sort (L.begin(), L.end(),std::greater<AUCPair>() );
101 double predictionPrev = -std::numeric_limits<double>::max();
102 for(std::size_t i=0; i != elements; i++) {
103 if(L[i].key != predictionPrev){
104 A +=
trapArea(FP/
double(N),FPPrev/
double(N),TP/
double(P),TPPrev/
double(P));
105 predictionPrev = L[i].key;
115 A +=
trapArea(FP/
double(N), FPPrev/
double(N), TP/
double(P), TPPrev/
double(P));
135 return eval(target, prediction, 0);
137 return eval(target, prediction, 1);
143 double trapArea(
double x1,
double x2,
double y1,
double y2)
const {
144 double base = std::abs(x1-x2);
145 double heightAvg = (y1+y2)/2;
146 return base * heightAvg;
163 template<
class LabelType =
unsigned int,
class OutputType = LabelType>
175 {
return "NegativeWilcoxonMannWhitneyStatistic"; }
183 std::vector<double> pos, neg;
184 for(std::size_t i=0; i<prediction.size(); i++) {
187 pos.push_back(prediction.
element(i)(column));
189 neg.push_back(prediction.
element(i)(column));
192 pos.push_back(-prediction.
element(i)(column));
194 neg.push_back(-prediction.
element(i)(column));
197 std::size_t m = pos.size();
198 std::size_t n = neg.size();
200 std::sort (pos.begin(), pos.end());
201 std::sort (neg.begin(), neg.end());
204 for(std::size_t i = 0, j = 0; i != m; i++) {
206 for(std::size_t j = 0; j != n; j++) {
217 for(std::size_t i=0; i<m; i++) {
218 for(std::size_t j=0; j<n; j++) {
219 if(pos[i] > neg[j]) verifyA++;
223 throw(
shark::Exception(
"shark::WilcoxonMannWhitneyStatistic::eval: error in algorithm, efficient and naive implementation do no coincide", __FILE__, __LINE__ ) );
236 return eval(target, prediction, 0);
238 return eval(target, prediction, 1);