Commit cf22e6dd authored by André Anjos's avatar André Anjos 💬

Almost all tests passing

parent 5c3475cd
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Wed 11 Dec 15:11:44 2013 CET
#
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
from ._library import __version__
from ._library import *
from . import plot
from . import load
......
This diff is collapsed.
......@@ -55,7 +55,8 @@ def roc(negatives, positives, npoints=100, CAR=False, **kwargs):
raise
from . import roc as calc
out = calc(negatives, positives, npoints)
import numpy
out = numpy.array(calc(negatives, positives, npoints))
if not CAR:
return mpl.plot(100.0*out[0,:], 100.0*out[1,:], **kwargs)
else:
......@@ -173,9 +174,10 @@ def epc(dev_negatives, dev_positives, test_negatives, test_positives,
raise
from . import epc as calc
import numpy
out = calc(dev_negatives, dev_positives, test_negatives, test_positives,
npoints)
out = numpy.array(calc(dev_negatives, dev_positives,
test_negatives, test_positives, npoints))
return mpl.plot(out[0,:], 100.0*out[1,:], **kwargs)
def det(negatives, positives, npoints=100, axisfontsize='x-small', **kwargs):
......@@ -291,8 +293,9 @@ def det(negatives, positives, npoints=100, axisfontsize='x-small', **kwargs):
# this will actually do the plotting
from . import det as calc
from . import ppndf
import numpy
out = calc(negatives, positives, npoints)
out = numpy.array(calc(negatives, positives, npoints))
retval = mpl.plot(out[0,:], out[1,:], **kwargs)
# now the trick: we must plot the tick marks by hand using the PPNDF method
......
......@@ -31,6 +31,7 @@ Examples:
import os
import sys
import numpy
def print_crit(dev_neg, dev_pos, test_neg, test_pos, crit):
"""Prints a single output line that contains all info for a given criterium"""
......@@ -207,8 +208,8 @@ def main(user_input=None):
print_crit(dev_neg, dev_pos, test_neg, test_pos, 'EER')
print_crit(dev_neg, dev_pos, test_neg, test_pos, 'Min. HTER')
if options.doplot:
plots(dev_neg, dev_pos, test_neg, test_pos,
options.npoints, options.plotfile)
plots(dev_neg, dev_pos, test_neg, test_pos, options.npoints,
options.plotfile)
print("[Plots] Performance curves => '%s'" % options.plotfile)
if options.selftest: #remove output file + tmp directory
......
......@@ -19,11 +19,6 @@ def F(f):
return pkg_resources.resource_filename(__name__, os.path.join('data', f))
def count(array, value=True):
"""Counts occurrences of a certain value in an array"""
return list(array == value).count(True)
def save(fname, data):
"""Saves a single array into a file in the 'data' directory."""
xbob.io.Array(data).save(os.path.join('data', fname))
......@@ -70,20 +65,20 @@ def test_basic_ratios():
nose.tools.eq_(recall, 1.0)
# Testing the values of F-score depending on different choices of the threshold
f_score = f_score(negatives, positives, minimum-0.1)
nose.tools.assert_almost_equal(f_score, 0.66666667)
f_score = f_score(negatives, positives, minimum-0.1, 2)
nose.tools.assert_almost_equal(f_score, 0.83333333)
f_score_ = f_score(negatives, positives, minimum-0.1)
nose.tools.assert_almost_equal(f_score_, 0.66666667)
f_score_ = f_score(negatives, positives, minimum-0.1, 2)
nose.tools.assert_almost_equal(f_score_, 0.83333333)
f_score = f_score(negatives, positives, maximum+0.1)
nose.tools.eq_(f_score, 0.0)
f_score = f_score(negatives, positives, maximum+0.1, 2)
nose.tools.eq_(f_score, 0.0)
f_score_ = f_score(negatives, positives, maximum+0.1)
nose.tools.eq_(f_score_, 0.0)
f_score_ = f_score(negatives, positives, maximum+0.1, 2)
nose.tools.eq_(f_score_, 0.0)
f_score = f_score(negatives, positives, 3.0)
nose.tools.eq_(f_score, 1.0)
f_score = f_score(negatives, positives, 3.0, 2)
nose.tools.eq_(f_score, 1.0)
f_score_ = f_score(negatives, positives, 3.0)
nose.tools.eq_(f_score_, 1.0)
f_score_ = f_score(negatives, positives, 3.0, 2)
nose.tools.eq_(f_score_, 1.0)
def test_indexing():
......@@ -101,23 +96,27 @@ def test_indexing():
# If the threshold is minimum, we should have all positive samples
# correctly classified and none of the negative samples correctly
# classified.
assert correctly_classified_positives(positives, minimum-0.1).all()
assert not correctly_classified_negatives(negatives, minimum-0.1).any()
assert numpy.array(correctly_classified_positives(positives, minimum-0.1)).all()
assert not numpy.array(correctly_classified_negatives(negatives, minimum-0.1)).any()
# The inverse is true if the threshold is a bit above the maximum.
assert not correctly_classified_positives(positives, maximum+0.1).any()
assert correctly_classified_negatives(negatives, maximum+0.1).all()
assert not numpy.array(correctly_classified_positives(positives, maximum+0.1)).any()
assert numpy.array(correctly_classified_negatives(negatives, maximum+0.1)).all()
# If the threshold separates the sets, than all should be correctly
# classified.
assert correctly_classified_positives(positives, 3).all()
assert correctly_classified_negatives(negatives, 3).all()
assert numpy.array(correctly_classified_positives(positives, 3)).all()
assert numpy.array(correctly_classified_negatives(negatives, 3)).all()
def test_thresholding():
from .. import eer_threshold, far_threshold, frr_threshold, farfrr, correctly_classified_positives, correctly_classified_negatives, min_hter_threshold
def count(array, value=True):
"""Counts occurrences of a certain value in an array"""
return list(numpy.array(array) == value).count(True)
# This example will demonstrate and check the use of eer_threshold() to
# calculate the threshold that minimizes the EER.
......
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