code: def _ensemble_sample(
      self,
      mcmc_steps,
      num_walkers,
      init_samples=None,
      init_loglikes=None,
      init_derived=None,
      loglstar=None,
      show_progress=False,
      max_start_tries=100,
      output_interval=None,
      stats_interval=None,
      plot_trace=True,
      moves=None,
  ):
      self.trainer.netG.eval()
  
      samples = []
      latent_samples = []
      derived_samples = []
      loglikes = []
  
      iters = (
          tqdm(range(1, mcmc_steps + 1))
          if show_progress
          else range(1, mcmc_steps + 1)
      )
  
      if init_samples is not None:
          if isinstance(init_samples, emcee.State):
              state = emcee.State(init_samples)
          else:
              num_walkers = init_samples.shape[0]
              z, _ = self.trainer.forward(init_samples, to_numpy=True)
              state = emcee.State(
                  z, log_prob=init_loglikes, blobs=init_derived
              )
      else:
          for i in range(max_start_tries):
              z = self.trainer.get_prior_samples(
                  num_walkers, to_numpy=True
              )
              x = self.trainer.get_samples(z, to_numpy=True)
              logl_prior = self.prior(x)
              if np.all(logl_prior) > -1e30:
                  break
              if i == max_start_tries - 1:
                  raise Exception("Could not find starting value")
          state = emcee.State(z)
  
      def transformed_loglike(z):
          assert z.shape == (self.x_dim,), z.shape
          try:
              x, log_det_J = self.trainer.inverse(
                  z.reshape((1, -1)), to_numpy=True
              )
          except:
              return -np.inf, np.zeros((1, self.num_derived))
          logl, der = self.loglike(x)
          if loglstar is not None:
              if logl < loglstar:
                  return -np.inf, der
              else:
                  return log_det_J + self.prior(x), der
          else:
              return logl + log_det_J + self.prior(x), np.zeros(
                  (1, self.num_derived)
              )
  
      sampler = emcee.EnsembleSampler(
          num_walkers, self.x_dim, transformed_loglike, moves=moves
      )
  
      ncall = num_walkers if init_loglikes is None else 0
  
      for it in iters:
          state = sampler.run_mcmc(state, 1)
          z = state.coords
          derived = state.blobs
  
          ncall += num_walkers
          x, log_det_J = self.trainer.inverse(z, to_numpy=True)
  
          samples.append(x)
          latent_samples.append(z)
          derived_samples.append(derived)
          loglikes.append(state.log_prob)
  
          if output_interval is not None and it % output_interval == 0:
              self._save_samples(
                  np.transpose(
                      np.array(self.transform(samples)), axes=[1, 0, 2]
                  ),
                  np.transpose(np.array(loglikes), axes=[1, 0]),
                  derived_samples=np.transpose(
                      np.array(derived_samples), axes=[1, 0, 2]
                  ),
              )
  
          if (
              stats_interval is not None
              and it % stats_interval == 0
              and it > 1
          ):
              self._chain_stats(
                  np.transpose(
                      np.array(self.transform(samples)), axes=[1, 0, 2]
                  ),
                  step=it,
              )
  
      # Transpose samples so shape is (chain_num, iteration, dim)
      samples = np.transpose(np.array(samples), axes=[1, 0, 2])
      latent_samples = np.transpose(
          np.array(latent_samples), axes=[1, 0, 2]
      )
      derived_samples = np.transpose(
          np.array(derived_samples), axes=[1, 0, 2]
      )
      loglikes = np.transpose(np.array(loglikes), axes=[1, 0])
  
      if plot_trace:
          self._plot_trace(samples, latent_samples)
  
      return samples, latent_samples, derived_samples, loglikes, ncall
  
imports: from __future__ import print_function
  from __future__ import division
  import os
  import json
  import logging
  import time
  import torch
  import numpy
  from tqdm import tqdm
  import matplotlib.pyplot
  from nnest.trainer import Trainer
  from nnest.utils.evaluation import acceptance_rate, effective_sample_size, mean_jump_distance, gelman_rubin_diagnostic
  from nnest.utils.logger import create_logger, get_or_create_run_dir
label_desc: Use image node_id 10 for calling the Sampler obj's underlying member method code with example usage: obj._ensemble_sample(mcmc_steps, num_walkers, init_samples, init_loglikes, init_derived, loglstar, show_progress, max_start_tries, output_interval, stats_interval, plot_trace, moves) and returns: samples,  latent_samples,  derived_samples,  loglikes,  ncall, unknown,  np, unknown,  np, unknown,  der, unknown,  der