From 7c53b1ec87f20b081235934bca872d0d5cf34de2 Mon Sep 17 00:00:00 2001
From: Fabian Pedregosa <fabian.pedregosa@inria.fr>
Date: Wed, 23 Feb 2011 10:59:47 +0100
Subject: [PATCH] Second patch by f0k.

---
 scikits/learn/mixture.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/scikits/learn/mixture.py b/scikits/learn/mixture.py
index af843a06b0..b5482d8973 100644
--- a/scikits/learn/mixture.py
+++ b/scikits/learn/mixture.py
@@ -405,17 +405,17 @@ class GMM(BaseEstimator):
         obs = np.empty((n, self.n_features))
         rand = np.random.rand(n)
         # decide which component to use for each sample
-        c = weight_cdf.searchsorted(rand)
+        comps = weight_cdf.searchsorted(rand)
         # for each component, generate all needed samples
-        for cc in xrange(self._n_states):
-            ccc = (c==cc)  # occurences of current component in obs
-            nccc = ccc.sum()  # number of those occurences
-            if nccc > 0:
-		        if self._cvtype == 'tied':
-		            cv = self._covars
-		        else:
-		            cv = self._covars[cc]
-		        obs[ccc] = sample_gaussian(self._means[cc], cv, self._cvtype, nccc).T
+        for comp in xrange(self._n_states):
+            comp_in_obs = (comp==comps)  # occurrences of current component in obs
+            num_comp_in_obs = comp_in_obs.sum()  # number of those occurrences
+            if num_comp_in_obs > 0:
+                if self._cvtype == 'tied':
+                    cv = self._covars
+                else:
+                    cv = self._covars[comp]
+                obs[comp_in_obs] = sample_gaussian(self._means[comp], cv, self._cvtype, num_comp_in_obs).T
         return obs
 
     def fit(self, X, n_iter=10, min_covar=1e-3, thresh=1e-2, params='wmc',
-- 
GitLab