class_docstr: Particular IMM with an additional null class.
  The data is supplied together
  with a sample-related probability of being under the null.
class_docstr_tok: ["Particular","IMM","with","an","additional","null","class",".","The","data","is","supplied","together","with","a","sample-related","probability","of","being","under","the","null","."]
docstr: sample the indicator and parameters
  
  Parameters
  ----------
  x: array of shape (n_samples, self.dim),
     the data used in the estimation process
  null_class_proba: array of shape(n_samples),
                    the probability to be under the null
  niter: int,
         the number of iterations to perform
  sampling_points: array of shape(nbpoints, self.dim), optional
                   points where the likelihood will be sampled
                   this defaults to x
  kfold: int, optional,
         parameter of cross-validation control
         by default, no cross-validation is used
         the procedure is faster but less accurate
  co_clustering: bool, optional
                 if True,
                 return a model of data co-labelling across iterations
  verbose=0: verbosity mode
  
  Returns
  -------
  likelihood: array of shape(nbpoints)
              total likelihood of the model
  pproba: array of shape(n_samples),
          the posterior of being in the null
          (the posterior of null_class_proba)
  coclust: only if co_clustering==True,
           sparse_matrix of shape (n_samples, n_samples),
           frequency of co-labelling of each sample pairs
           across iterations
docstr_tok: ["sample","the","indicator","and","parameters","Parameters","--","--","--","--","--","x",":","array","of","shape","(","n_samples",",","self.dim",")",",","the","data","used","in","the","estimation","process","null_class_proba",":","array","of","shape","(","n_samples",")",",","the","probability","to","be","under","the","null","niter",":","int",",","the","number","of","iterations","to","perform","sampling_points",":","array","of","shape","(","nbpoints",",","self.dim",")",",","optional","points","where","the","likelihood","will","be","sampled","this","defaults","to","x","kfold",":","int",",","optional",",","parameter","of","cross-validation","control","by","default",",","no","cross-validation","is","used","the","procedure","is","faster","but","less","accurate","co_clustering",":","bool",",","optional","if","True",",","return","a","model","of","data","co-labelling","across","iterations","verbose=0",":","verbosity","mode","Returns","--","--","--","-","likelihood",":","array","of","shape","(","nbpoints",")","total","likelihood","of","the","model","pproba",":","array","of","shape","(","n_samples",")",",","the","posterior","of","being","in","the","null","(","the","posterior","of","null_class_proba",")","coclust",":","only","if","co_clustering==True",",","sparse_matrix","of","shape","(","n_samples",",","n_samples",")",",","frequency","of","co-labelling","of","each","sample","pairs","across","iterations"]
code: def sample(
      self,
      x,
      null_class_proba,
      niter=1,
      sampling_points=None,
      init=False,
      kfold=None,
      co_clustering=False,
      verbose=0,
  ):
      """
      sample the indicator and parameters
  
      Parameters
      ----------
      x: array of shape (n_samples, self.dim),
         the data used in the estimation process
      null_class_proba: array of shape(n_samples),
                        the probability to be under the null
      niter: int,
             the number of iterations to perform
      sampling_points: array of shape(nbpoints, self.dim), optional
                       points where the likelihood will be sampled
                       this defaults to x
      kfold: int, optional,
             parameter of cross-validation control
             by default, no cross-validation is used
             the procedure is faster but less accurate
      co_clustering: bool, optional
                     if True,
                     return a model of data co-labelling across iterations
      verbose=0: verbosity mode
  
      Returns
      -------
      likelihood: array of shape(nbpoints)
                  total likelihood of the model
      pproba: array of shape(n_samples),
              the posterior of being in the null
              (the posterior of null_class_proba)
      coclust: only if co_clustering==True,
               sparse_matrix of shape (n_samples, n_samples),
               frequency of co-labelling of each sample pairs
               across iterations
      """
      self.check_x(x)
      pproba = np.zeros(x.shape[0])
  
      if sampling_points is None:
          average_like = np.zeros(x.shape[0])
      else:
          average_like = np.zeros(sampling_points.shape[0])
          splike = self.likelihood_under_the_prior(sampling_points)
  
      plike = self.likelihood_under_the_prior(x)
  
      if init:
          self.k = 1
          z = np.zeros(x.shape[0])
          self.update(x, z)
  
      like = self.likelihood(x, plike)
      z = self.sample_indicator(like, null_class_proba)
  
      if co_clustering:
          from scipy.sparse import coo_matrix
  
          coclust = coo_matrix((x.shape[0], x.shape[0]))
  
      for i in range(niter):
          if kfold is None:
              like = self.simple_update(x, z, plike, null_class_proba)
          else:
              like, z = self.cross_validated_update(
                  x, z, plike, null_class_proba, kfold
              )
  
          llike = self.likelihood(x, plike)
          z = self.sample_indicator(llike, null_class_proba)
          pproba += z == -1
  
          if co_clustering:
              coclust = coclust + co_labelling(z, self.k, -1)
  
          if sampling_points is None:
              average_like += like
          else:
              average_like += np.sum(
                  self.likelihood(sampling_points, splike), 1
              )
  
      average_like /= niter
      pproba /= niter
      if co_clustering:
          coclust /= niter
          return average_like, pproba, coclust
      return average_like, pproba
  
imports: import math
  import numpy
  from scipy.special import gammaln
  from .bgmm import BGMM, detsh
label_desc: Use image node_id 3 for calling the MixedIMM obj's underlying member method code with example usage: obj.sample(x, null_class_proba, niter, sampling_points, init, kfold, co_clustering, verbose) and returns: average_like,  pproba, average_like,  pproba,  coclust