guide.rst 21.5 KB
Newer Older
André Anjos's avatar
André Anjos committed
1 2 3 4
.. vim: set fileencoding=utf-8 :
.. Andre Anjos <andre.dos.anjos@gmail.com>
.. Tue 15 Oct 17:41:52 2013

André Anjos's avatar
André Anjos committed
5
.. testsetup:: *
André Anjos's avatar
André Anjos committed
6

André Anjos's avatar
André Anjos committed
7 8 9 10 11 12
  import numpy
  positives = numpy.random.normal(1,1,100)
  negatives = numpy.random.normal(-1,1,100)
  import matplotlib
  if not hasattr(matplotlib, 'backends'):
    matplotlib.use('pdf') #non-interactive avoids exception on display
André Anjos's avatar
André Anjos committed
13
  import bob.measure
André Anjos's avatar
André Anjos committed
14 15 16 17 18

============
 User Guide
============

André Anjos's avatar
André Anjos committed
19
Methods in the :py:mod:`bob.measure` module can help you to quickly and easily
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
evaluate error for multi-class or binary classification problems. If you are
not yet familiarized with aspects of performance evaluation, we recommend the
following papers for an overview of some of the methods implemented.

* Bengio, S., Keller, M., Mariéthoz, J. (2004). `The Expected Performance
  Curve`_.  International Conference on Machine Learning ICML Workshop on ROC
  Analysis in Machine Learning, 136(1), 19631966.
* Martin, A., Doddington, G., Kamm, T., Ordowski, M., & Przybocki, M. (1997).
  `The DET curve in assessment of detection task performance`_. Fifth European
  Conference on Speech Communication and Technology (pp. 1895-1898).

Overview
--------

A classifier is subject to two types of errors, either the real access/signal
is rejected (false rejection) or an impostor attack/a false access is accepted
(false acceptance). A possible way to measure the detection performance is to
use the Half Total Error Rate (HTER), which combines the False Rejection Rate
(FRR) and the False Acceptance Rate (FAR) and is defined in the following
formula:

.. math::

  HTER(\tau, \mathcal{D}) = \frac{FAR(\tau, \mathcal{D}) + FRR(\tau, \mathcal{D})}{2} \quad \textrm{[\%]}

where :math:`\mathcal{D}` denotes the dataset used. Since both the FAR and the
FRR depends on the threshold :math:`\tau`, they are strongly related to each
other: increasing the FAR will reduce the FRR and vice-versa. For this reason,
results are often presented using either a Receiver Operating Characteristic
(ROC) or a Detection-Error Tradeoff (DET) plot, these two plots basically
present the FAR versus the FRR for different values of the threshold. Another
widely used measure to summarise the performance of a system is the Equal Error
Rate (EER), defined as the point along the ROC or DET curve where the FAR
equals the FRR.

However, it was noted in by Bengio et al. (2004) that ROC and DET curves may be
misleading when comparing systems. Hence, the so-called Expected Performance
Curve (EPC) was proposed and consists of an unbiased estimate of the reachable
performance of a system at various operating points.  Indeed, in real-world
scenarios, the threshold :math:`\tau` has to be set a priori: this is typically
done using a development set (also called cross-validation set). Nevertheless,
the optimal threshold can be different depending on the relative importance
given to the FAR and the FRR. Hence, in the EPC framework, the cost
:math:`\beta \in [0;1]` is defined as the tradeoff between the FAR and FRR. The
optimal threshold :math:`\tau^*` is then computed using different values of
:math:`\beta`, corresponding to different operating points:

.. math::
  \tau^{*} = \arg\!\min_{\tau} \quad \beta \cdot \textrm{FAR}(\tau, \mathcal{D}_{d}) + (1-\beta) \cdot \textrm{FRR}(\tau, \mathcal{D}_{d})

where :math:`\mathcal{D}_{d}` denotes the development set and should be
completely separate to the evaluation set `\mathcal{D}`.

Performance for different values of :math:`\beta` is then computed on the test
set :math:`\mathcal{D}_{t}` using the previously derived threshold. Note that
setting :math:`\beta` to 0.5 yields to the Half Total Error Rate (HTER) as
defined in the first equation.
André Anjos's avatar
André Anjos committed
77 78 79

.. note::

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  Most of the methods availabe in this module require as input a set of 2
  :py:class:`numpy.ndarray` objects that contain the scores obtained by the
  classification system to be evaluated, without specific order. Most of the
  classes that are defined to deal with two-class problems. Therefore, in this
  setting, and throughout this manual, we have defined that the **negatives**
  represents the impostor attacks or false class accesses (that is when a
  sample of class A is given to the classifier of another class, such as class
  B) for of the classifier. The second set, refered as the **positives**
  represents the true class accesses or signal response of the classifier. The
  vectors are called this way because the procedures implemented in this module
  expects that the scores of **negatives** to be statistically distributed to
  the left of the signal scores (the **positives**). If that is not the case,
  one should either invert the input to the methods or multiply all scores
  available by -1, in order to have them inverted.

  The input to create these two vectors is generated by experiments conducted
  by the user and normally sits in files that may need some parsing before
  these vectors can be extracted.

  While it is not possible to provide a parser for every individual file that
  may be generated in different experimental frameworks, we do provide a few
  parsers for formats we use the most. Please refer to the documentation of
  :py:mod:`bob.measure.load` for a list of formats and details.

  In the remainder of this section we assume you have successfuly parsed and
  loaded your scores in two 1D float64 vectors and are ready to evaluate the
  performance of the classifier.
André Anjos's avatar
André Anjos committed
107

108 109
Evaluation
----------
André Anjos's avatar
André Anjos committed
110

111 112
To count the number of correctly classified positives and negatives you can use
the following techniques:
André Anjos's avatar
André Anjos committed
113 114 115

.. doctest::

116 117
  >>> # negatives, positives = parse_my_scores(...) # write parser if not provided!
  >>> T = 0.0 #Threshold: later we explain how one can calculate these
André Anjos's avatar
André Anjos committed
118
  >>> correct_negatives = bob.measure.correctly_classified_negatives(negatives, T)
119
  >>> FAR = 1 - (float(correct_negatives.sum())/negatives.size)
André Anjos's avatar
André Anjos committed
120
  >>> correct_positives = bob.measure.correctly_classified_positives(positives, T)
121
  >>> FRR = 1 - (float(correct_positives.sum())/positives.size)
André Anjos's avatar
André Anjos committed
122

123
We do provide a method to calculate the FAR and FRR in a single shot:
André Anjos's avatar
André Anjos committed
124 125 126

.. doctest::

André Anjos's avatar
André Anjos committed
127
  >>> FAR, FRR = bob.measure.farfrr(negatives, positives, T)
André Anjos's avatar
André Anjos committed
128

129 130 131 132 133 134
The threshold ``T`` is normally calculated by looking at the distribution of
negatives and positives in a development (or validation) set, selecting a
threshold that matches a certain criterion and applying this derived threshold
to the test (or evaluation) set. This technique gives a better overview of the
generalization of a method. We implement different techniques for the
calculation of the threshold:
André Anjos's avatar
André Anjos committed
135

136
* Threshold for the EER
André Anjos's avatar
André Anjos committed
137

138
  .. doctest::
André Anjos's avatar
André Anjos committed
139

André Anjos's avatar
André Anjos committed
140
    >>> T = bob.measure.eer_threshold(negatives, positives)
André Anjos's avatar
André Anjos committed
141

142
* Threshold for the minimum HTER
André Anjos's avatar
André Anjos committed
143

144
  .. doctest::
André Anjos's avatar
André Anjos committed
145

André Anjos's avatar
André Anjos committed
146
    >>> T = bob.measure.min_hter_threshold(negatives, positives)
André Anjos's avatar
André Anjos committed
147

148 149
* Threshold for the minimum weighted error rate (MWER) given a certain cost
  :math:`\beta`.
André Anjos's avatar
André Anjos committed
150

151
  .. code-block:: python
André Anjos's avatar
André Anjos committed
152

153
     >>> cost = 0.3 #or "beta"
André Anjos's avatar
André Anjos committed
154
     >>> T = bob.measure.min_weighted_error_rate_threshold(negatives, positives, cost)
André Anjos's avatar
André Anjos committed
155

156
  .. note::
André Anjos's avatar
André Anjos committed
157

158
    By setting cost to 0.5 is equivalent to use
André Anjos's avatar
André Anjos committed
159
    :py:meth:`bob.measure.min_hter_threshold`.
André Anjos's avatar
André Anjos committed
160

161 162
Plotting
--------
André Anjos's avatar
André Anjos committed
163

164 165 166
An image is worth 1000 words, they say. You can combine the capabilities of
`Matplotlib`_ with |project| to plot a number of curves. However, you must have that
package installed though. In this section we describe a few recipes.
André Anjos's avatar
André Anjos committed
167

168 169
ROC
===
André Anjos's avatar
André Anjos committed
170

171 172 173
The Receiver Operating Characteristic (ROC) curve is one of the oldest plots in
town. To plot an ROC curve, in possession of your **negatives** and
**positives**, just do something along the lines of:
André Anjos's avatar
André Anjos committed
174 175 176

.. doctest::

177 178 179
  >>> from matplotlib import pyplot
  >>> # we assume you have your negatives and positives already split
  >>> npoints = 100
André Anjos's avatar
André Anjos committed
180
  >>> bob.measure.plot.roc(negatives, positives, npoints, color=(0,0,0), linestyle='-', label='test') # doctest: +SKIP
181 182
  >>> pyplot.xlabel('FAR (%)') # doctest: +SKIP
  >>> pyplot.ylabel('FRR (%)') # doctest: +SKIP
183 184
  >>> pyplot.grid(True)
  >>> pyplot.show() # doctest: +SKIP
André Anjos's avatar
André Anjos committed
185

186
You should see an image like the following one:
André Anjos's avatar
André Anjos committed
187

André Anjos's avatar
André Anjos committed
188 189 190
.. plot::

   import numpy
André Anjos's avatar
André Anjos committed
191
   import bob.measure
André Anjos's avatar
André Anjos committed
192 193 194 195 196
   from matplotlib import pyplot

   positives = numpy.random.normal(1,1,100)
   negatives = numpy.random.normal(-1,1,100)
   npoints = 100
André Anjos's avatar
André Anjos committed
197
   bob.measure.plot.roc(negatives, positives, npoints, color=(0,0,0), linestyle='-', label='test')
André Anjos's avatar
André Anjos committed
198 199 200 201
   pyplot.grid(True)
   pyplot.xlabel('FAR (%)')
   pyplot.ylabel('FRR (%)')
   pyplot.title('ROC')
André Anjos's avatar
André Anjos committed
202

203
As can be observed, plotting methods live in the namespace
André Anjos's avatar
André Anjos committed
204
:py:mod:`bob.measure.plot`. They work like `Matplotlib`_'s `plot()`_ method
205 206 207 208
itself, except that instead of receiving the x and y point coordinates as
parameters, they receive the two :py:class:`numpy.ndarray` arrays with
negatives and positives, as well as an indication of the number of points the
curve must contain.
André Anjos's avatar
André Anjos committed
209

210 211 212 213 214 215
As in `Matplotlib`_'s `plot()`_ command, you can pass optional parameters for
the line as shown in the example to setup its color, shape and even the label.
For an overview of the keywords accepted, please refer to the `Matplotlib`_'s
Documentation. Other plot properties such as the plot title, axis labels,
grids, legends should be controlled directly using the relevant `Matplotlib`_'s
controls.
André Anjos's avatar
André Anjos committed
216

217 218
DET
===
André Anjos's avatar
André Anjos committed
219

220
A DET curve can be drawn using similar commands such as the ones for the ROC curve:
André Anjos's avatar
André Anjos committed
221 222 223

.. doctest::

224 225 226
  >>> from matplotlib import pyplot
  >>> # we assume you have your negatives and positives already split
  >>> npoints = 100
André Anjos's avatar
André Anjos committed
227 228
  >>> bob.measure.plot.det(negatives, positives, npoints, color=(0,0,0), linestyle='-', label='test') # doctest: +SKIP
  >>> bob.measure.plot.det_axis([0.01, 40, 0.01, 40]) # doctest: +SKIP
229 230 231 232
  >>> pyplot.xlabel('FAR (%)') # doctest: +SKIP
  >>> pyplot.ylabel('FRR (%)') # doctest: +SKIP
  >>> pyplot.grid(True)
  >>> pyplot.show() # doctest: +SKIP
André Anjos's avatar
André Anjos committed
233

234
This will produce an image like the following one:
André Anjos's avatar
André Anjos committed
235

André Anjos's avatar
André Anjos committed
236 237 238
.. plot::

   import numpy
André Anjos's avatar
André Anjos committed
239
   import bob.measure
André Anjos's avatar
André Anjos committed
240 241 242 243 244 245
   from matplotlib import pyplot

   positives = numpy.random.normal(1,1,100)
   negatives = numpy.random.normal(-1,1,100)

   npoints = 100
André Anjos's avatar
André Anjos committed
246 247
   bob.measure.plot.det(negatives, positives, npoints, color=(0,0,0), linestyle='-', label='test')
   bob.measure.plot.det_axis([0.1, 80, 0.1, 80])
André Anjos's avatar
André Anjos committed
248 249 250 251
   pyplot.grid(True)
   pyplot.xlabel('FAR (%)')
   pyplot.ylabel('FRR (%)')
   pyplot.title('DET')
André Anjos's avatar
André Anjos committed
252 253 254

.. note::

255 256 257
  If you wish to reset axis zooming, you must use the Gaussian scale rather
  than the visual marks showed at the plot, which are just there for
  displaying purposes. The real axis scale is based on the
258
  :py:func:`bob.measure.ppndf` method. For example, if you wish to set the x and y
259
  axis to display data between 1% and 40% here is the recipe:
André Anjos's avatar
André Anjos committed
260

261
  .. doctest::
André Anjos's avatar
André Anjos committed
262

263
    >>> #AFTER you plot the DET curve, just set the axis in this way:
André Anjos's avatar
André Anjos committed
264
    >>> pyplot.axis([bob.measure.ppndf(k/100.0) for k in (1, 40, 1, 40)]) # doctest: +SKIP
André Anjos's avatar
André Anjos committed
265

266
  We provide a convenient way for you to do the above in this module. So,
André Anjos's avatar
André Anjos committed
267
  optionally, you may use the ``bob.measure.plot.det_axis`` method like this:
André Anjos's avatar
André Anjos committed
268

269
  .. doctest::
André Anjos's avatar
André Anjos committed
270

André Anjos's avatar
André Anjos committed
271
    >>> bob.measure.plot.det_axis([1, 40, 1, 40]) # doctest: +SKIP
André Anjos's avatar
André Anjos committed
272

273 274
EPC
===
André Anjos's avatar
André Anjos committed
275

276
Drawing an EPC requires that both the development set negatives and positives are provided alongside
277
the test (or evaluation) set ones. Because of this the API is slightly modified:
André Anjos's avatar
André Anjos committed
278 279 280

.. doctest::

André Anjos's avatar
André Anjos committed
281
  >>> bob.measure.plot.epc(dev_neg, dev_pos, test_neg, test_pos, npoints, color=(0,0,0), linestyle='-') # doctest: +SKIP
282
  >>> pyplot.show() # doctest: +SKIP
André Anjos's avatar
André Anjos committed
283

284
This will produce an image like the following one:
André Anjos's avatar
André Anjos committed
285

André Anjos's avatar
André Anjos committed
286 287 288
.. plot::

   import numpy
André Anjos's avatar
André Anjos committed
289
   import bob.measure
André Anjos's avatar
André Anjos committed
290 291 292 293 294 295 296
   from matplotlib import pyplot

   dev_pos = numpy.random.normal(1,1,100)
   dev_neg = numpy.random.normal(-1,1,100)
   test_pos = numpy.random.normal(0.9,1,100)
   test_neg = numpy.random.normal(-1.1,1,100)
   npoints = 100
André Anjos's avatar
André Anjos committed
297
   bob.measure.plot.epc(dev_neg, dev_pos, test_neg, test_pos, npoints, color=(0,0,0), linestyle='-')
André Anjos's avatar
André Anjos committed
298 299
   pyplot.grid(True)
   pyplot.title('EPC')
André Anjos's avatar
André Anjos committed
300

301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

CMC
===

The Cumulative Match Characteristics (CMC) curve estimates the probability that the correct model is in the *N* models with the highest similarity to a given probe.
A CMC curve can be plotted using the :py:func:`bob.measure.plot.cmc` function.
The CMC can be calculated from a relatively complex data structure, which defines a pair of positive and negative scores **per probe**:

.. plot::

   import numpy
   import bob.measure
   from matplotlib import pyplot

   scores = []
   for probe in range(10):
     positives = numpy.random.normal(1, 1, 1)
     negatives = numpy.random.normal(0, 1, 19)
     scores.append((negatives, positives))
   bob.measure.plot.cmc(scores, logx=False)
   pyplot.title('CMC')
   pyplot.xlabel('Rank')
   pyplot.xticks([1,5,10,20])
   pyplot.xlim([1,20])
   pyplot.ylim([0,100])

Usually, there is only a single positive score per probe, but this is not a fixed restriction.

.. note::
   The complex data structure can be read from our default 4 or 5 column score files using the :py:func:`bob.measure.load.cmc_four_column` or :py:func:`bob.measure.load.cmc_five_column` function.

332 333
Fine-tunning
============
André Anjos's avatar
André Anjos committed
334

André Anjos's avatar
André Anjos committed
335 336
The methods inside :py:mod:`bob.measure.plot` are only provided as a
`Matplotlib`_ wrapper to equivalent methods in :py:mod:`bob.measure` that can
337 338
only calculate the points without doing any plotting. You may prefer to tweak
the plotting or even use a different plotting system such as gnuplot. Have a
André Anjos's avatar
André Anjos committed
339
look at the implementations at :py:mod:`bob.measure.plot` to understand how
340 341 342 343 344 345 346 347 348
to use the |project| methods to compute the curves and interlace that in the
way that best suits you.

Full applications
-----------------

We do provide a few scripts that can be used to quickly evaluate a set of
scores. We present these scripts in this section. The scripts take as input
either a 4-column or 5-column data format as specified in the documentation of
349 350
:py:func:`bob.measure.load.four_column` or
:py:func:`bob.measure.load.five_column`.
351 352 353 354 355 356

To calculate the threshold using a certain criterion (EER, min.HTER or weighted
Error Rate) on a set, after setting up |project|, just do:

.. code-block:: sh

André Anjos's avatar
André Anjos committed
357
  $ bob_eval_threshold.py --scores=development-scores-4col.txt
358 359 360 361 362 363 364 365 366 367
  Threshold: -0.004787956164
  FAR : 6.731% (35/520)
  FRR : 6.667% (26/390)
  HTER: 6.699%

The output will present the threshold together with the FAR, FRR and HTER on
the given set, calculated using such a threshold. The relative counts of FAs
and FRs are also displayed between parenthesis.

To evaluate the performance of a new score file with a given threshold, use the
André Anjos's avatar
André Anjos committed
368
application ``bob_apply_threshold.py``:
369 370 371

.. code-block:: sh

André Anjos's avatar
André Anjos committed
372
  $ bob_apply_threshold.py --scores=test-scores-4col.txt --threshold=-0.0047879
373 374 375 376 377 378
  FAR : 2.115% (11/520)
  FRR : 7.179% (28/390)
  HTER: 4.647%

In this case, only the error figures are presented. You can conduct the
evaluation and plotting of development and test set data using our combined
André Anjos's avatar
André Anjos committed
379
``bob_compute_perf.py`` script. You pass both sets and it does the rest:
380 381 382

.. code-block:: sh

André Anjos's avatar
André Anjos committed
383
  $ bob_compute_perf.py --devel=development-scores-4col.txt --test=test-scores-4col.txt
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
  [Min. criterium: EER] Threshold on Development set: -4.787956e-03
         | Development     | Test
  -------+-----------------+------------------
    FAR  | 6.731% (35/520) | 2.500% (13/520)
    FRR  | 6.667% (26/390) | 6.154% (24/390)
    HTER | 6.699%          | 4.327%
  [Min. criterium: Min. HTER] Threshold on Development set: 3.411070e-03
         | Development     | Test
  -------+-----------------+------------------
    FAR  | 4.231% (22/520) | 1.923% (10/520)
    FRR  | 7.949% (31/390) | 7.692% (30/390)
    HTER | 6.090%          | 4.808%
  [Plots] Performance curves => 'curves.pdf'

Inside that script we evaluate 2 different thresholds based on the EER and the
minimum HTER on the development set and apply the output to the test set. As
can be seen from the toy-example above, the system generalizes reasonably well.
A single PDF file is generated containing an EPC as well as ROC and DET plots of such a
system.

Use the ``--help`` option on the above-cited scripts to find-out about more
options.
André Anjos's avatar
André Anjos committed
406

407 408 409 410 411 412 413

Score file conversion
---------------------

Sometimes, it is required to export the score files generated by Bob to a different format, e.g., to be able to generate a plot comparing Bob's systems with other systems.
In this package, we provide source code to convert between different types of score files.

414 415 416 417
Bob to OpenBR
=============

One of the supported formats is the matrix format that the National Institute of Standards and Technology (NIST) uses, and which is supported by OpenBR_.
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
The scores are stored in two binary matrices, where the first matrix (usually with a ``.mtx`` filename extension) contains the raw scores, while a second mask matrix (extension ``.mask``) contains information, which scores are positives, and which are negatives.

To convert from Bob's four column or five column score file to a pair of these matrices, you can use the :py:func:`bob.measure.openbr.write_matrix` function.
In the simplest way, this function takes a score file ``'five-column-sore-file'`` and writes the pair ``'openbr.mtx', 'openbr.mask'`` of OpenBR compatible files:

.. code-block:: py

   >>> bob.measure.openbr.write_matrix('five-column-sore-file', 'openbr.mtx', 'openbr.mask', score_file_format = '5column')

In this way, the score file will be parsed and the matrices will be written in the same order that is obtained from the score file.

For most of the applications, this should be sufficient, but as the identity information is lost in the matrix files, no deeper analysis is possible anymore when just using the matrices.
To enforce an order of the models and probes inside the matrices, you can use the ``model_names`` and ``probe_names`` parameters of :py:func:`bob.measure.openbr.write_matrix`:

* The ``probe_names`` parameter lists the ``path`` elements stored in the score files, which are the fourth column in a ``5column`` file, and the third column in a ``4column`` file, see :py:func:`bob.measure.load.five_column` and :py:func:`bob.measure.load.four_column`.

* The ``model_names`` parameter is a bit more complicated.
  In a ``5column`` format score file, the model names are defined by the second column of that file, see :py:func:`bob.measure.load.five_column`.
  In a ``4column`` format score file, the model information is not contained, but only the client information of the model.
  Hence, for the ``4column`` format, the ``model_names`` actually lists the client ids found in the first column, see :py:func:`bob.measure.load.four_column`.

  .. warning::
     The model information is lost, but required to write the matrix files.
     In the ``4column`` format, we use client ids instead of the model information.
     Hence, when several models exist per client, this function will not work as expected.

Additionally, there are fields in the matrix files, which define the gallery and probe list files that were used to generate the matrix.
These file names can be selected with the ``gallery_file_name`` and ``probe_file_name`` keyword parameters of :py:func:`bob.measure.openbr.write_matrix`.

Finally, OpenBR defines a specific ``'search'`` score file format, which is designed to be used to compute CMC curves.
The score matrix contains descendingly sorted and possibly truncated list of scores, i.e., for each probe, a sorted list of all scores for the models is generated.
To generate these special score file format, you can specify the ``search`` parameter.
It specifies the number of highest scores per probe that should be kept.
If the ``search`` parameter is set to a negative value, all scores will be kept.
If the ``search`` parameter is higher as the actual number of models, ``NaN`` scores will be appended, and the according mask values will be set to ``0`` (i.e., to be ignored).

454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479

OpenBR to Bob
=============

On the other hand, you might also want to generate a Bob-compatible (four or five column) score file based on a pair of OpenBR matrix and mask files.
This is possible by using the :py:func:`bob.measure.openbr.write_score_file` function.
At the basic, it takes the given pair of matrix and mask files, as well as the desired output score file:

.. code-block:: py

   >>> bob.measure.openbr.write_score_file('openbr.mtx', 'openbr.mask', 'four-column-sore-file')

This score file is sufficient to compute a CMC curve (see `CMC`_), however it does not contain relevant client ids or paths for models and probes.
Particularly, it assumes that each client has exactly one associated model.

To add/correct these information, you can use additional parameters to :py:func:`bob.measure.openbr.write_score_file`.
Client ids of models and probes can be added using the ``models_ids`` and ``probes_ids`` keyword arguments.
The length of these lists must be identical to the number of models and probes as given in the matrix files, **and they must be in the same order as used to compute the OpenBR matrix**.
This includes that the same same-client and different-client pairs as indicated by the OpenBR mask will be generated, which will be checked inside the function.

To add model and probe path information, the ``model_names`` and ``probe_names`` parameters, which need to have the same size and order as the ``models_ids`` and ``probes_ids``.
These information are simply stored in the score file, and no further check is applied.

.. note:: The ``model_names`` parameter is used only when writing score files in ``score_file_format='5column'``, in the ``'4column'`` format, this parameter is ignored.


André Anjos's avatar
André Anjos committed
480 481
.. include:: links.rst

482
.. Place youre references here:
André Anjos's avatar
André Anjos committed
483

484 485 486
.. _`The Expected Performance Curve`: http://publications.idiap.ch/downloads/reports/2005/bengio_2005_icml.pdf
.. _`The DET curve in assessment of detection task performance`: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.117.4489&rep=rep1&type=pdf
.. _`plot()`: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.plot
487
.. _openbr: http://openbiometrics.org