Commit ddaf5749 authored by André Anjos's avatar André Anjos 💬

Complete design and doc of HammingDistance

parent fd73f70f
...@@ -3,35 +3,32 @@ ...@@ -3,35 +3,32 @@
from bob.bio.base.algorithm import Distance from bob.bio.base.algorithm import Distance
import scipy.spatial.distance
class HammingDistance (Distance): class HammingDistance (Distance):
"""This class calculates the Hamming distance between two binary images. """This class calculates the Hamming distance between two binary images.
Each binary image is first flattened by concatenating its rows to form a one-dimensional vector. The Hamming distance is then calculated between the two binary vectors. The enrollement and scoring functions of this class are implemented by its
The Hamming distance is computed using :py:func:`scipy.spatial.distance.hamming`, which returns a scalar ``float`` to represent the proportion of mismatching corresponding bits between the two binary vectors. base :py:class:`bob.bio.base.algorithm.Distance`.
**Parameters:** 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.
``distance_function`` : function The current implementation uses :py:func:`scipy.spatial.distance.hamming`,
Set this parameter to ``scipy.spatial.distance.hamming`` to ensure we are calculating the Hamming distance which returns a scalar 64-bit ``float`` to represent the proportion of
mismatching corresponding bits between the two binary vectors.
``is_distance_function`` : bool The base clas constructor parameter ``is_distance_function`` is set to
Set this flag to ``False`` to ensure that Hamming distances are returned as positive values rather than negative ``False`` on purpose to ensure that calculated distances are returned as
positive values rather than negative.
""" """
def __init__(self):
def __init__( from scipy.spatial.distance import hamming
self, super(HammingDistance, self).__init__(
distance_function = scipy.spatial.distance.hamming, distance_function = hamming,
is_distance_function = False # setting this to False ensures that Hamming distances are returned as positive values rather than negative is_distance_function = False,
): )
# Call base class constructor
Distance.__init__(
self,
distance_function = distance_function,
is_distance_function = is_distance_function
)
\ No newline at end of file
from .MiuraMatch import MiuraMatch from .MiuraMatch import MiuraMatch
from .MiuraMatchRotationFast import MiuraMatchRotationFast
from .Correlate import Correlate from .Correlate import Correlate
from .HammingDistance import HammingDistance from .HammingDistance import HammingDistance
...@@ -19,7 +18,6 @@ def __appropriate__(*args): ...@@ -19,7 +18,6 @@ def __appropriate__(*args):
__appropriate__( __appropriate__(
MiuraMatch, MiuraMatch,
MiuraMatchRotationFast,
Correlate, Correlate,
HammingDistance, HammingDistance,
) )
......
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