class_docstr: This class implements Bayesian GMMs
  
  this class contains the following fields
  k: int,
     the number of components in the mixture
  dim: int,
       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 components
  weights: array of shape (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 degrees of freedom of the components
  prior_means: array of shape (k, dim):
               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
  -----
  only 'full' precision is supported
class_docstr_tok: ["This","class","implements","Bayesian","GMMs","this","class","contains","the","following","fields","k",":","int",",","the","number","of","components","in","the","mixture","dim",":","int",",","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","components","weights",":","array","of","shape","(","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","degrees","of","freedom","of","the","components","prior_means",":","array","of","shape","(","k",",","dim",")",":","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","--","--","-","only","'full","'","precision","is","supported"]
docstr: sample the indicator and parameters
  
  Parameters
  ----------
  x array of shape (nb_samples,self.dim)
    the data used in the estimation process
  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 (nb_samples, niter)
             the z that give the highest posterior
             to the data is returned first
docstr_tok: ["sample","the","indicator","and","parameters","Parameters","--","--","--","--","--","x","array","of","shape","(","nb_samples",",","self.dim",")","the","data","used","in","the","estimation","process","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","(","nb_samples",",","niter",")","the","z","that","give","the","highest","posterior","to","the","data","is","returned","first"]
code: def sample(self, x, niter=1, mem=0, verbose=0):
      """
      sample the indicator and parameters
  
      Parameters
      ----------
      x array of shape (nb_samples,self.dim)
        the data used in the estimation process
      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 (nb_samples, niter)
                 the z that give the highest posterior
                 to the data is returned first
      """
      self.check_x(x)
      if mem:
          possibleZ = -np.ones((x.shape[0], niter)).astype(np.int_)
  
      score = -np.inf
      bpz = -np.inf
  
      for i in range(niter):
          like = self.likelihood(x)
          sll = np.mean(np.log(np.sum(like, 1)))
          sll += np.log(self.probability_under_prior())
          if sll > score:
              score = sll
              best_weights = self.weights.copy()
              best_means = self.means.copy()
              best_precisions = self.precisions.copy()
  
          z = self.sample_indicator(like)
          if mem:
              possibleZ[:, i] = z
          puz = sll  # to save time
          self.update(x, z)
          if puz > bpz:
              ibz = i
              bpz = puz
  
      if mem:
          aux = possibleZ[:, 0].copy()
          possibleZ[:, 0] = possibleZ[:, ibz].copy()
          possibleZ[:, ibz] = aux
          return best_weights, best_means, best_precisions, possibleZ
  
imports: import math
  import numpy
  import numpy.random
  from scipy.linalg import cholesky, eigvalsh, inv
  from scipy.special import gammaln
  from .gmm import GMM
  from .utils import kmeans
label_desc: Use image node_id 12 for calling the BGMM obj's underlying member method code with example usage: obj.sample(x, niter, mem, verbose) and returns: best_weights,  best_means,  best_precisions,  possibleZ