Coverage for src/bob/bio/vein/algorithm/HammingDistance.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-12 23:27 +0200

1#!/usr/bin/env python 

2# vim: set fileencoding=utf-8 : 

3 

4 

5from bob.bio.base.algorithm import Distance 

6 

7 

8class HammingDistance(Distance): 

9 """This class calculates the Hamming distance between two binary images. 

10 

11 The enrollement and scoring functions of this class are implemented by its 

12 base :py:class:`bob.bio.base.algorithm.Distance`. 

13 

14 The input to this function should be of binary nature (boolean arrays). Each 

15 binary input is first flattened to form a one-dimensional vector. The 

16 `Hamming distance <https://en.wikipedia.org/wiki/Hamming_distance>`_ is then 

17 calculated between these two binary vectors. 

18 

19 The current implementation uses :py:func:`scipy.spatial.distance.hamming`, 

20 which returns a scalar 64-bit ``float`` to represent the proportion of 

21 mismatching corresponding bits between the two binary vectors. 

22 

23 The base class constructor parameter ``factor`` is set to ``1`` on purpose 

24 to ensure that calculated distances are returned as positive values rather 

25 than negative. 

26 """ 

27 

28 def __init__(self, **kwargs): 

29 super(HammingDistance, self).__init__( 

30 distance_function="hamming", 

31 factor=1, 

32 **kwargs, 

33 )