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

Complete design and doc of HammingDistance

parent fd73f70f
......@@ -3,35 +3,32 @@
from bob.bio.base.algorithm import Distance
import scipy.spatial.distance
class HammingDistance (Distance):
"""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 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.
The enrollement and scoring functions of this class are implemented by its
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
Set this parameter to ``scipy.spatial.distance.hamming`` to ensure we are calculating the Hamming distance
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.
``is_distance_function`` : bool
Set this flag to ``False`` to ensure that Hamming distances are returned as positive values rather than negative
The base clas constructor parameter ``is_distance_function`` is set to
``False`` on purpose to ensure that calculated distances are returned as
positive values rather than negative.
"""
def __init__(
self,
distance_function = scipy.spatial.distance.hamming,
is_distance_function = False # setting this to False ensures that Hamming distances are returned as positive values rather than negative
):
# Call base class constructor
Distance.__init__(
self,
distance_function = distance_function,
is_distance_function = is_distance_function
)
\ No newline at end of file
def __init__(self):
from scipy.spatial.distance import hamming
super(HammingDistance, self).__init__(
distance_function = hamming,
is_distance_function = False,
)
from .MiuraMatch import MiuraMatch
from .MiuraMatchRotationFast import MiuraMatchRotationFast
from .Correlate import Correlate
from .HammingDistance import HammingDistance
......@@ -19,7 +18,6 @@ def __appropriate__(*args):
__appropriate__(
MiuraMatch,
MiuraMatchRotationFast,
Correlate,
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