Commit 241aef27 authored by André Anjos's avatar André Anjos 💬

Merge branch 'roc-det-fix' into 'master'

Compute roc using roc_for_far internally

Closes #26

See merge request !44
parents 3a64d554 f67d3a34
Pipeline #14142 passed with stages
in 9 minutes and 44 seconds
...@@ -241,18 +241,15 @@ double bob::measure::minWeightedErrorRateThreshold( ...@@ -241,18 +241,15 @@ double bob::measure::minWeightedErrorRateThreshold(
blitz::Array<double, 2> blitz::Array<double, 2>
bob::measure::roc(const blitz::Array<double, 1> &negatives, bob::measure::roc(const blitz::Array<double, 1> &negatives,
const blitz::Array<double, 1> &positives, size_t points) { const blitz::Array<double, 1> &positives, size_t points) {
double min = std::min(blitz::min(negatives), blitz::min(positives)); // Uses roc_for_far internally
double max = std::max(blitz::max(negatives), blitz::max(positives)); // Create an far_list
double step = (max - min) / ((double)points - 1.0); blitz::Array<double, 1> far_list((int)points);
blitz::Array<double, 2> retval(2, points); int min_far = -8; // minimum FAR in terms of 10^(min_far)
for (int i = 0; i < (int)points; ++i) { double counts_per_step = points / (-min_far) ;
std::pair<double, double> ratios = for (int i = 1-(int)points; i <= 0; ++i) {
bob::measure::farfrr(negatives, positives, min + i * step); far_list(i+(int)points-1) = std::pow(10., (double)i/counts_per_step);
// preserve X x Y ordering (FAR x FRR)
retval(0, i) = ratios.first;
retval(1, i) = ratios.second;
} }
return retval; return bob::measure::roc_for_far(negatives, positives, far_list, false);
} }
blitz::Array<double, 2> blitz::Array<double, 2>
...@@ -472,9 +469,9 @@ bob::measure::roc_for_far(const blitz::Array<double, 1> &negatives, ...@@ -472,9 +469,9 @@ bob::measure::roc_for_far(const blitz::Array<double, 1> &negatives,
if (far_index >= 0) { if (far_index >= 0) {
// walk to the end of both lists; at least one of both lists should already // walk to the end of both lists; at least one of both lists should already
// have reached its limit. // have reached its limit.
while (pos_it++ != pos.end()) while (pos_it != pos.end() && pos_it++ != pos.end())
++pos_index; ++pos_index;
while (neg_it++ != neg.end()) while (neg_it != neg.end() && neg_it++ != neg.end())
++neg_index; ++neg_index;
// fill in the remaining elements of the CAR list // fill in the remaining elements of the CAR list
do { do {
......
...@@ -288,7 +288,7 @@ def test_plots(): ...@@ -288,7 +288,7 @@ def test_plots():
# This example will test the ROC plot calculation functionality. # This example will test the ROC plot calculation functionality.
xy = roc(negatives, positives, 100) xy = roc(negatives, positives, 100)
# uncomment the next line to save a reference value # uncomment the next line to save a reference value
# save('nonsep-roc.hdf5', xy) # save(F('nonsep-roc.hdf5'), xy)
xyref = bob.io.base.load(F('nonsep-roc.hdf5')) xyref = bob.io.base.load(F('nonsep-roc.hdf5'))
assert numpy.array_equal(xy, xyref) assert numpy.array_equal(xy, xyref)
...@@ -310,7 +310,7 @@ def test_plots(): ...@@ -310,7 +310,7 @@ def test_plots():
# This example will test the DET plot calculation functionality. # This example will test the DET plot calculation functionality.
det_xyzw = det(negatives, positives, 100) det_xyzw = det(negatives, positives, 100)
# uncomment the next line to save a reference value # uncomment the next line to save a reference value
# save('nonsep-det.hdf5', det_xyzw) # save(F('nonsep-det.hdf5'), det_xyzw)
det_xyzw_ref = bob.io.base.load(F('nonsep-det.hdf5')) det_xyzw_ref = bob.io.base.load(F('nonsep-det.hdf5'))
assert numpy.allclose(det_xyzw, det_xyzw_ref, atol=1e-15) assert numpy.allclose(det_xyzw, det_xyzw_ref, atol=1e-15)
......
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