For open set recognition, i.e., when there exist a tuple including negative scores without corresponding positive scores (``None``), and **all** negative scores are below ``threshold`` :math:`\\max\\{S_p^+\\} < \\theta`, the probe item is correctly rejected, **and it does not count into the denominator** :math:`P`.
When no ``threshold`` is provided, the open set probes will **always** count as misclassified, regardless of the ``rank``.
.. warn:
For open set tests, this rate does not correspond to a standard rate.
Please use :py:func:`detection_identification_rate` and :py:func:`false_alarm_rate` instead.
Each pair contains the ``negative`` and the ``positive`` scores for **one probe item**.
Each pair can contain up to one empty array (or ``None``), i.e., in case of open set recognition.
``rank`` : int or ``None``
The rank for which the recognition rate should be computed, 1 by default.
``threshold`` : float or ``None``
Decision threshold. If not ``None``, **all** scores will be filtered by the threshold.
In an open set recognition problem, all open set scores (negatives with no corresponding positive) for which all scores are below threshold, will be counted as correctly rejected and **removed** from the probe list (i.e., the denominator).
``rank`` : int or ``None``
The rank for which the recognition rate should be computed, 1 by default.
"""detection_identification_rate(cmc_scores, threshold, rank) -> dir
Computes the `detection and identification rate` for the given threshold.
This value is designed to be used in an open set identification protocol, and defined in Chapter 14.1 of [LiJain2005]_.
Although the detection and identification rate is designed to be computed on an open set protocol, it uses only the probe elements, for which a corresponding gallery element exists.
For closed set identification protocols, this function is identical to :py:func:`recognition_rate`.
The only difference is that for this function, a ``threshold`` for the scores need to be defined, while for :py:func:`recognition_rate` it is optional.
CMC scores loaded with one of the functions (:py:func:`bob.measure.load.cmc_four_column` or :py:func:`bob.measure.load.cmc_five_column`).
Each pair contains the ``negative`` and the ``positive`` scores for **one probe item**.
There need to be at least one probe item, for which positive and negative scores exist.
``threshold`` : float
The decision threshold :math:`\\tau``.
``rank`` : int
The rank for which the curve should be plotted, by default 1.
**Returns:**
``dir`` : float
The detection and identification rate for the given threshold.
"""
# count the correctly classifier probes
correct=0
counter=0
forneg,posincmc_scores:
ifposisNoneornotnumpy.array(pos).size:
# we only consider probes with corresponding gallery items
continue
# we have an in-gallery probe
counter+=1
# check, if it is correctly classified
ifnegisNone:
neg=[]
# get the maximum positive score for the current probe item
# (usually, there is only one positive score, but just in case...)
max_pos=numpy.max(pos)
index=numpy.sum(neg>=max_pos)# compute the rank (in fact, rank - 1)
ifmax_pos>=thresholdandindex<rank:
correct+=1
ifnotcounter:
logger.warn("No in-gallery probe was found")
return0.
returnfloat(correct)/float(counter)
deffalse_alarm_rate(cmc_scores,threshold):
"""false_alarm_rate(cmc_scores, threshold) -> far
Computes the `false alarm rate` for the given threshold,.
This value is designed to be used in an open set identification protocol, and defined in Chapter 14.1 of [LiJain2005]_.
The false alarm rate is designed to be computed on an open set protocol, it uses only the probe elements, for which **no** corresponding gallery element exists.
See :py:func:`bob.measure.detection_identification_rate`
``far_values`` : [float]
The values for the FAR, where the CAR should be plotted; each value should be in range [0,1].
``rank`` : int or ``None``
The rank for which the curve should be plotted. If ``None``, rank 1 is assumed.
The rank for which the curve should be plotted, 1 by default.
``logx`` : bool
Plot the FAR axis in logarithmic scale using :py:func:`matplotlib.pyplot.semilogx` or in linear scale using :py:func:`matplotlib.pyplot.plot`? (Default: ``True``)