Commit 3836f30c authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME
Browse files

Add generic loading function and corresponding test

parent 7ef58230
Pipeline #17751 passed with stage
in 18 minutes and 2 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`, ``file-like``:
The file object that will be opened with :py:func:`open_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[:, 0]
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
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)
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