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>() );
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);
139 throw SHARKEXCEPTION(
"[NegativeAUC::eval] no default value for column");
145 double trapArea(
double x1,
double x2,
double y1,
double y2)
const {
146 double base = std::abs(x1-x2);
147 double heightAvg = (y1+y2)/2;
148 return base * heightAvg;
165 template<
class LabelType =
unsigned int,
class OutputType = LabelType>
177 {
return "NegativeWilcoxonMannWhitneyStatistic"; }
184 SHARK_CHECK(prediction(0).
size() > column,
"[NegativeWilcoxonMannWhitneyStatistic::eval] column number too large");
185 std::vector<double> pos, neg;
186 for(std::size_t i=0; i<prediction.size(); i++) {
199 std::size_t m = pos.size();
200 std::size_t n = neg.size();
202 std::sort (pos.begin(), pos.end());
203 std::sort (neg.begin(), neg.end());
206 for(std::size_t i = 0, j = 0; i != m; i++) {
208 for(std::size_t j = 0; j != n; j++) {
219 for(std::size_t i=0; i<m; i++) {
220 for(std::size_t j=0; j<n; j++) {
221 if(pos[i] > neg[j]) verifyA++;
225 throw(
shark::Exception(
"shark::WilcoxonMannWhitneyStatistic::eval: error in algorithm, efficient and naive implementation do no coincide", __FILE__, __LINE__ ) );
237 return eval(target, prediction, 0);
239 return eval(target, prediction, 1);
241 throw SHARKEXCEPTION(
"[NegativeAUC::eval] no default value for column");