code: def _rejection_flow_sample(
      self,
      init_samples,
      loglstar,
      enlargement_factor=1.1,
      constant_efficiency_factor=None,
      cache=False,
  ):
      self.trainer.netG.eval()
  
      def get_cache():
          z, log_det_J = self.trainer.forward(init_samples)
          # We want max det dx/dz to set envelope for rejection sampling
          self.max_log_det_J = enlargement_factor * torch.max(
              -log_det_J
          )
          z = z.cpu().numpy()
          self.max_r = np.max(np.linalg.norm(z, axis=1))
  
      if not cache:
          get_cache()
      else:
          try:
              self.max_log_det_J
          except:
              get_cache()
  
      if constant_efficiency_factor is not None:
          enlargement_factor = (1 / constant_efficiency_factor) ** (
              1 / self.x_dim
          )
  
      ncall = 0
      while True:
          if hasattr(self.trainer.netG.prior, "usample"):
              z = (
                  self.trainer.netG.prior.usample(sample_shape=(1,))
                  * enlargement_factor
              )
          else:
              z = np.random.randn(self.x_dim)
              z = (
                  enlargement_factor
                  * self.max_r
                  * z
                  * np.random.rand() ** (1.0 / self.x_dim)
                  / np.sqrt(np.sum(z**2))
              )
              z = np.expand_dims(z, 0)
          try:
              x, log_det_J = self.trainer.inverse(z)
          except ValueError:
              # self.logger.error('Could not find inverse', z)
              continue
  
          x = x.cpu().numpy()
          if self.prior(x) < -1e30:
              continue
  
          # Check Jacobian constraint
          log_ratio = log_det_J - self.max_log_det_J
          rnd_u = torch.rand(log_ratio.shape)
          ratio = log_ratio.exp().clamp(max=1)
          if rnd_u > ratio:
              continue
  
          logl, derived = self.loglike(x)
          idx = np.where(np.isfinite(logl) & (logl < loglstar))[0]
          log_ratio[idx] = -np.inf
          ratio = log_ratio.exp().clamp(max=1)
          ncall += 1
          if rnd_u < ratio:
              break
  
      return x, logl, derived, 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 8 for calling the Sampler obj's underlying member method code with example usage: obj._rejection_flow_sample(init_samples, loglstar, enlargement_factor, constant_efficiency_factor, cache) and returns: x,  logl,  derived,  ncall