@@ -134,9 +134,10 @@ class GMM(BaseEstimator):
134
134
135
135
Parameters
136
136
----------
137
- n_states : int
138
- Number of mixture components.
139
- cvtype : string (read-only)
137
+ n_states : int, optional
138
+ Number of mixture components. Defaults to 1.
139
+
140
+ cvtype : string (read-only), optional
140
141
String describing the type of covariance parameters to
141
142
use. Must be one of 'spherical', 'tied', 'diag', 'full'.
142
143
Defaults to 'diag'.
@@ -386,36 +387,39 @@ def predict_proba(self, X):
386
387
logprob , posteriors = self .eval (X )
387
388
return posteriors
388
389
389
- def rvs (self , n = 1 ):
390
+ def rvs (self , n_samples = 1 ):
390
391
"""Generate random samples from the model.
391
392
392
393
Parameters
393
394
----------
394
- n : int
395
- Number of samples to generate.
395
+ n_samples : int, optional
396
+ Number of samples to generate. Defaults to 1.
396
397
397
398
Returns
398
399
-------
399
- obs : array_like, shape (n , n_features)
400
+ obs : array_like, shape (n_samples , n_features)
400
401
List of samples
401
402
"""
402
403
weight_pdf = self .weights
403
404
weight_cdf = np .cumsum (weight_pdf )
404
405
405
- obs = np .empty ((n , self .n_features ))
406
- rand = np .random .rand (n )
406
+ obs = np .empty ((n_samples , self .n_features ))
407
+ rand = np .random .rand (n_samples )
407
408
# decide which component to use for each sample
408
409
comps = weight_cdf .searchsorted (rand )
409
410
# for each component, generate all needed samples
410
411
for comp in xrange (self ._n_states ):
411
- comp_in_obs = (comp == comps ) # occurrences of current component in obs
412
- num_comp_in_obs = comp_in_obs .sum () # number of those occurrences
412
+ # occurrences of current component in obs
413
+ comp_in_obs = (comp == comps )
414
<
9013
/td>+ # number of those occurrences
415
+ num_comp_in_obs = comp_in_obs .sum ()
413
416
if num_comp_in_obs > 0 :
414
417
if self ._cvtype == 'tied' :
415
418
cv = self ._covars
416
419
else :
417
420
cv = self ._covars [comp ]
418
- obs [comp_in_obs ] = sample_gaussian (self ._means [comp ], cv , self ._cvtype , num_comp_in_obs ).T
421
+ obs [comp_in_obs ] = sample_gaussian (
422
+ self ._means [comp ], cv , self ._cvtype , num_comp_in_obs ).T
419
423
return obs
420
424
421
425
def fit (self , X , n_iter = 10 , min_covar = 1e-3 , thresh = 1e-2 , params = 'wmc' ,
0 commit comments