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
6a5d4c28
Commit
6a5d4c28
authored
14 years ago
by
Olivier Grisel
Browse files
Options
Downloads
Patches
Plain Diff
make fast_svd deteriministc by default while allowing to pass rng seeds
parent
8fa07c39
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/plot_face_recognition.py
+1
-1
1 addition, 1 deletion
examples/plot_face_recognition.py
scikits/learn/utils/extmath.py
+10
-2
10 additions, 2 deletions
scikits/learn/utils/extmath.py
with
11 additions
and
3 deletions
examples/plot_face_recognition.py
+
1
−
1
View file @
6a5d4c28
...
...
@@ -110,7 +110,7 @@ y_train, y_test = y[:split], y[split:]
################################################################################
# Compute a PCA (eigenfaces) on the training set
n_components
=
1
00
n_components
=
2
00
print
"
Extracting the top %d eigenfaces
"
%
n_components
pca
=
PCA
(
n_comp
=
n_components
,
do_fast_svd
=
True
).
fit
(
X_train
)
...
...
This diff is collapsed.
Click to expand it.
scikits/learn/utils/extmath.py
+
10
−
2
View file @
6a5d4c28
...
...
@@ -86,7 +86,7 @@ def density(w, **kwargs):
return
d
def
fast_svd
(
M
,
k
,
p
=
10
):
def
fast_svd
(
M
,
k
,
p
=
10
,
rng
=
0
):
"""
Computes the k-truncated SVD using random projections
Parameters
...
...
@@ -101,6 +101,9 @@ def fast_svd(M, k, p=10):
Additional number of samples of the range of M to ensure proper
conditioning. See the notes below.
rng: RandomState or an int seed (0 by default)
A random number generator instance to make behavior
Notes
=====
This algorithm finds the exact truncated singular values decomposition
...
...
@@ -117,11 +120,16 @@ def fast_svd(M, k, p=10):
Halko, et al., 2009 (arXiv:909)
"""
if
rng
is
None
:
rng
=
np
.
random
.
RandomState
()
elif
isinstance
(
rng
,
int
):
rng
=
np
.
random
.
RandomState
(
rng
)
# lazy import of scipy sparse, because it is very slow.
from
scipy
import
sparse
# generating random gaussian vectors r with shape: (M.shape[1], k + p)
r
=
np
.
random
.
normal
(
size
=
(
M
.
shape
[
1
],
k
+
p
))
r
=
rng
.
normal
(
size
=
(
M
.
shape
[
1
],
k
+
p
))
# sampling the range of M using by linear projection of r
if
sparse
.
issparse
(
M
):
...
...
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