@@ -33,16 +33,19 @@ def log_multivariate_normal_density(X, means, covars, covariance_type='diag'):
33
33
X : array_like, shape (n_samples, n_features)
34
34
List of n_features-dimensional data points. Each row corresponds to a
35
35
single data point.
36
+
36
37
means : array_like, shape (n_components, n_features)
37
38
List of n_features-dimensional mean vectors for n_components Gaussians.
38
39
Each row corresponds to a single mean vector.
40
+
39
41
covars : array_like
40
42
List of n_components covariance parameters for each Gaussian. The shape
41
43
depends on `covariance_type`:
42
44
(n_components, n_features) if 'spherical',
43
45
(n_features, n_features) if 'tied',
44
46
(n_components, n_features) if 'diag',
45
47
(n_components, n_features, n_features) if 'full'
48
+
46
49
covariance_type : string
47
50
Type of the covariance parameters. Must be one of
48
51
'spherical', 'tied', 'diag', 'full'. Defaults to 'diag'.
@@ -119,7 +122,6 @@ class GMM(BaseEstimator):
119
122
Initializes parameters such that every mixture component has zero
120
123
mean and identity covariance.
121
124
122
-
123
125
Parameters
124
126
----------
125
127
n_components : int, optional
@@ -182,8 +184,6 @@ class GMM(BaseEstimator):
182
184
converged_ : bool
183
185
True when convergence was reached in fit(), False otherwise.
184
186
185
-
186
-
187
187
See Also
188
188
--------
189
189
@@ -268,13 +268,15 @@ def __init__(self, n_components=1, covariance_type='diag',
268
268
269
269
def _get_covars (self ):
270
270
"""Covariance parameters for each mixture component.
271
- The shape depends on `cvtype`::
272
271
273
- (`n_states`, 'n_features') if 'spherical',
274
- (`n_features`, `n_features`) if 'tied',
275
- (`n_states`, `n_features`) if 'diag',
276
- (`n_states`, `n_features`, `n_features`) if 'full'
277
- """
272
+ The shape depends on ``cvtype``::
273
+
274
+ (n_states, n_features) if 'spherical',
275
+ (n_features, n_features) if 'tied',
276
+ (n_states, n_features) if 'diag',
277
+ (n_states, n_features, n_features) if 'full'
278
+
279
+ """
278
280
if self .covariance_type == 'full' :
279
281
return self .covars_
280
282
elif self .covariance_type == 'diag' :
@@ -323,8 +325,8 @@ def score_samples(self, X):
323
325
raise ValueError ('The shape of X is not compatible with self' )
324
326
325
327
lpr = (log_multivariate_normal_density (X , self .means_ , self .covars_ ,
326
- self .covariance_type )
327
- + np .log (self .weights_ ))
328
+ self .covariance_type ) +
329
+ np .log (self .weights_ ))
328
330
logprob = logsumexp (lpr , axis = 1 )
329
331
responsibilities = np .exp (lpr - logprob [:, np .newaxis ])
330
332
return logprob , responsibilities
@@ -420,8 +422,8 @@ def sample(self, n_samples=1, random_state=None):
420
422
return X
421
423
422
424
def fit_predict (self , X , y = None ):
423
- """
424
- Fit and then predict labels for data.
425
+ """Fit and then predict labels for data.
426
+
425
427
Warning: due to the final maximization step in the EM algorithm,
426
428
with low iterations the prediction may not be 100% accurate
427
429
@@ -653,7 +655,7 @@ def aic(self, X):
653
655
654
656
655
657
#########################################################################
656
- ## some helper routines
658
+ # some helper routines
657
659
#########################################################################
658
660
659
661
@@ -684,8 +686,7 @@ def _log_multivariate_normal_density_tied(X, means, covars):
684
686
685
687
686
688
def _log_multivariate_normal_density_full (X , means , covars , min_covar = 1.e-7 ):
687
- """Log probability for full covariance matrices.
688
- """
689
+ """Log probability for full covariance matrices."""
689
690
n_samples , n_dim = X .shape
690
691
nmix = len (means )
691
692
log_prob = np .empty ((n_samples , nmix ))
@@ -751,8 +752,7 @@ def _validate_covars(covars, covariance_type, n_components):
751
752
752
753
def distribute_covar_matrix_to_match_covariance_type (
753
754
tied_cv , covariance_type , n_components ):
754
- """Create all the covariance matrices from a given template
755
- """
755
+ """Create all the covariance matrices from a given template"""
756
756
if covariance_type == 'spherical' :
757
757
cv = np .tile (tied_cv .mean () * np .ones (tied_cv .shape [1 ]),
758
758
(n_components , 1 ))
0 commit comments