N log(N) far threshold search

parent c7cf32af
Pipeline #14114 passed with stages
in 7 minutes and 31 seconds
...@@ -130,15 +130,36 @@ double bob::measure::farThreshold(const blitz::Array<double, 1> &negatives, ...@@ -130,15 +130,36 @@ double bob::measure::farThreshold(const blitz::Array<double, 1> &negatives,
// Move towards the beginning of array changing the threshold until we pass // Move towards the beginning of array changing the threshold until we pass
// the desired FAR value. Start with a threshold that corresponds to FAR == // the desired FAR value. Start with a threshold that corresponds to FAR ==
// 0. // 0.
int index = neg.extent(0) - 1; int last_pivot = neg.extent(0);
double threshold = neg(index) + 1e-12; int pivot = last_pivot / 2;
double threshold = neg(last_pivot-1) + 1e-12;
double future_far; double future_far;
while (index >= 0) { while (pivot < neg.extent(0)) {
future_far = blitz::count(neg >= neg(index)) / (double)neg.extent(0); future_far = blitz::count(neg >= neg(pivot)) / (double)neg.extent(0);
if (future_far <= far_value){
// Moving towards the beggining of the list
last_pivot = pivot;
pivot = pivot / 2;
}
else{
//Checking if we are in the boundary
if(pivot==neg.extent(0)-1){
threshold = neg(pivot) + 1e-12;
break;
}
future_far = blitz::count(neg >= neg(pivot+1)) / (double)neg.extent(0);
// If we are in the boundary we are done....
if (future_far > far_value) if (future_far > far_value)
//Let's keep searching towards the end of the list
pivot = (last_pivot + pivot) / 2;
else{
// I found you....
threshold = neg(pivot+1);
break; break;
threshold = neg(index); }
--index; }
} }
return threshold; return threshold;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment