Commit 3b270041 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

Merge branch 'theo-gen-load' into 'theo'

Generic loading input file

See merge request !50
parents f3657022 f3ea47fb
Pipeline #17786 passed with stage
in 20 minutes and 58 seconds
This diff is collapsed.
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Mon 23 May 2011 16:23:05 CEST
"""A set of utilities to load score files with different formats.
import logging
import numpy
LOGGER = logging.getLogger('bob.measure')
def split(filename):
"""split(filename) -> negatives, positives
Loads the scores from the given file and splits them into positive
and negative arrays. The file must be a two columns file where the first
column contains -1 or 1 (for negative or positive respectively) and the
second the corresponding scores.
filename: :py:class:`str`:
The name of the file containing the scores.
negatives: 1D :py:class:`numpy.ndarray` of type float
This array contains the list of negative scores
positives: 1D :py:class:`numpy.ndarray` of type float
This array contains the list of positive scores
columns = numpy.loadtxt(filename)
neg_pos = columns[:, 0]
scores = columns[:, 1]
LOGGER.error('''Cannot read {}. This file must be a two columns file with
the first column containing -1 or 1 (i.e. negative or
positive) and the second the scores
return None, None
return (scores[numpy.where(neg_pos == -1)],
scores[numpy.where(neg_pos == 1)])
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <>
# Wed 11 Dec 15:14:08 2013 CET
# Copyright (C) 2011-2013 Idiap Research Institute, Martigny, Switzerland
"""Tests the IO functionality of bob.measure."""
from import assert_equal
import bob.measure.load
import numpy
def test_split():
# This function test loading for generic bob.measure input files
# Read test file
test_file =
'data.txt', 'bob.measure')
neg, pos = bob.measure.load.split(test_file)
assert neg is not None
assert_equal(len(neg), 521)
assert_equal(len(pos), 479)
test_ref_file_path =
'two-cols.hdf5', 'bob.measure')
test_ref =
neg_ref ='negatives')
pos_ref ='positives')
del test_ref
assert numpy.array_equal(numpy.nan_to_num(neg_ref), numpy.nan_to_num(neg))
assert numpy.array_equal(numpy.nan_to_num(pos_ref), numpy.nan_to_num(pos))
......@@ -83,6 +83,12 @@ Plotting
.. autosummary::
......@@ -90,3 +96,4 @@ Details
.. automodule:: bob.measure
.. automodule:: bob.measure.calibration
.. automodule:: bob.measure.plot
.. automodule:: bob.measure.load
Supports Markdown
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