Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.bio.face
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bob
bob.bio.face
Merge requests
!184
Fix color functions
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix color functions
deprecation
into
master
Overview
0
Commits
4
Pipelines
2
Changes
4
Merged
Amir MOHAMMADI
requested to merge
deprecation
into
master
3 years ago
Overview
0
Commits
4
Pipelines
2
Changes
4
Expand
and remove bob.math and bob.core
0
0
Merge request reports
Compare
master
version 1
ab146d51
3 years ago
master (base)
and
latest version
latest version
3c84311e
4 commits,
3 years ago
version 1
ab146d51
3 commits,
3 years ago
4 files
+
84
−
46
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
bob/bio/face/algorithm/Histogram.py
+
54
−
3
Options
@@ -2,12 +2,63 @@
@@ -2,12 +2,63 @@
# vim: set fileencoding=utf-8 :
# vim: set fileencoding=utf-8 :
# Manuel Guenther <Manuel.Guenther@idiap.ch>
# Manuel Guenther <Manuel.Guenther@idiap.ch>
import
bob.math
import
numpy
import
numpy
from
bob.bio.base.algorithm
import
Algorithm
from
bob.bio.base.algorithm
import
Algorithm
def
chi_square
(
*
args
):
"""
Calculates the chi-square distance between two histograms.
@param hist1 The first histogram
@param hist2 The second histogram
@returns The chi-square distance between the two histograms
"""
if
len
(
args
)
==
2
:
h1
,
h2
=
args
d
=
0
for
i
in
range
(
h1
.
shape
[
0
]):
if
h1
[
i
]
!=
h2
[
i
]:
d
+=
int
(((
h1
[
i
]
-
h2
[
i
])
**
2
)
/
(
h1
[
i
]
+
h2
[
i
]))
return
d
else
:
# histogram intersection with sparse histograms
index_1
,
value_1
,
index_2
,
value_2
=
args
raise
NotImplementedError
(
"
chi_square distance with sparse histograms is not implemented yet
"
)
def
histogram_intersection
(
*
args
):
"""
Calculates the histogram intersection between two histograms.
@param hist1 The first histogram
@param hist2 The second histogram
@returns The histogram intersection between the two histograms
"""
if
len
(
args
)
==
2
:
hist1
,
hist2
=
args
return
numpy
.
sum
(
numpy
.
minimum
(
hist1
,
hist2
))
else
:
# histogram intersection with sparse histograms
index_1
,
value_1
,
index_2
,
value_2
=
args
i1
,
i2
,
i1_end
,
i2_end
=
0
,
0
,
index_1
.
shape
[
0
],
index_2
.
shape
[
0
]
p1
,
p2
=
index_1
[
i1
],
index_2
[
i2
]
sum
=
0
while
i1
<
i1_end
and
i2
<
i2_end
:
p1
=
index_1
[
i1
]
p2
=
index_2
[
i2
]
if
p1
==
p2
:
sum
+=
numpy
.
minimum
(
value_1
[
i1
],
value_2
[
i2
])
i1
+=
1
i2
+=
1
elif
p1
<
p2
:
i1
+=
1
else
:
i2
+=
1
return
sum
class
Histogram
(
Algorithm
):
class
Histogram
(
Algorithm
):
"""
Computes the distance between histogram sequences.
"""
Computes the distance between histogram sequences.
@@ -30,7 +81,7 @@ class Histogram (Algorithm):
@@ -30,7 +81,7 @@ class Histogram (Algorithm):
def
__init__
(
def
__init__
(
self
,
self
,
distance_function
=
bob
.
math
.
chi_square
,
distance_function
=
chi_square
,
is_distance_function
=
True
,
is_distance_function
=
True
,
multiple_probe_scoring
=
'
average
'
multiple_probe_scoring
=
'
average
'
):
):
Loading