Commit 2bd64323 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

lint and a small bugfix on score generation

parent 190eb6de
......@@ -10,6 +10,7 @@ import numpy
LOGGER = logging.getLogger('bob.measure')
def split(filename):
"""split(filename) -> negatives, positives
......@@ -36,7 +37,7 @@ def split(filename):
columns = numpy.loadtxt(filename)
neg_pos = columns[:, 0]
scores = columns[:, 1]
except:
except Exception:
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
......@@ -45,6 +46,7 @@ def split(filename):
return (scores[numpy.where(neg_pos == -1)],
scores[numpy.where(neg_pos == 1)])
def split_files(filenames):
"""split_files
......
......@@ -196,7 +196,7 @@ class Metrics(MeasureBase):
threshold),
file=self.log_file)
else:
click.echo("[Min. criterion: user provider] Threshold on "
click.echo("[Min. criterion: user provided] Threshold on "
"Development set `%s`: %e"
% (dev_file or title, threshold), file=self.log_file)
......
"""Generate random scores.
"""
import pkg_resources # to make sure bob gets imported properly
import os
import logging
import numpy
......@@ -15,6 +14,7 @@ logger = logging.getLogger(__name__)
NUM_NEG = 5000
NUM_POS = 5000
def gen_score_distr(mean_neg, mean_pos, sigma_neg=1, sigma_pos=1):
"""Generate scores from normal distributions
......@@ -47,17 +47,17 @@ def gen_score_distr(mean_neg, mean_pos, sigma_neg=1, sigma_pos=1):
return neg_scores, pos_scores
def write_scores_to_file(pos, neg, filename):
def write_scores_to_file(neg, pos, filename):
"""Writes score distributions into 2-column score files. For the format of
the 2-column score files, please refer to Bob's documentation. See
:py:func:`bob.measure.load.split`.
Parameters
----------
pos : :py:class:`numpy.ndarray`
Scores for positive samples.
neg : :py:class:`numpy.ndarray`
Scores for negative samples.
pos : :py:class:`numpy.ndarray`
Scores for positive samples.
filename : str
The path to write the score to.
"""
......@@ -72,6 +72,7 @@ def write_scores_to_file(pos, neg, filename):
text = '-1 %f\n' % i if nan_dist(mt) > 0.01 else '1 nan\n'
f.write(text)
@click.command()
@click.argument('outdir')
@click.option('--mean-neg', default=-1, type=FLOAT, show_default=True)
......
......@@ -4,6 +4,7 @@ import numpy
import scipy.stats
import bob.core
def remove_nan(scores):
"""remove_nan
......@@ -28,6 +29,7 @@ def remove_nan(scores):
logger.warning('Found {} NaNs in {} scores'.format(sum_nans, total))
return scores[numpy.where(~nans)], sum_nans, total
def get_fta(scores):
"""get_fta
calculates the Failure To Acquire (FtA) rate, i.e. proportion of NaN(s)
......@@ -53,6 +55,7 @@ def get_fta(scores):
fta_total += total
return ((neg, pos), fta_sum / fta_total)
def get_fta_list(scores):
""" Get FTAs for a list of scores
......@@ -84,6 +87,7 @@ def get_fta_list(scores):
fta_list.append(fta)
return (neg_list, pos_list, fta_list)
def get_thres(criter, neg, pos, far=None):
"""Get threshold for the given positive/negatives scores and criterion
......@@ -116,6 +120,7 @@ def get_thres(criter, neg, pos, far=None):
else:
raise ValueError("Incorrect plotting criterion: ``%s``" % criter)
def get_colors(n):
"""get_colors
Get a list of matplotlib colors
......@@ -135,7 +140,8 @@ def get_colors(n):
cmap = pyplot.cm.get_cmap(name='magma')
return [cmap(i) for i in numpy.linspace(0, 1.0, n + 1)]
return ['C0','C1','C2','C3','C4','C5','C6','C7','C8','C9']
return ['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9']
def get_linestyles(n, on=True):
"""Get a list of matplotlib linestyles
......@@ -154,24 +160,25 @@ def get_linestyles(n, on=True):
return [None] * n
list_linestyles = [
(0, ()), #solid
(0, (1, 1)), #densely dotted
(0, (5, 5)), #dashed
(0, (5, 1)), #densely dashed
(0, (3, 1, 1, 1, 1, 1)), #densely dashdotdotted
(0, (3, 10, 1, 10, 1, 10)), #loosely dashdotdotted
(0, (3, 5, 1, 5, 1, 5)), #dashdotdotted
(0, (3, 1, 1, 1)), #densely dashdotted
(0, (1, 5)), #dotted
(0, (3, 5, 1, 5)), #dashdotted
(0, (5, 10)), #loosely dashed
(0, (3, 10, 1, 10)), #loosely dashdotted
(0, (1, 10)) #loosely dotted
(0, ()), # solid
(0, (1, 1)), # densely dotted
(0, (5, 5)), # dashed
(0, (5, 1)), # densely dashed
(0, (3, 1, 1, 1, 1, 1)), # densely dashdotdotted
(0, (3, 10, 1, 10, 1, 10)), # loosely dashdotdotted
(0, (3, 5, 1, 5, 1, 5)), # dashdotdotted
(0, (3, 1, 1, 1)), # densely dashdotted
(0, (1, 5)), # dotted
(0, (3, 5, 1, 5)), # dashdotted
(0, (5, 10)), # loosely dashed
(0, (3, 10, 1, 10)), # loosely dashdotted
(0, (1, 10)) # loosely dotted
]
while n > len(list_linestyles):
list_linestyles += list_linestyles
return list_linestyles
def confidence_for_indicator_variable(x, n, alpha=0.05):
'''Calculates the confidence interval for proportion estimates
The Clopper-Pearson interval method is used for estimating the confidence
......
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