Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Ian Johnson
scikit-learn
Commits
cd8c6b00
Commit
cd8c6b00
authored
14 years ago
by
Olivier Grisel
Browse files
Options
Downloads
Patches
Plain Diff
one more test for SVD
parent
734467a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scikits/learn/utils/tests/test_svd.py
+34
-2
34 additions, 2 deletions
scikits/learn/utils/tests/test_svd.py
with
34 additions
and
2 deletions
scikits/learn/utils/tests/test_svd.py
+
34
−
2
View file @
cd8c6b00
...
@@ -12,7 +12,7 @@ from scikits.learn.utils.extmath import fast_svd
...
@@ -12,7 +12,7 @@ from scikits.learn.utils.extmath import fast_svd
from
scikits.learn.datasets.samples_generator
import
low_rank_fat_tail
from
scikits.learn.datasets.samples_generator
import
low_rank_fat_tail
def
test_fast_svd
():
def
test_fast_svd
_low_rank
():
"""
Check that extmath.fast_svd is consistent with linalg.svd
"""
"""
Check that extmath.fast_svd is consistent with linalg.svd
"""
n_samples
=
100
n_samples
=
100
n_features
=
500
n_features
=
500
...
@@ -50,7 +50,7 @@ def test_fast_svd():
...
@@ -50,7 +50,7 @@ def test_fast_svd():
assert_almost_equal
(
s
[:
rank
],
sa
[:
rank
])
assert_almost_equal
(
s
[:
rank
],
sa
[:
rank
])
def
test_fast_svd_with_noise
():
def
test_fast_svd_
low_rank_
with_noise
():
"""
Check that extmath.fast_svd can handle noisy matrices
"""
"""
Check that extmath.fast_svd can handle noisy matrices
"""
n_samples
=
100
n_samples
=
100
n_features
=
500
n_features
=
500
...
@@ -81,3 +81,35 @@ def test_fast_svd_with_noise():
...
@@ -81,3 +81,35 @@ def test_fast_svd_with_noise():
assert_almost_equal
(
s
[:
rank
],
sap
[:
rank
],
decimal
=
5
)
assert_almost_equal
(
s
[:
rank
],
sap
[:
rank
],
decimal
=
5
)
def
test_fast_svd_infinite_rank
():
"""
Check that extmath.fast_svd can handle noisy matrices
"""
n_samples
=
100
n_features
=
500
rank
=
5
k
=
10
# let us try again without 'low_rank component': just regularly but slowly
# decreasing singular values: the rank of the data matrix is infinite
X
=
low_rank_fat_tail
(
n_samples
,
n_features
,
effective_rank
=
rank
,
tail_strength
=
1.0
,
seed
=
0
)
assert_equal
(
X
.
shape
,
(
n_samples
,
n_features
))
# compute the singular values of X using the slow exact method
_
,
s
,
_
=
linalg
.
svd
(
X
,
full_matrices
=
False
)
# compute the singular values of X using the fast approximate method without
# the iterated power method
_
,
sa
,
_
=
fast_svd
(
X
,
k
,
q
=
0
)
# the approximation does not tolerate the noise:
assert
np
.
abs
(
s
[:
rank
]
-
sa
[:
rank
]).
max
()
>
0.1
# compute the singular values of X using the fast approximate method with
# iterated power method
_
,
sap
,
_
=
fast_svd
(
X
,
k
,
q
=
7
)
# the iterated power method is still managing to get most of the structure
# at the requested rank
assert_almost_equal
(
s
[:
rank
],
sap
[:
rank
],
decimal
=
5
)
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