From ddaf57497c7afccf8a01ed8512744f7c4e17b601 Mon Sep 17 00:00:00 2001 From: Andre Anjos Date: Fri, 20 Oct 2017 11:28:00 +0200 Subject: [PATCH] Complete design and doc of HammingDistance --- bob/bio/vein/algorithm/HammingDistance.py | 39 +++++++++++------------ bob/bio/vein/algorithm/__init__.py | 2 -- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/bob/bio/vein/algorithm/HammingDistance.py b/bob/bio/vein/algorithm/HammingDistance.py index cfa5c29..ac1446d 100644 --- a/bob/bio/vein/algorithm/HammingDistance.py +++ b/bob/bio/vein/algorithm/HammingDistance.py @@ -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 `_ 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, + ) diff --git a/bob/bio/vein/algorithm/__init__.py b/bob/bio/vein/algorithm/__init__.py index 793f107..e69a1e6 100644 --- a/bob/bio/vein/algorithm/__init__.py +++ b/bob/bio/vein/algorithm/__init__.py @@ -1,5 +1,4 @@ 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, ) -- 2.21.0