HammingDistance.py 1.2 KB
Newer Older
1 2
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
3

4 5 6 7 8

from bob.bio.base.algorithm import Distance


class HammingDistance (Distance):
9 10
  """This class calculates the Hamming distance between two binary images.

11 12
  The enrollement and scoring functions of this class are implemented by its
  base :py:class:`bob.bio.base.algorithm.Distance`.
13

14 15 16 17
  The input to this function should be of binary nature (boolean arrays). Each
  binary input is first flattened to form a one-dimensional vector. The `Hamming
  distance <https://en.wikipedia.org/wiki/Hamming_distance>`_ is then
  calculated between these two binary vectors.
18

19 20 21
  The current implementation uses :py:func:`scipy.spatial.distance.hamming`,
  which returns a scalar 64-bit ``float`` to represent the proportion of
  mismatching corresponding bits between the two binary vectors.
22

André Anjos's avatar
André Anjos committed
23
  The base class constructor parameter ``is_distance_function`` is set to
24 25
  ``False`` on purpose to ensure that calculated distances are returned as
  positive values rather than negative.
26

27 28
  """

29 30 31 32 33 34
  def __init__(self):
    from scipy.spatial.distance import hamming
    super(HammingDistance, self).__init__(
        distance_function = hamming,
        is_distance_function = False,
        )