Commit cd6a04d2 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

Add histograms, vulnerability, epc, epsc, gen commands and corresponding tests

parent 01f51991
Pipeline #18941 failed with stage
in 39 minutes and 55 seconds
"""Generates PAD ISO compliant EPC based on the score files
"""
import click
from bob.measure.script import common_options
from bob.extension.scripts.click_helper import verbosity_option
from bob.bio.base.score import load
from . import figure
FUNC_SPLIT = lambda x: load.load_files(x, load.split)
@click.command()
@common_options.scores_argument(eval_mandatory=True, min_len=2, nargs=-1)
@common_options.output_plot_file_option(default_out='epc.pdf')
@common_options.titles_option()
@common_options.axis_fontsize_option()
@common_options.const_layout_option()
@common_options.figsize_option()
@common_options.bool_option(
'iapmr', 'I', 'Whether to plot the IAPMR related lines or not.', True
)
@verbosity_option()
@click.pass_context
def epc(ctx, scores, **kwargs):
"""Plot EPC (expected performance curve):
You need to provide 4 score
files for each biometric system in this order:
\b
* licit development scores
* licit evaluation scores
* spoof development scores
* spoof evaluation scores
See :ref:`bob.pad.base.vulnerability` in the documentation for a guide on
vulnerability analysis.
Examples:
$ bob pad epc dev-scores eval-scores
$ bob pad epc -o my_epc.pdf dev-scores1 eval-scores1
$ bob pad epc {licit,spoof}/scores-{dev,eval}
"""
process = figure.Epc(ctx, scores, True, FUNC_SPLIT)
process.run()
@click.command()
@common_options.scores_argument(eval_mandatory=True, min_len=2, nargs=-1)
@common_options.output_plot_file_option(default_out='epsc.pdf')
@common_options.titles_option()
@common_options.figsize_option()
@common_options.axis_fontsize_option()
@common_options.const_layout_option()
@common_options.bool_option(
'wer', 'w', 'Whether to plot the WER related lines or not.', True
)
@common_options.bool_option(
'three-d', 'D', 'If true, generate 3D plots', False
)
@common_options.bool_option(
'iapmr', 'I', 'Whether to plot the IAPMR related lines or not.', False
)
@click.option('-c', '--criteria', default="eer", show_default=True,
help='Criteria for threshold selection',
type=click.Choice(('eer', 'hter', 'wer')))
@click.option('-vp', '--var-param', default="omega", show_default=True,
help='Name of the varying parameter',
type=click.Choice(('omega', 'beta')))
@click.option('-fp', '--fixed-param', default=0.5, show_default=True,
help='Value of the fixed parameter',
type=click.FLOAT)
@verbosity_option()
@click.pass_context
def epsc(ctx, scores, criteria, var_param, fixed_param, three_d, **kwargs):
"""Plot EPSC (expected performance curve):
You need to provide 4 score
files for each biometric system in this order:
\b
* licit development scores
* licit evaluation scores
* spoof development scores
* spoof evaluation scores
See :ref:`bob.pad.base.vulnerability` in the documentation for a guide on
vulnerability analysis.
Note that when using 3D plots with option ``--three-d``, you cannot plot
both WER and IAPMR on the same figure (which is possible in 2D).
Examples:
$ bob pad epsc dev-scores eval-scores
$ bob pad epsc -o my_epsc.pdf dev-scores1 eval-scores1
$ bob pad epsc -D {licit,spoof}/scores-{dev,eval}
"""
if three_d:
if (ctx.meta['wer'] and ctx.meta['iapmr']):
raise click.BadParameter('Cannot plot both WER and IAPMR in 3D')
process = figure.Epsc3D(
ctx, scores, True, FUNC_SPLIT,
criteria, var_param, fixed_param
)
else:
process = figure.Epsc(
ctx, scores, True, FUNC_SPLIT,
criteria, var_param, fixed_param
)
process.run()
#!/usr/bin/env python
#Ivana Chingovska <ivana.chingovska@idiap.ch>
#Fri Dec 7 12:33:37 CET 2012
"""Utility functions for computation of EPSC curve and related measurement"""
import os
import sys
import bob.measure
import numpy
import argparse
def calc_pass_rate(threshold, attacks):
"""Calculates the rate of successful spoofing attacks
Keyword parameters:
- threshold - the threshold used for classification
- attack: numpy with the scores of the spoofing attacks
"""
return sum(1 for i in attacks if i >= threshold) / float(attacks.size)
def epc(dev_negatives, dev_positives, test_negatives, test_positives, points):
"""Reproduces the bob.measure.epc() functionality, but also returns the
thresholds on the 3rd column of the input data.
Keyword parameters:
- dev_negatives - numpy.array with scores of the negative samples of the dev set
- dev_positives - numpy.array with scores of the positive samples of the dev set
- test_negatives - numpy.array with scores of the negative samples of the test set
- test_positives - numpy.array with scores of the positive samples of the test set
- points - the number of points to be considered for the weight parameter
"""
retval = numpy.ndarray((points, 3), 'float64')
step = 1. / (float(points) - 1.) # step for the weight parameter
for i in range(points):
retval[i, 0] = i * step # weight parameter
retval[i, 2] = bob.measure.min_weighted_error_rate_threshold(
dev_negatives, dev_positives, retval[i, 0]) # threshold (dev set)
retval[i, 1] = sum(
bob.measure.farfrr(test_negatives, test_positives, retval[
i, 2])) / 2. # HTER error rate (test set)
return retval
def weighted_neg_error_rate_criteria(data,
weight,
thres,
beta=0.5,
criteria='eer'):
"""Given the single value for the weight parameter balancing between impostors and spoofing attacks and a threshold, calculates the error rates and their relationship depending on the criteria (difference in case of 'eer', hter in case of 'hter' criteria)
Keyword parameters:
- data - the development data used to determine the threshold. List on 4 numpy.arrays containing: negatives (licit), positives (licit), negatives (spoof), positivies (spoof)
- weight - the weight parameter balancing between impostors and spoofing attacks
- thres - the given threshold
- beta - the weight parameter balancing between real accesses and all the negative samples (impostors and spoofing attacks). Note that this parameter will be overriden and not considered if the selected criteria is 'hter'.
- criteria - 'eer', 'wer' or 'hter' criteria for decision threshold
"""
licit_neg = data[0]
licit_pos = data[1]
spoof_neg = data[2]
spoof_pos = data[3] # unpacking the data
farfrr_licit = bob.measure.farfrr(licit_neg, licit_pos, thres)
farfrr_spoof = bob.measure.farfrr(spoof_neg, spoof_pos, thres)
frr = farfrr_licit[1] # farfrr_spoof[1] should have the same value
far_i = farfrr_licit[0]
far_s = farfrr_spoof[0]
far_w = (1 - weight) * far_i + weight * far_s
if criteria == 'eer':
if beta == 0.5:
return abs(far_w - frr)
else:
#return abs(far_w - frr)
return abs((1 - beta) * frr - beta * far_w)
elif criteria == 'hter':
return (far_w + frr) / 2
else:
return (1 - beta) * frr + beta * far_w
def recursive_thr_search(data,
span_min,
span_max,
weight,
beta=0.5,
criteria='eer'):
"""Recursive search for the optimal threshold given a criteria. It evaluates the full range of thresholds at 100 points, and computes the one which optimizes the threshold. In the next search iteration, it examines the region around the point that optimizes the threshold. The procedure stops when the search range is smaller then 1e-10.
Keyword arguments:
- data - the development data used to determine the threshold. List on 4 numpy.arrays containing: negatives (licit), positives (licit), negatives (spoof), positivies (spoof)
- span_min - the minimum of the search range
- span_max - the maximum of the search range
- weight - the weight parameter balancing between impostors and spoofing attacks
- beta - the weight parameter balancing between real accesses and all the negative samples (impostors and spoofing attacks). Note that methods called within this function will override this parameter and not considered if the selected criteria is 'hter'.
- criteria - the decision threshold criteria ('eer' for EER, 'wer' for Minimum WER or 'hter' for Minimum HTER criteria).
"""
quit_thr = 1e-10
steps = 100
if abs((span_max - span_min) / span_max) < quit_thr:
return span_max # or span_min, it doesn't matter
else:
step_size = (span_max - span_min) / steps
thresholds = numpy.array(
[(i * step_size) + span_min for i in range(steps + 1)])
weighted_error_rates = numpy.array([
weighted_neg_error_rate_criteria(data, weight, thr, beta, criteria)
for thr in thresholds
])
selected_thres = thresholds[numpy.where(
weighted_error_rates == min(weighted_error_rates)
)] # all the thresholds which have minimum weighted error rate
thr = selected_thres[int(
selected_thres.size / 2
)] # choose the centrally positioned threshold
return recursive_thr_search(data, thr - step_size, thr + step_size,
weight, beta, criteria)
def weighted_negatives_threshold(licit_neg,
licit_pos,
spoof_neg,
spoof_pos,
weight,
beta=0.5,
criteria='eer'):
"""Calculates the threshold for achieving the given criteria between the FAR_w and the FRR, given the single value for the weight parameter balancing between impostors and spoofing attacks and a single value for the parameter beta balancing between the real accesses and the negatives (impostors and spoofing attacks)
Keyword parameters:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- weight - the weight parameter balancing between impostors and spoofing attacks
- beta - the weight parameter balancing between real accesses and all the negative samples (impostors and spoofing attacks). Note that methods called within this function will override this parameter and not considered if the selected criteria is 'hter'.
- criteria - the decision threshold criteria ('eer' for EER, 'wer' for Minimum WER or 'hter' for Minimum HTER criteria).
"""
span_min = min(
numpy.append(licit_neg, spoof_neg)
) # the min of the span where we will search for the threshold
span_max = max(
numpy.append(licit_pos, spoof_pos)
) # the max of the span where we will search for the threshold
data = (licit_neg, licit_pos, spoof_neg,
spoof_pos) # pack the data into a single list
return recursive_thr_search(data, span_min, span_max, weight, beta,
criteria)
def epsc_weights(licit_neg, licit_pos, spoof_neg, spoof_pos, points=100):
"""Returns the weights for EPSC
Keyword arguments:
- points - number of points to calculate EPSC
"""
step_size = 1 / float(points)
weights = numpy.array([(i * step_size) for i in range(points + 1)])
return weights
def epsc_thresholds(licit_neg,
licit_pos,
spoof_neg,
spoof_pos,
points=100,
criteria='eer',
omega=None,
beta=None):
"""Calculates the optimal thresholds for EPSC, for a range of the weight parameter balancing between impostors and spoofing attacks, and for a range of the beta parameter balancing between real accesses and all the negatives (impostors and spoofing attacks)
Keyword arguments:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- points - number of points to calculate EPSC
- criteria - the decision threshold criteria ('eer', 'wer' or 'hter')
- omega - the value of the parameter omega, balancing between impostors and spoofing attacks. If None, it is going to span the full range [0,1]. Otherwise, can be set to a fixed value or a list of values.
- beta - the value of the parameter beta, balancing between real accesses and all the negatives (zero-effort impostors and spoofing attacks). If None, it is going to span the full range [0,1]. Otherwise, can be set to a fixed value or a list of values.
"""
step_size = 1 / float(points)
if omega == None:
omega = numpy.array([(i * step_size) for i in range(points + 1)])
elif not isinstance(omega, list) and not isinstance(
omega, tuple) and not isinstance(omega, numpy.ndarray):
omega = numpy.array([omega])
else:
omega = numpy.array(omega)
if beta == None:
beta = numpy.array([(i * step_size) for i in range(points + 1)])
elif not isinstance(beta, list) and not isinstance(
beta, tuple) and not isinstance(beta, numpy.ndarray):
beta = numpy.array([beta])
else:
beta = numpy.array(beta)
thresholds = numpy.ndarray([beta.size, omega.size], 'float64')
for bindex, b in enumerate(beta):
thresholds[bindex, :] = numpy.array([
weighted_negatives_threshold(
licit_neg,
licit_pos,
spoof_neg,
spoof_pos,
w,
b,
criteria=criteria) for w in omega
], 'float64')
return omega, beta, thresholds
def weighted_err(error_1, error_2, weight):
"""Calculates the weighted error rate between the two input parameters
Keyword arguments:
- error_1 - the first input error rate (FAR for zero effort impostors usually)
- error_2 - the second input error rate (SFAR)
- weight - the given weight
"""
return (1 - weight) * error_1 + weight * error_2
def error_rates_at_weight(licit_neg,
licit_pos,
spoof_neg,
spoof_pos,
omega,
threshold,
beta=0.5):
"""Calculates several error rates: FRR, FAR (zero-effort impostors), SFAR, FAR_w, HTER_w for a given value of w. It returns the calculated threshold as a last argument
Keyword arguments:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- threshold - the given threshold
- omega - the omega parameter balancing between impostors and spoofing attacks
- beta - the weight parameter balancing between real accesses and all the negative samples (impostors and spoofing attacks).
"""
farfrr_licit = bob.measure.farfrr(
licit_neg, licit_pos,
threshold) # calculate test frr @ threshold (licit scenario)
farfrr_spoof = bob.measure.farfrr(
spoof_neg, spoof_pos,
threshold) # calculate test frr @ threshold (spoof scenario)
frr = farfrr_licit[
1] # we can take this value from farfrr_spoof as well, it doesn't matter
far = farfrr_licit[0]
sfar = farfrr_spoof[0]
far_w = weighted_err(far, sfar, omega)
hter_w = (far_w + frr) / 2
wer_wb = weighted_err(frr, far_w, beta)
return (frr, far, sfar, far_w, wer_wb, hter_w, threshold)
def epsc_error_rates(licit_neg, licit_pos, spoof_neg, spoof_pos, thresholds,
omega, beta):
"""Calculates several error rates: FAR_w and WER_wb for the given weights (omega and beta) and thresholds (the thresholds need to be computed first using the method: epsc_thresholds() before passing to this method)
Keyword arguments:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- thresholds - numpy.ndarray with threshold values
- omega - numpy.array of the omega parameter balancing between impostors and spoofing attacks
- beta - numpy.array of the beta parameter balancing between real accesses and all negatives (impostors and spoofing attacks)
"""
if not isinstance(omega, list) and not isinstance(
omega, tuple) and not isinstance(omega, numpy.ndarray):
omega = numpy.array([omega])
else:
omega = numpy.array(omega)
if not isinstance(beta, list) and not isinstance(
beta, tuple) and not isinstance(beta, numpy.ndarray):
beta = numpy.array([beta])
else:
beta = numpy.array(beta)
far_w_errors = numpy.ndarray((beta.size, omega.size), 'float64')
wer_wb_errors = numpy.ndarray((beta.size, omega.size), 'float64')
for bindex, b in enumerate(beta):
errors = [
error_rates_at_weight(licit_neg, licit_pos, spoof_neg, spoof_pos,
w, thresholds[bindex, windex], b)
for windex, w in enumerate(omega)
]
far_w_errors[bindex, :] = [errors[i][3] for i in range(len(errors))]
wer_wb_errors[bindex, :] = [errors[i][4] for i in range(len(errors))]
return far_w_errors, wer_wb_errors
def all_error_rates(licit_neg, licit_pos, spoof_neg, spoof_pos, thresholds,
omega, beta):
"""Calculates several error rates: FAR_w and HTER_w for the given weights (omega and beta) and thresholds (the thresholds need to be computed first using the method: epsc_thresholds() before passing to this method)
Keyword arguments:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- thresholds - numpy.array with threshold values
- omega - numpy.array of the omega parameter balancing between impostors and spoofing attacks
- beta - numpy.array of the beta parameter balancing between real accesses and all negatives (impostors and spoofing attacks)
"""
if not isinstance(omega, list) and not isinstance(
omega, tuple) and not isinstance(omega, numpy.ndarray):
omega = numpy.array([omega])
else:
omega = numpy.array(omega)
if not isinstance(beta, list) and not isinstance(
beta, tuple) and not isinstance(beta, numpy.ndarray):
beta = numpy.array([beta])
else:
beta = numpy.array(beta)
frr_errors = numpy.ndarray((beta.size, omega.size), 'float64')
far_errors = numpy.ndarray((beta.size, omega.size), 'float64')
sfar_errors = numpy.ndarray((beta.size, omega.size), 'float64')
far_w_errors = numpy.ndarray((beta.size, omega.size), 'float64')
wer_wb_errors = numpy.ndarray((beta.size, omega.size), 'float64')
hter_wb_errors = numpy.ndarray((beta.size, omega.size), 'float64')
for bindex, b in enumerate(beta):
errors = [
error_rates_at_weight(licit_neg, licit_pos, spoof_neg, spoof_pos,
w, thresholds[bindex, windex], b)
for windex, w in enumerate(omega)
]
frr_errors[bindex, :] = [errors[i][0] for i in range(len(errors))]
far_errors[bindex, :] = [errors[i][1] for i in range(len(errors))]
sfar_errors[bindex, :] = [errors[i][2] for i in range(len(errors))]
far_w_errors[bindex, :] = [errors[i][3] for i in range(len(errors))]
wer_wb_errors[bindex, :] = [errors[i][4] for i in range(len(errors))]
hter_wb_errors[bindex, :] = [errors[i][5] for i in range(len(errors))]
return frr_errors, far_errors, sfar_errors, far_w_errors, wer_wb_errors, hter_wb_errors
def calc_aue(licit_neg,
licit_pos,
spoof_neg,
spoof_pos,
thresholds,
omega,
beta,
l_bound=0,
h_bound=1,
var_param='omega'):
"""Calculates AUE of EPSC for the given thresholds and weights
Keyword arguments:
- licit_neg - numpy.array of scores for the negatives (licit scenario)
- licit_pos - numpy.array of scores for the positives (licit scenario)
- spoof_neg - numpy.array of scores for the negatives (spoof scenario)
- spoof_pos - numpy.array of scores for the positives (spoof scenario)
- l_bound - lower bound of integration
- h_bound - higher bound of integration
- points - number of points to calculate EPSC
- criteria - the decision threshold criteria ('eer', 'wer' or 'hter')
- var_param - name of the parameter which is varied on the abscissa ('omega' or 'beta')
"""
from scipy import integrate
if var_param == 'omega':
errors = all_error_rates(licit_neg, licit_pos, spoof_neg, spoof_pos,
thresholds, omega, beta)
weights = omega # setting the weights to the varying parameter
else:
errors = all_error_rates(licit_neg, licit_pos, spoof_neg, spoof_pos,
thresholds, omega, beta)
weights = beta # setting the weights to the varying parameter
wer_errors = errors[4].reshape(1, errors[4].size)
l_ind = numpy.where(weights >= l_bound)[0][0]
h_ind = numpy.where(weights <= h_bound)[0][-1]
aue = integrate.cumtrapz(wer_errors, weights)
aue = numpy.append(
[0], aue) # for indexing purposes, aue is cumulative integration
aue = aue[h_ind] - aue[l_ind]
return aue
'''Runs error analysis on score sets, outputs metrics and plots'''
import click
import numpy as np
import bob.measure.script.figure as measure_figure
from tabulate import tabulate
import matplotlib.pyplot as mpl
from bob.extension.scripts.click_helper import verbosity_option
from bob.measure.utils import (get_fta, get_thres)
from bob.measure import (
far_threshold, eer_threshold, min_hter_threshold, farfrr
)
from . import error_utils
ALL_CRITERIA = ('bpcer20', 'eer', 'min-hter')
def calc_threshold(method, neg, pos):
"""Calculates the threshold based on the given method.
The scores should be sorted!
Parameters
----------
method : str
One of ``bpcer201``, ``eer``, ``min-hter``.
neg : array_like
The negative scores. They should be sorted!
pos : array_like
The positive scores. They should be sorted!
Returns
-------
float
The calculated threshold.
Raises
------
ValueError
If method is unknown.
"""
method = method.lower()
if method == 'bpcer20':
threshold = far_threshold(neg, pos, 0.05, True)
elif method == 'eer':
threshold = eer_threshold(neg, pos, True)
elif method == 'min-hter':
threshold = min_hter_threshold(neg, pos, True)
else:
raise ValueError("Unknown threshold criteria: {}".format(method))
return threshold
class Metrics(measure_figure.Metrics):
def __init__(self, ctx, scores, evaluation, func_load):
super(Metrics, self).__init__(ctx, scores, evaluation, func_load)
''' Compute metrics from score files'''
def compute(self, idx, dev_score, dev_file=None,
eval_score=None, eval_file=None):
''' Compute metrics for the given criteria'''
dev_neg, dev_pos, _, eval_neg, eval_pos, _ =\
self._process_scores(dev_score, eval_score)
title = self._titles[idx] if self._titles is not None else None
headers = ['' or title, 'Development %s' % dev_file]
if self._eval and eval_score is not None:
headers.append('Eval. % s' % eval_file)
for m in ALL_CRITERIA:
raws = []
threshold = calc_threshold(m, dev_neg, dev_pos)
click.echo("\nThreshold of %f selected with the %s criteria" % (
threshold, m))
apcer, bpcer = farfrr(dev_neg, dev_pos, threshold)
raws.append(['BPCER20', '{:>5.1f}%'.format(apcer * 100)])
raws.append(['EER', '{:>5.1f}%'.format(bpcer * 100)])
raws.append(['min-HTER', '{:>5.1f}%'.format((apcer + bpcer) * 50)])
if self._eval and eval_neg is not None:
apcer, bpcer = farfrr(eval_neg, eval_pos, threshold)
raws[0].append('{:>5.1f}%'.format(apcer * 100))
raws[1].append('{:>5.1f}%'.format(bpcer * 100))
raws[2].append('{:>5.1f}%'.format((apcer + bpcer) * 50))
click.echo(
tabulate(raws, headers, self._tablefmt),
file=self.log_file
)
class HistPad(measure_figure.Hist):
''' Histograms for PAD '''
def _setup_hist(self, neg, pos):
self._title_base = 'PAD'
self._density_hist(
pos, label='Bona Fide', color='C1', **self._kwargs
)
self._density_hist(
neg, label='Presentation attack', alpha=0.4, color='C7',
hatch='\\\\', **self._kwargs
)
def _calc_pass_rate(threshold, scores):
return (scores >= threshold).mean()
def _iapmr_dot(threshold, iapmr, real_data, **kwargs):
# plot a dot on threshold versus IAPMR line and show IAPMR as a number
axlim = mpl.axis()
mpl.plot(threshold, 100. * iapmr, 'o', color='C3', **kwargs)
if not real_data:
mpl.annotate(
'IAPMR at\noperating point',
xy=(threshold, 100. * iapmr),
xycoords='data',
xytext=(0.85, 0.6),
textcoords='axes fraction',
color='black',
size='large',
arrowprops=dict(facecolor='black', shrink=0.05, width=2),
horizontalalignment='center',
verticalalignment='top',
)
else:
mpl.text(threshold + (threshold - axlim[0]) / 12, 100. * iapmr,
'%.1f%%' % (100. * iapmr,), color='C3')
def _iapmr_line_plot(scores, n_points=100, **kwargs):
axlim = mpl.axis()
step = (axlim[1] - axlim[0]) / float(n_points)
thres = [(k * step) + axlim[0] for k in range(2, n_points - 1)]
mix_prob_y = []
for k in thres:
mix_prob_y.append(100. * _calc_pass_rate(k, scores))
mpl.plot(thres, mix_prob_y, label='IAPMR', color='C3', **kwargs)
def _iapmr_plot(scores, threshold, iapmr, real_data, **kwargs):
_iapmr_dot(threshold, iapmr, real_data, **kwargs)
_iapmr_line_plot(scores, n_points=100, **kwargs)
class HistVuln(measure_figure.Hist):
''' Histograms for vulnerability '''
def _get_neg_pos_thres(self, idx, dev_score, eval_score):
assert len(dev_score) == self._min_arg
dev_neg_list = []
eval_neg_list = []
dev_pos_list = []
eval_pos_list = []
for i in range(self._min_arg):
dev_neg, dev_pos, _, eval_neg, eval_pos, _ = self._process_scores(
dev_score[i], eval_score[i]
)
dev_neg_list.append(dev_neg)
dev_pos_list.append(dev_pos)
eval_neg_list.append(eval_neg)
eval_pos_list.append(eval_pos)
threshold = get_thres(
self._criter, dev_neg_list[0], dev_pos_list[0]
) if self._thres is None else self._thres[idx]
return (dev_neg_list, dev_pos_list,
eval_neg_list, eval_pos_list, threshold)
def _setup_hist(self, neg, pos):
self._title_base = 'Vulnerability'