Inheritance diagram for nipy.neurospin.clustering.bgmm:
Bayesian Gaussian Mixture Model Classes: contains the basic fields and methods of Bayesian GMMs the high level functions are/should be binded in C
The base class BGMM relies on an implementation that perfoms Gibbs sampling
A derived class VBGMM uses Variational Bayes inference instead
A third class is introduces to take advnatge of the old C-bindings, but it is limited to diagonal covariance models
fixme: the docs should be rewritten
Author : Bertrand Thirion, 2008-2009
Bases: nipy.neurospin.clustering.gmm.GMM
This class implements Bayesian GMMs
this class contains the follwing fields - k (int): the number of components in the mixture - dim (int): is the dimension of the data - means array of shape (k,dim): all the means of the components - precisions array of shape (k,dim,dim): the precisions of the componenets - weights: array of shsape (k) weights of the mixture
- shrinkage : array of shape (k):
scaling factor of the posterior precisions on the mean - dof : array of shape (k): the posterior dofs
the prior on the components means - prior_scale : array of shape (k,dim): the prior on the components precisions - prior_dof : array of shape (k): the prior on the dof (should be at least equal to dim) - prior_shrinkage : array of shape (k): scaling factor of the prior precisions on the mean - prior_weights : array of shape (k) the prior on the components weights - shrinkage : array of shape (k): scaling factor of the posterior precisions on the mean - dof : array of shape (k): the posterior dofs
fixme : - E-step and mstep, inhereitde from GMM, should be overriden/removed ? - only ‘full’ preicsion is supported
Methods
returns the averaged log-likelihood of the model for the dataset x
| Parameters: | x: array of shape (nbitems,self.dim) :
tiny = 1.e-15: a small constant to avoid numerical singularities : |
|---|
Evaluate the Bayes Factor of the current model using Chib’s method
| Parameters: | x: array of shape (nbitems,dim) :
z: array of shape (nbitems), type = np.int :
nperm=0: int :
verbose=0: verbosity mode : |
|---|---|
| Returns: | bf (float) the computed evidence (Bayes factor) : |
computation of bic approximation of evidence
| Parameters: | like, array of shape (nbitem,self.k) :
tiny=1.e-15, a small constant to avoid numerical singularities : |
|---|---|
| Returns: | the bic value : |
essentially check that x.shape[1]==self.dim
x is returned with possibly reshaping
Compute the probability of the current parameters of self given x and z
| Parameters: | x= array of shape (nbitems,dim) :
z= array of shape (nbitems), type = np.int :
|
|---|
estimation of self given a dataset x
| Parameters: | x array of shape (nbitem,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 |
Set the priors in order of having them weakly uninformative this is from Fraley and raftery; Journal of Classification 24:155-181 (2007)
| Parameters: | x, array of shape (nbitems,self.dim) :
nocheck=0, Boolean, if nocheck==True, check is skipped : |
|---|
Set the regularizing priors as weakly informative according to Fraley and raftery; Journal of Classification 24:155-181 (2007)
| Parameters: | x array of shape (nbitems,dim) :
|
|---|
initialize z using a k-means algorithm, then upate the parameters
| Parameters: | x: array of shape (nbitems,self.dim) :
|
|---|
estimation of self given x
| Parameters: | x array of shape (nbitem,dim) :
z = None: array of shape (nbitem) :
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 (nbitems,self.dim) :
|
|---|---|
| Returns: | like, array of shape(nbitem,self.k) :
|
return the MAP labelling of x
| Parameters: | x array of shape (nbitem,dim) :
like=None array of shape(nbitem,self.k) :
|
|---|---|
| Returns: | z: array of shape(nbitem): the resulting MAP labelling :
|
returns the likelihood of the mixture for x
| Parameters: | x: array of shape (nbitems,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: | z array of shape (nbitems), type = np.int :
|
|---|---|
| Returns: | hist : array shape (self.k)n count variable |
sample the indicator and parameters
| Parameters: | x array of shape (nbitems,self.dim) :
niter=1 : the number of iterations to perform mem=0: if mem, the best values of the parameters are computed : verbose=0: verbosity mode : |
|---|---|
| Returns: | best_weights: array of shape (self.k) : best_means: array of shape (self.k,self.dim) : best_precisions: array of shape (self.k,self.dim,self.dim) : possibleZ: array of shape (nbitems,niter) :
|
sample the indicator and parameters the average values for weights,means, precisions are returned
| Parameters: | x = array of shape (nbitems,dim) :
|
|---|---|
| Returns: | weights: array of shape (self.k) :
|
sample the indicator from the likelihood
| Parameters: | like: array of shape (nbitem,self.k) :
|
|---|---|
| Returns: | z: array of shape(nbitem): a draw of the membership variable : |
Set the prior of the BGMM
| Parameters: | prior_means: array of shape (self.k,self.dim) : prior_weights: array of shape (self.k) : prior_scale: array of shape (self.k,self.dim,self.dim) : prior_dof: array of shape (self.k) : prior_shrinkage: array of shape (self.k) : |
|---|
Function to plot a GMM – Currently, works only in 1D
| Parameters: | x: array of shape(nbitems,dim) :
gd: grid descriptor structure : density = None: :
mpaxes = None: axes handle to make the figure :
|
|---|
returns the log-likelihood of the mixture for x
| Parameters: | x array of shape (nbitems,self.dim) :
|
|---|---|
| Returns: | ll: array of shape(nbitems) :
|
return the likelihood of each data for each component the values are not weighted by the component weights
| Parameters: | x: array of shape (nbitems,self.dim) :
|
|---|---|
| Returns: | like, array of shape(nbitem,self.k) :
|
update function (draw a sample of the GMM parameters)
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, and the corresponding data x, resample the mean
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, and the corresponding data x, resample the precisions
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, resmaple the weights parameter
| Parameters: | z array of shape (nbitems), type = np.int :
|
|---|
Bases: nipy.neurospin.clustering.bgmm.BGMM
Particular subcalss of Bayesian GMMs (BGMM) that implements Variational bayes estimation of the parameters
Methods
returns the averaged log-likelihood of the model for the dataset x
| Parameters: | x: array of shape (nbitems,self.dim) :
tiny = 1.e-15: a small constant to avoid numerical singularities : |
|---|
Evaluate the Bayes Factor of the current model using Chib’s method
| Parameters: | x: array of shape (nbitems,dim) :
z: array of shape (nbitems), type = np.int :
nperm=0: int :
verbose=0: verbosity mode : |
|---|---|
| Returns: | bf (float) the computed evidence (Bayes factor) : |
computation of bic approximation of evidence
| Parameters: | like, array of shape (nbitem,self.k) :
tiny=1.e-15, a small constant to avoid numerical singularities : |
|---|---|
| Returns: | the bic value : |
essentially check that x.shape[1]==self.dim
x is returned with possibly reshaping
Compute the probability of the current parameters of self given x and z
| Parameters: | x= array of shape (nbitems,dim) :
z= array of shape (nbitems), type = np.int :
|
|---|
estimation of self given x
| Parameters: | x array of shape (nbitem,dim) :
z = None: array of shape (nbitem) :
niter=100: maximal number of iterations in the estimation process : delta = 1.e-4: increment of data likelihood at which :
verbose=0: :
|
|---|
computation of evidence or integrated likelihood
| Parameters: | x array of shape (nbitems,dim) :
l=None: array of shape (nbitem,self.k) :
verbose=0: verbosity model : |
|---|---|
| Returns: | ev (float) the computed evidence : |
Set the priors in order of having them weakly uninformative this is from Fraley and raftery; Journal of Classification 24:155-181 (2007)
| Parameters: | x, array of shape (nbitems,self.dim) :
nocheck=0, Boolean, if nocheck==True, check is skipped : |
|---|
Set the regularizing priors as weakly informative according to Fraley and raftery; Journal of Classification 24:155-181 (2007)
| Parameters: | x array of shape (nbitems,dim) :
|
|---|
initialize z using a k-means algorithm, then upate the parameters
| Parameters: | x: array of shape (nbitems,self.dim) :
|
|---|
estimation of self given x
| Parameters: | x array of shape (nbitem,dim) :
z = None: array of shape (nbitem) :
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 (nbitems,self.dim) :
|
|---|---|
| Returns: | L array of shape(nbitem,self.k) :
|
return the MAP labelling of x
| Parameters: | x array of shape (nbitem,dim) :
L=None array of shape(nbitem,self.k) :
|
|---|---|
| Returns: | z: array of shape(nbitem): the resulting MAP labelling :
|
returns the likelihood of the mixture for x
| Parameters: | x: array of shape (nbitems,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: | z array of shape (nbitems), type = np.int :
|
|---|---|
| Returns: | hist : array shape (self.k)n count variable |
sample the indicator and parameters
| Parameters: | x array of shape (nbitems,self.dim) :
niter=1 : the number of iterations to perform mem=0: if mem, the best values of the parameters are computed : verbose=0: verbosity mode : |
|---|---|
| Returns: | best_weights: array of shape (self.k) : best_means: array of shape (self.k,self.dim) : best_precisions: array of shape (self.k,self.dim,self.dim) : possibleZ: array of shape (nbitems,niter) :
|
sample the indicator and parameters the average values for weights,means, precisions are returned
| Parameters: | x = array of shape (nbitems,dim) :
|
|---|---|
| Returns: | weights: array of shape (self.k) :
|
sample the indicator from the likelihood
| Parameters: | like: array of shape (nbitem,self.k) :
|
|---|---|
| Returns: | z: array of shape(nbitem): a draw of the membership variable : |
Set the prior of the BGMM
| Parameters: | prior_means: array of shape (self.k,self.dim) : prior_weights: array of shape (self.k) : prior_scale: array of shape (self.k,self.dim,self.dim) : prior_dof: array of shape (self.k) : prior_shrinkage: array of shape (self.k) : |
|---|
Function to plot a GMM – Currently, works only in 1D
| Parameters: | x: array of shape(nbitems,dim) :
gd: grid descriptor structure : density = None: :
mpaxes = None: axes handle to make the figure :
|
|---|
returns the log-likelihood of the mixture for x
| Parameters: | x array of shape (nbitems,self.dim) :
|
|---|---|
| Returns: | ll: array of shape(nbitems) :
|
return the likelihood of each data for each component the values are not weighted by the component weights
| Parameters: | x: array of shape (nbitems,self.dim) :
|
|---|---|
| Returns: | like, array of shape(nbitem,self.k) :
|
update function (draw a sample of the GMM parameters)
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, and the corresponding data x, resample the mean
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, and the corresponding data x, resample the precisions
| Parameters: | x array of shape (nbitems,self.dim) :
z array of shape (nbitems), type = np.int :
|
|---|
Given the allocation vector z, resmaple the weights parameter
| Parameters: | z array of shape (nbitems), type = np.int :
|
|---|
Evaluation of the probability of W under Wishart(n,V)
| Parameters: | n: float, :
V: array of shape (n,n) :
W: array of shape (n,n) :
dV: float, optional, :
dW: float, optional, :
piV: array of shape (n,n), optional :
|
|---|---|
| Returns: | (float) the density : |
Evaluate the probability of a certain discrete draw w from the Dirichlet density with parameters alpha
| Parameters: | w: array of shape (n) : alpha: array of shape (n) : FIXME : check that the dimensions of x and alpha are compatible |
|---|
Generate a sample from Wishart
| Parameters: | n (scalar) = the number of degrees of freedom (dofs) : V = array of shape (n,n) the scale matrix : |
|---|---|
| Returns: | W: array of shape (n,n): the Wishart draw : |
Generate a Gaussian sample with mean m and precision P
| Parameters: | m array of shape n: the mean vector : P array of shape (n,n): the precision matrix : |
|---|---|
| Returns: | ng : array of shape(n): a draw from the gaussian density |
returns an array of shape(nbperm, k) representing the permutations of k elements
| Parameters: | k, int the number of elements to be permuted :
|
|---|---|
| Returns: | p: array of shape(nperm,k): each row is permutation of k : |
Generate samples form a miltivariate distribution
| Parameters: | Likelihood: array of shape (nelements, nclasses): :
|
|---|---|
| Returns: | z array of shape (nelements): the draws, :
|
Probability of x under normal(mu,inv(P))
| Parameters: | mu: array of shape (n): the mean parameter : P: array of shape (n,n): the precision matrix : x: array of shape (n): the data to be evaluated : |
|---|---|
| Returns: | (float) the density : |
compute the population, i.e. the statistics of allocation
| Parameters: | L array of shape (nbitem,self.k): :
|
|---|