Inheritance diagram for nipy.algorithms.clustering.gmm:
Gaussian Mixture Model Class: contains the basic fields and methods of GMMs The class GMM _old uses C bindings which are computationally and memory efficient.
Author : Bertrand Thirion, 2006-2009
Bases: object
Standard GMM.
this class contains the following members k (int): the number of components in the mixture dim (int): is the dimension of the data prec_type = ‘full’ (string) is the parameterization
of the precisions/covariance matrices: either ‘full’ or ‘diagonal’.
weights: array of shape(k): weights of the mixture
Methods
Initialize the structure, at least with the dimensions of the problem
Parameters : | k (int) the number of classes of the model : dim (int) the dimension of the problem : prec_type = ‘full’ : coavriance:precision parameterization
means = None: array of shape (self.k,self.dim) : precisions = None: array of shape (self.k,self.dim,self.dim) :
weights=None: array of shape (self.k) : By default, means, precision and weights are set as : zeros() : eye() : 1/k ones() : with the correct dimensions : |
---|
returns the averaged log-likelihood of the mode for the dataset x
Parameters : | x: array of shape (n_samples,self.dim) :
tiny = 1.e-15: a small constant to avoid numerical singularities : |
---|
Computation of bic approximation of evidence
Parameters : | like, array of shape (n_samples, self.k) :
tiny=1.e-15, a small constant to avoid numerical singularities : |
---|---|
Returns : | the bic value, float : |
Checking the shape of different matrices involved in the model
essentially check that x.shape[1]==self.dim
x is returned with possibly reshaping
Estimation of the model given a dataset x
Parameters : | x array of shape (n_samples,dim) :
niter=100: maximal number of iterations in the estimation process : delta = 1.e-4: increment of data likelihood at which :
verbose=0: verbosity mode : |
---|---|
Returns : | bic : an asymptotic approximation of model evidence |
Computation of bic approximation of evidence
Parameters : | x array of shape (n_samples,dim) :
|
---|---|
Returns : | the bic value : |
Set the regularizing priors as weakly informative according to Fraley and raftery; Journal of Classification 24:155-181 (2007)
Parameters : | x array of shape (n_samples,dim) :
|
---|
Initializes self according to a certain dataset x: 1. sets the regularizing hyper-parameters 2. initializes z using a k-means algorithm, then 3. upate the parameters
Parameters : | x, array of shape (n_samples,self.dim) :
|
---|
Estimation of self given x
Parameters : | x array of shape (n_samples,dim) :
z = None: array of shape (n_samples) :
niter=100: maximal number of iterations in the estimation process : delta = 1.e-4: increment of data likelihood at which :
ninit=1: number of initialization performed :
verbose=0: verbosity mode : |
---|---|
Returns : | the best model is returned : |
return the likelihood of the model for the data x the values are weighted by the components weights
Parameters : | x array of shape (n_samples,self.dim) :
|
---|---|
Returns : | like, array of shape(n_samples,self.k) :
|
return the MAP labelling of x
Parameters : | x array of shape (n_samples,dim) :
like=None array of shape(n_samples,self.k) :
|
---|---|
Returns : | z: array of shape(n_samples): the resulting MAP labelling :
|
Returns the likelihood of the mixture for x
Parameters : | x: array of shape (n_samples,self.dim) :
|
---|
Set manually the weights, means and precision of the model
Parameters : | means: array of shape (self.k,self.dim) : precisions: array of shape (self.k,self.dim,self.dim) :
weights: array of shape (self.k) : |
---|
compute the population, i.e. the statistics of allocation
Parameters : | like: array of shape (n_samples,self.k): :
|
---|
Function to plot a GMM, still in progress Currently, works only in 1D and 2D
Parameters : | x: array of shape(n_samples, dim) :
gd: GridDescriptor instance : density: array os shape(prod(gd.n_bins)) :
|
---|
Function to plot a GMM – Currently, works only in 1D
Parameters : | x: array of shape(n_samples, dim) :
gd: GridDescriptor instance : density: array os shape(prod(gd.n_bins)) :
mpaxes: axes handle to make the figure, optional, :
|
---|
Returns the log-likelihood of the mixture for x
Parameters : | x array of shape (n_samples,self.dim) :
|
---|---|
Returns : | ll: array of shape(n_samples) :
|
Idem initialize_and_estimate
return the likelihood of each data for each component the values are not weighted by the component weights
Parameters : | x: array of shape (n_samples,self.dim) :
|
---|---|
Returns : | like, array of shape(n_samples,self.k) :
|
Notes
Hopefully faster
return the likelihood of each data for each component the values are not weighted by the component weights
Parameters : | x: array of shape (n_samples,self.dim) :
|
---|---|
Returns : | like, array of shape(n_samples,self.k) :
|
Identical to self._Mstep(x,l)
Bases: object
A tiny class to handle cartesian grids
Methods
make_grid | |
set |
Parameters : | dim: int, optional, :
lim: list of len(2*self.dim), :
n_bins: list of len(self.dim), :
|
---|
Compute the grid points
Returns : | grid: array of shape (nb_nodes, self.dim) :
|
---|
set the limits of the grid and the number of bins
Parameters : | lim: list of len(2*self.dim), :
n_bins: list of len(self.dim), optional :
|
---|
Given a certain dataset x, find the best-fitting GMM with a number k of classes in a certain range defined by krange
Parameters : | x: array of shape (n_samples,dim) :
krange: list of floats, :
prec_type: string (to be chosen within ‘full’,’diag’), optional, :
niter: int, optional, :
delta: float, optional, :
ninit: int :
verbose=0: verbosity mode : |
---|---|
Returns : | mg : the best-fitting GMM instance |
Given a set of points in a plane and a GMM, plot them
Parameters : | x: array of shape (npoints, dim=2), :
my_gmm: GMM instance, :
z: array of shape (npoints), optional :
with_dots, bool, optional :
log_scale: bool, optional :
mpaxes=None, int, optional :
verbose: verbosity mode, optional : |
---|---|
Returns : | gd, GridDescriptor instance, :
ax, handle to the figure axes : |
Notes
my_gmm is assumed to have have a ‘nixture_likelihood’ method that takes an array of points of shape (np, dim) and returns an array of shape (np,my_gmm.k) that represents the likelihood component-wise