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: This is a step in the sampling procedure
  that uses internal corss_validation
  
  Parameters
  ----------
  x: array of shape(n_samples, dim),
     the input data
  z: array of shape(n_samples),
     the associated membership variables
  plike: array of shape(n_samples),
         the likelihood under the prior
  kfold: int, optional, or array
         number of folds in cross-validation loop
         or set of indexes for the cross-validation procedure
  null_class_proba: array of shape(n_samples),
                    prior probability to be under the null
  
  Returns
  -------
  like: array od shape(n_samples),
        the (cross-validated) likelihood of the data
  z: array of shape(n_samples),
        the associated membership variables
  
  Notes
  -----
  When kfold is an array, there is an internal reshuffling to randomize
  the order of updates
docstr_tok: ["This","is","a","step","in","the","sampling","procedure","that","uses","internal","corss_validation","Parameters","--","--","--","--","--","x",":","array","of","shape","(","n_samples",",","dim",")",",","the","input","data","z",":","array","of","shape","(","n_samples",")",",","the","associated","membership","variables","plike",":","array","of","shape","(","n_samples",")",",","the","likelihood","under","the","prior","kfold",":","int",",","optional",",","or","array","number","of","folds","in","cross-validation","loop","or","set","of","indexes","for","the","cross-validation","procedure","null_class_proba",":","array","of","shape","(","n_samples",")",",","prior","probability","to","be","under","the","null","Returns","--","--","--","-","like",":","array","od","shape","(","n_samples",")",",","the","(","cross-validated",")","likelihood","of","the","data","z",":","array","of","shape","(","n_samples",")",",","the","associated","membership","variables","Notes","--","--","-","When","kfold","is","an","array",",","there","is","an","internal","reshuffling","to","randomize","the","order","of","updates"]
code: def cross_validated_update(
      self, x, z, plike, null_class_proba, kfold=10
  ):
      """
      This is a step in the sampling procedure
      that uses internal corss_validation
  
      Parameters
      ----------
      x: array of shape(n_samples, dim),
         the input data
      z: array of shape(n_samples),
         the associated membership variables
      plike: array of shape(n_samples),
             the likelihood under the prior
      kfold: int, optional, or array
             number of folds in cross-validation loop
             or set of indexes for the cross-validation procedure
      null_class_proba: array of shape(n_samples),
                        prior probability to be under the null
  
      Returns
      -------
      like: array od shape(n_samples),
            the (cross-validated) likelihood of the data
      z: array of shape(n_samples),
            the associated membership variables
  
      Notes
      -----
      When kfold is an array, there is an internal reshuffling to randomize
      the order of updates
      """
      n_samples = x.shape[0]
      slike = np.zeros(n_samples)
  
      if np.isscalar(kfold):
          aux = np.argsort(np.random.rand(n_samples))
          idx = -np.ones(n_samples).astype(np.int_)
          j = int(math.ceil(n_samples / kfold))
          kmax = kfold
          for k in range(kmax):
              idx[aux[k * j : min(n_samples, j * (k + 1))]] = k
      else:
          if np.array(kfold).size != n_samples:
              raise ValueError("kfold and x do not have the same size")
          uk = np.unique(kfold)
          np.random.shuffle(uk)
          idx = np.zeros(n_samples).astype(np.int_)
          for i, k in enumerate(uk):
              idx += i * (kfold == k)
          kmax = uk.max() + 1
  
      for k in range(kmax):
          # split at iteration k
          test = np.zeros(n_samples).astype("bool")
          test[idx == k] = 1
          train = np.logical_not(test)
  
          # remove a fraction of the data
          # and re-estimate the clusters
          z[train] = self.reduce(z[train])
          self.update(x[train], z[train])
  
          # draw the membership for the left-out data
          alike = self.likelihood(x[test], plike[test])
          slike[test] = alike.sum(1)
          # standard + likelihood under the prior
          # like has shape (x.shape[0], self.k+1)
  
          z[test] = self.sample_indicator(alike, null_class_proba[test])
          # almost standard, but many new components can be created
  
      return slike, z
  
imports: import math
  import numpy
  from scipy.special import gammaln
  from .bgmm import BGMM, detsh
label_desc: Use image node_id 5 for calling the MixedIMM obj's underlying member method code with example usage: obj.cross_validated_update(x, z, plike, null_class_proba, kfold) and returns: slike,  z