From 36b81e53f504ef006a96be3aa2832d119290af6a Mon Sep 17 00:00:00 2001
From: vene <vlad@vene.ro>
Date: Mon, 19 Sep 2011 13:51:23 +0300
Subject: [PATCH] Stabilized and improved face decomposition example

---
 .../decomposition/plot_faces_decomposition.py    | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/examples/decomposition/plot_faces_decomposition.py b/examples/decomposition/plot_faces_decomposition.py
index fcab10be6d..2634e822cc 100644
--- a/examples/decomposition/plot_faces_decomposition.py
+++ b/examples/decomposition/plot_faces_decomposition.py
@@ -17,6 +17,7 @@ print __doc__
 import logging
 from time import time
 
+from numpy.random import RandomState
 import pylab as pl
 
 from sklearn.datasets import fetch_olivetti_faces
@@ -29,6 +30,7 @@ logging.basicConfig(level=logging.INFO,
 n_row, n_col = 2, 3
 n_components = n_row * n_col
 image_shape = (64, 64)
+rng = RandomState(0)
 
 ###############################################################################
 # Load faces data
@@ -79,16 +81,19 @@ estimators = [
 
     ('Sparse comp. - MiniBatchSparsePCA',
      decomposition.MiniBatchSparsePCA(n_components=n_components, alpha=1e-3,
-                                      n_iter=100, chunk_size=3),
+                                      n_iter=100, chunk_size=3,
+                                      random_state=rng),
      True, False),
 
     ('MiniBatchDictionaryLearning',
-    decomposition.MiniBatchDictionaryLearning(n_atoms=n_components, alpha=5e-3,
-                                              n_iter=100, chunk_size=3),
+    decomposition.MiniBatchDictionaryLearning(n_atoms=15, alpha=5e-3,
+                                              n_iter=50, chunk_size=3,
+                                              random_state=rng),
      True, False),
 
     ('Cluster centers - MiniBatchKMeans',
-     MiniBatchKMeans(k=n_components, tol=1e-3, chunk_size=20, max_iter=50),
+     MiniBatchKMeans(k=n_components, tol=1e-3, chunk_size=20, max_iter=50,
+                     random_state=rng),
      True, False)
 ]
 
@@ -117,6 +122,7 @@ for name, estimator, center, transpose in estimators:
         components_ = estimator.components_
     if transpose:
         components_ = components_.T
-    plot_gallery('%s - Train time %.1fs' % (name, train_time), components_)
+    plot_gallery('%s - Train time %.1fs' % (name, train_time),
+                 components_[:n_components])
 
 pl.show()
-- 
GitLab