Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.libsvm
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
Model registry
Operate
Environments
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.libsvm
Commits
f59d0af1
Commit
f59d0af1
authored
5 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[test_trainer] Be more verbose when test fails
parent
a49eed00
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!10
Fix precision test to be a bit softer on floating-point comparisons
Pipeline
#35971
failed
5 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/libsvm/test_trainer.py
+14
-11
14 additions, 11 deletions
bob/learn/libsvm/test_trainer.py
with
14 additions
and
11 deletions
bob/learn/libsvm/test_trainer.py
+
14
−
11
View file @
f59d0af1
...
@@ -34,6 +34,10 @@ HEART_DATA = F('heart.svmdata') #13 inputs
...
@@ -34,6 +34,10 @@ HEART_DATA = F('heart.svmdata') #13 inputs
HEART_MACHINE
=
F
(
'
heart.svmmodel
'
)
#supports probabilities
HEART_MACHINE
=
F
(
'
heart.svmmodel
'
)
#supports probabilities
HEART_EXPECTED
=
F
(
'
heart.out
'
)
#expected probabilities
HEART_EXPECTED
=
F
(
'
heart.out
'
)
#expected probabilities
def
_check_abs_diff
(
a
,
b
,
maxval
):
assert
numpy
.
all
(
abs
(
a
-
b
)
<
maxval
),
"
Maximum
"
\
"
difference exceeded limit (%g): %g
"
%
(
maxval
,
abs
(
a
-
b
).
max
())
def
test_initialization
():
def
test_initialization
():
# tests and examplifies some initialization parameters
# tests and examplifies some initialization parameters
...
@@ -118,8 +122,8 @@ def test_training():
...
@@ -118,8 +122,8 @@ def test_training():
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
assert
numpy
.
all
(
abs
(
machine
.
input_subtract
-
previous
.
input_subtract
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_subtract
,
previous
.
input_subtract
,
1e-8
)
assert
numpy
.
all
(
abs
(
machine
.
input_divide
-
previous
.
input_divide
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_divide
,
previous
.
input_divide
,
1e-8
)
curr_label
=
machine
.
predict_class
(
data
)
curr_label
=
machine
.
predict_class
(
data
)
prev_label
=
previous
.
predict_class
(
data
)
prev_label
=
previous
.
predict_class
(
data
)
...
@@ -131,7 +135,7 @@ def test_training():
...
@@ -131,7 +135,7 @@ def test_training():
curr_scores
=
numpy
.
array
(
curr_scores
)
curr_scores
=
numpy
.
array
(
curr_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
assert
numpy
.
all
(
abs
(
curr_scores
-
prev_scores
)
<
1e-8
)
_check_abs_diff
(
curr_scores
,
prev_scores
,
1e-8
)
def
test_training_with_probability
():
def
test_training_with_probability
():
...
@@ -152,8 +156,8 @@ def test_training_with_probability():
...
@@ -152,8 +156,8 @@ def test_training_with_probability():
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
assert
numpy
.
all
(
abs
(
machine
.
input_subtract
-
previous
.
input_subtract
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_subtract
,
previous
.
input_subtract
,
1e-8
)
assert
numpy
.
all
(
abs
(
machine
.
input_divide
-
previous
.
input_divide
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_divide
,
previous
.
input_divide
,
1e-8
)
# check labels
# check labels
curr_label
=
machine
.
predict_class
(
data
)
curr_label
=
machine
.
predict_class
(
data
)
...
@@ -167,7 +171,7 @@ def test_training_with_probability():
...
@@ -167,7 +171,7 @@ def test_training_with_probability():
curr_scores
=
numpy
.
array
(
curr_scores
)
curr_scores
=
numpy
.
array
(
curr_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
assert
numpy
.
all
(
abs
(
curr_scores
-
prev_scores
)
<
1e-8
)
_check_abs_diff
(
curr_scores
,
prev_scores
,
1e-8
)
# check probabilities -- probA and probB do not get the exact same values
# check probabilities -- probA and probB do not get the exact same values
# as when using libsvm's svm-train.c. The reason may lie in the order in
# as when using libsvm's svm-train.c. The reason may lie in the order in
...
@@ -176,7 +180,7 @@ def test_training_with_probability():
...
@@ -176,7 +180,7 @@ def test_training_with_probability():
prev_labels
,
prev_scores
=
previous
.
predict_class_and_probabilities
(
data
)
prev_labels
,
prev_scores
=
previous
.
predict_class_and_probabilities
(
data
)
curr_scores
=
numpy
.
array
(
curr_scores
)
curr_scores
=
numpy
.
array
(
curr_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
#
assert numpy.all(abs
(curr_scores
-
prev_scores
) <
1e-8)
#
_check_abs_diff
(curr_scores
,
prev_scores
,
1e-8)
def
test_training_one_class
():
def
test_training_one_class
():
...
@@ -200,8 +204,8 @@ def test_training_one_class():
...
@@ -200,8 +204,8 @@ def test_training_one_class():
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
nose
.
tools
.
eq_
(
machine
.
kernel_type
,
previous
.
kernel_type
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
assert
numpy
.
isclose
(
machine
.
gamma
,
previous
.
gamma
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
nose
.
tools
.
eq_
(
machine
.
shape
,
previous
.
shape
)
assert
numpy
.
all
(
abs
(
machine
.
input_subtract
-
previous
.
input_subtract
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_subtract
,
previous
.
input_subtract
,
1e-8
)
assert
numpy
.
all
(
abs
(
machine
.
input_divide
-
previous
.
input_divide
)
<
1e-8
)
_check_abs_diff
(
machine
.
input_divide
,
previous
.
input_divide
,
1e-8
)
curr_label
=
machine
.
predict_class
(
data
)
curr_label
=
machine
.
predict_class
(
data
)
prev_label
=
previous
.
predict_class
(
data
)
prev_label
=
previous
.
predict_class
(
data
)
...
@@ -213,8 +217,7 @@ def test_training_one_class():
...
@@ -213,8 +217,7 @@ def test_training_one_class():
curr_scores
=
numpy
.
array
(
curr_scores
)
curr_scores
=
numpy
.
array
(
curr_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
prev_scores
=
numpy
.
array
(
prev_scores
)
assert
numpy
.
all
(
abs
(
curr_scores
-
prev_scores
)
<
1e-8
)
_check_abs_diff
(
curr_scores
,
prev_scores
)
def
test_successive_training
():
def
test_successive_training
():
...
...
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