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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
6c1c6c31
Commit
6c1c6c31
authored
Nov 27, 2010
by
Olivier Grisel
Browse files
Options
Downloads
Patches
Plain Diff
forgot the test file in my last checkin...
parent
2d0ce097
Branches
Branches containing commit
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
+52
-0
52 additions, 0 deletions
scikits/learn/utils/tests/test_svd.py
with
52 additions
and
0 deletions
scikits/learn/utils/tests/test_svd.py
0 → 100644
+
52
−
0
View file @
6c1c6c31
# Author: Olivier Grisel <olivier.grisel@ensta.org>
# License: BSD
import
numpy
as
np
from
scipy
import
sparse
from
scipy
import
linalg
from
numpy.testing
import
assert_equal
from
numpy.testing
import
assert_almost_equal
from
..extmath
import
fast_svd
def
test_fast_svd
():
"""
Check that extmath.fast_svd is consistent with linalg.svd
"""
n_samples
=
100
n_features
=
500
rank
=
5
k
=
100
# generate a matrix X of rank `rank`
np
.
random
.
seed
(
42
)
X
=
np
.
dot
(
np
.
random
.
randn
(
n_samples
,
rank
),
np
.
random
.
randn
(
rank
,
n_features
))
assert_equal
(
X
.
shape
,
(
n_samples
,
n_features
))
# compute the singular values of X using the slow exact method
U
,
s
,
V
=
linalg
.
svd
(
X
,
full_matrices
=
False
)
# compute the singular values of X using the fast approximate method
Ua
,
sa
,
Va
=
fast_svd
(
X
,
k
)
assert_equal
(
Ua
.
shape
,
(
n_samples
,
k
))
assert_equal
(
sa
.
shape
,
(
k
,))
assert_equal
(
Va
.
shape
,
(
k
,
n_features
))
# ensure that the singular values of both methods are equal up to the real
# rank of the matrix
assert_almost_equal
(
s
[:
rank
],
sa
[:
rank
])
# check the singular vectors too
# XXX: some vectors are not equal, while others perfectly match?
#assert_almost_equal(U[:, :rank], Ua[:, :rank])
#assert_almost_equal(V[:rank, :], Va[:rank, :])
# check the sparse matrix representation
X
=
sparse
.
csr_matrix
(
X
)
# compute the singular values of X using the fast approximate method
Ua
,
sa
,
Va
=
fast_svd
(
X
,
k
)
assert_almost_equal
(
s
[:
rank
],
sa
[:
rank
])
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