Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.em
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.learn.em
Commits
b8ed3f06
Commit
b8ed3f06
authored
3 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
[factor_analysis] merge tests into one file
parent
5ce317d2
No related branches found
No related tags found
1 merge request
!53
Factor Analysis on pure python
Pipeline
#60143
failed
3 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/learn/em/test/test_factor_analysis.py
+84
-4
84 additions, 4 deletions
bob/learn/em/test/test_factor_analysis.py
bob/learn/em/test/test_jfa.py
+0
-94
0 additions, 94 deletions
bob/learn/em/test/test_jfa.py
with
84 additions
and
98 deletions
bob/learn/em/test/test_
j
fa
_trainer
.py
→
bob/learn/em/test/test_fa
ctor_analysis
.py
+
84
−
4
View file @
b8ed3f06
#!/usr/bin/env python
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
# Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
# Tiago Freitas Pereira <tiago.pereira@idiap.ch>
# Tiago Freitas Pereira <tiago.pereira@idiap.ch>
# Tue Jul 19 12:16:17 2011 +0200
# Amir Mohammadi <amir.mohammadi@idiap.ch>
#
# Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
import
copy
import
copy
...
@@ -507,3 +504,86 @@ def test_ISVTrainInitialize():
...
@@ -507,3 +504,86 @@ def test_ISVTrainInitialize():
np
.
testing
.
assert_allclose
(
u1
,
u2
,
rtol
=
eps
,
atol
=
1e-8
)
np
.
testing
.
assert_allclose
(
u1
,
u2
,
rtol
=
eps
,
atol
=
1e-8
)
np
.
testing
.
assert_allclose
(
d1
,
d2
,
rtol
=
eps
,
atol
=
1e-8
)
np
.
testing
.
assert_allclose
(
d1
,
d2
,
rtol
=
eps
,
atol
=
1e-8
)
def
test_JFAMachine
():
eps
=
1e-10
# Creates a UBM
ubm
=
GMMMachine
(
2
,
3
)
ubm
.
weights
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
ubm
.
means
=
np
.
array
([[
1
,
6
,
2
],
[
4
,
3
,
2
]],
"
float64
"
)
ubm
.
variances
=
np
.
array
([[
1
,
2
,
1
],
[
2
,
1
,
2
]],
"
float64
"
)
# Defines GMMStats
gs
=
GMMStats
(
2
,
3
)
gs
.
log_likelihood
=
-
3.0
gs
.
t
=
1
gs
.
n
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
gs
.
sum_px
=
np
.
array
([[
1.0
,
2.0
,
3.0
],
[
4.0
,
5.0
,
6.0
]],
"
float64
"
)
gs
.
sum_pxx
=
np
.
array
([[
10.0
,
20.0
,
30.0
],
[
40.0
,
50.0
,
60.0
]],
"
float64
"
)
# Creates a JFAMachine
m
=
JFAMachine
(
ubm
,
2
,
2
,
em_iterations
=
10
)
m
.
U
=
np
.
array
(
[[
1
,
2
],
[
3
,
4
],
[
5
,
6
],
[
7
,
8
],
[
9
,
10
],
[
11
,
12
]],
"
float64
"
)
m
.
V
=
np
.
array
([[
6
,
5
],
[
4
,
3
],
[
2
,
1
],
[
1
,
2
],
[
3
,
4
],
[
5
,
6
]],
"
float64
"
)
m
.
D
=
np
.
array
([
0
,
1
,
0
,
1
,
0
,
1
],
"
float64
"
)
# Preparing the model
y
=
np
.
array
([
1
,
2
],
"
float64
"
)
z
=
np
.
array
([
3
,
4
,
1
,
2
,
0
,
1
],
"
float64
"
)
model
=
[
y
,
z
]
score_ref
=
-
2.111577181208289
score
=
m
.
score
(
model
,
gs
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
# Scoring with numpy array
np
.
random
.
seed
(
0
)
X
=
np
.
random
.
normal
(
loc
=
0.0
,
scale
=
1.0
,
size
=
(
50
,
3
))
score_ref
=
2.028009315286946
score
=
m
.
score_with_array
(
model
,
X
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
def
test_ISVMachine
():
eps
=
1e-10
# Creates a UBM
ubm
=
GMMMachine
(
2
,
3
)
ubm
.
weights
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
ubm
.
means
=
np
.
array
([[
1
,
6
,
2
],
[
4
,
3
,
2
]],
"
float64
"
)
ubm
.
variances
=
np
.
array
([[
1
,
2
,
1
],
[
2
,
1
,
2
]],
"
float64
"
)
# Creates a ISVMachine
isv_machine
=
ISVMachine
(
ubm
=
ubm
,
r_U
=
2
,
em_iterations
=
10
)
isv_machine
.
U
=
np
.
array
(
[[
1
,
2
],
[
3
,
4
],
[
5
,
6
],
[
7
,
8
],
[
9
,
10
],
[
11
,
12
]],
"
float64
"
)
# base.v = numpy.array([[0], [0], [0], [0], [0], [0]], 'float64')
isv_machine
.
D
=
np
.
array
([
0
,
1
,
0
,
1
,
0
,
1
],
"
float64
"
)
# Defines GMMStats
gs
=
GMMStats
(
2
,
3
)
gs
.
log_likelihood
=
-
3.0
gs
.
t
=
1
gs
.
n
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
gs
.
sum_px
=
np
.
array
([[
1.0
,
2.0
,
3.0
],
[
4.0
,
5.0
,
6.0
]],
"
float64
"
)
gs
.
sum_pxx
=
np
.
array
([[
10.0
,
20.0
,
30.0
],
[
40.0
,
50.0
,
60.0
]],
"
float64
"
)
# Enrolled model
latent_z
=
np
.
array
([
3
,
4
,
1
,
2
,
0
,
1
],
"
float64
"
)
score
=
isv_machine
.
score
(
latent_z
,
gs
)
score_ref
=
-
3.280498193082100
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
# Scoring with numpy array
np
.
random
.
seed
(
0
)
X
=
np
.
random
.
normal
(
loc
=
0.0
,
scale
=
1.0
,
size
=
(
50
,
3
))
score_ref
=
-
1.2343813195374242
score
=
isv_machine
.
score_with_array
(
latent_z
,
X
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
This diff is collapsed.
Click to expand it.
bob/learn/em/test/test_jfa.py
deleted
100644 → 0
+
0
−
94
View file @
5ce317d2
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
# Tiago Freitas Pereira <tiago.pereira@idiap.ch>
# Tue Jul 19 12:16:17 2011 +0200
#
# Copyright (C) 2011-2014 Idiap Research Institute, Martigny, Switzerland
import
numpy
as
np
from
bob.learn.em
import
GMMMachine
,
GMMStats
,
ISVMachine
,
JFAMachine
def
test_JFAMachine
():
eps
=
1e-10
# Creates a UBM
ubm
=
GMMMachine
(
2
,
3
)
ubm
.
weights
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
ubm
.
means
=
np
.
array
([[
1
,
6
,
2
],
[
4
,
3
,
2
]],
"
float64
"
)
ubm
.
variances
=
np
.
array
([[
1
,
2
,
1
],
[
2
,
1
,
2
]],
"
float64
"
)
# Defines GMMStats
gs
=
GMMStats
(
2
,
3
)
gs
.
log_likelihood
=
-
3.0
gs
.
t
=
1
gs
.
n
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
gs
.
sum_px
=
np
.
array
([[
1.0
,
2.0
,
3.0
],
[
4.0
,
5.0
,
6.0
]],
"
float64
"
)
gs
.
sum_pxx
=
np
.
array
([[
10.0
,
20.0
,
30.0
],
[
40.0
,
50.0
,
60.0
]],
"
float64
"
)
# Creates a JFAMachine
m
=
JFAMachine
(
ubm
,
2
,
2
,
em_iterations
=
10
)
m
.
U
=
np
.
array
(
[[
1
,
2
],
[
3
,
4
],
[
5
,
6
],
[
7
,
8
],
[
9
,
10
],
[
11
,
12
]],
"
float64
"
)
m
.
V
=
np
.
array
([[
6
,
5
],
[
4
,
3
],
[
2
,
1
],
[
1
,
2
],
[
3
,
4
],
[
5
,
6
]],
"
float64
"
)
m
.
D
=
np
.
array
([
0
,
1
,
0
,
1
,
0
,
1
],
"
float64
"
)
# Preparing the model
y
=
np
.
array
([
1
,
2
],
"
float64
"
)
z
=
np
.
array
([
3
,
4
,
1
,
2
,
0
,
1
],
"
float64
"
)
model
=
[
y
,
z
]
score_ref
=
-
2.111577181208289
score
=
m
.
score
(
model
,
gs
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
# Scoring with numpy array
np
.
random
.
seed
(
0
)
X
=
np
.
random
.
normal
(
loc
=
0.0
,
scale
=
1.0
,
size
=
(
50
,
3
))
score_ref
=
2.028009315286946
score
=
m
.
score_with_array
(
model
,
X
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
def
test_ISVMachine
():
eps
=
1e-10
# Creates a UBM
ubm
=
GMMMachine
(
2
,
3
)
ubm
.
weights
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
ubm
.
means
=
np
.
array
([[
1
,
6
,
2
],
[
4
,
3
,
2
]],
"
float64
"
)
ubm
.
variances
=
np
.
array
([[
1
,
2
,
1
],
[
2
,
1
,
2
]],
"
float64
"
)
# Creates a ISVMachine
isv_machine
=
ISVMachine
(
ubm
=
ubm
,
r_U
=
2
,
em_iterations
=
10
)
isv_machine
.
U
=
np
.
array
(
[[
1
,
2
],
[
3
,
4
],
[
5
,
6
],
[
7
,
8
],
[
9
,
10
],
[
11
,
12
]],
"
float64
"
)
# base.v = numpy.array([[0], [0], [0], [0], [0], [0]], 'float64')
isv_machine
.
D
=
np
.
array
([
0
,
1
,
0
,
1
,
0
,
1
],
"
float64
"
)
# Defines GMMStats
gs
=
GMMStats
(
2
,
3
)
gs
.
log_likelihood
=
-
3.0
gs
.
t
=
1
gs
.
n
=
np
.
array
([
0.4
,
0.6
],
"
float64
"
)
gs
.
sum_px
=
np
.
array
([[
1.0
,
2.0
,
3.0
],
[
4.0
,
5.0
,
6.0
]],
"
float64
"
)
gs
.
sum_pxx
=
np
.
array
([[
10.0
,
20.0
,
30.0
],
[
40.0
,
50.0
,
60.0
]],
"
float64
"
)
# Enrolled model
latent_z
=
np
.
array
([
3
,
4
,
1
,
2
,
0
,
1
],
"
float64
"
)
score
=
isv_machine
.
score
(
latent_z
,
gs
)
score_ref
=
-
3.280498193082100
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
# Scoring with numpy array
np
.
random
.
seed
(
0
)
X
=
np
.
random
.
normal
(
loc
=
0.0
,
scale
=
1.0
,
size
=
(
50
,
3
))
score_ref
=
-
1.2343813195374242
score
=
isv_machine
.
score_with_array
(
latent_z
,
X
)
np
.
testing
.
assert_allclose
(
score
,
score_ref
,
atol
=
eps
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment