class_docstr: Nested sampler with reactive exploration strategy.
  
  Storage & resume capable, optionally MPI parallelised.
class_docstr_tok: ["Nested","sampler","with","reactive","exploration","strategy",".","Storage","&","resume","capable",",","optionally","MPI","parallelised","."]
docstr: Initialise nested sampler.
  
  Parameters
  -----------
  param_names: list of str, names of the parameters.
      Length gives dimensionality of the sampling problem.
  
  loglike: function
      log-likelihood function.
      Receives multiple parameter vectors, returns vector of likelihood.
  transform: function
      parameter transform from unit cube to physical parameters.
      Receives multiple cube vectors, returns multiple parameter vectors.
  
  derived_param_names: list of str
      Additional derived parameters created by transform. (empty by default)
  
  log_dir: str
      where to store output files
  resume: 'resume', 'resume-similar', 'overwrite' or 'subfolder'
  
      if 'overwrite', overwrite previous data.
  
      if 'subfolder', create a fresh subdirectory in log_dir.
  
      if 'resume' or True, continue previous run if available.
      Only works when dimensionality, transform or likelihood are consistent.
  
      if 'resume-similar', continue previous run if available.
      Only works when dimensionality and transform are consistent.
      If a likelihood difference is detected, the existing likelihoods
      are updated until the live point order differs.
      Otherwise, behaves like resume.
  
  run_num: int or None
      If resume=='subfolder', this is the subfolder number.
      Automatically increments if set to None.
  
  wrapped_params: list of bools
      indicating whether this parameter wraps around (circular parameter).
  
  num_test_samples: int
      test transform and likelihood with this number of
      random points for errors first. Useful to catch bugs.
  
  vectorized: bool
      If true, loglike and transform function can receive arrays
      of points.
  
  draw_multiple: bool
      If efficiency goes down, dynamically draw more points
      from the region between `ndraw_min` and `ndraw_max`.
      If set to False, few points are sampled at once.
  
  ndraw_min: int
      Minimum number of points to simultaneously propose.
      Increase this if your likelihood makes vectorization very cheap.
  
  ndraw_max: int
      Maximum number of points to simultaneously propose.
      Increase this if your likelihood makes vectorization very cheap.
      Memory allocation may be slow for extremely high values.
  
  num_bootstraps: int
      number of logZ estimators and MLFriends region
      bootstrap rounds.
  
  storage_backend: str or class
      Class to use for storing the evaluated points (see ultranest.store)
      'hdf5' is strongly recommended. 'tsv' and 'csv' are also possible.
  
  warmstart_max_tau: float
      Maximum disorder to accept when resume='resume-similar';
      Live points are reused as long as the live point order
      is below this normalised Kendall tau distance.
      Values from 0 (highly conservative) to 1 (extremely negligent).
docstr_tok: ["Initialise","nested","sampler",".","Parameters","--","--","--","--","--","-","param_names",":","list","of","str",",","names","of","the","parameters",".","Length","gives","dimensionality","of","the","sampling","problem",".","loglike",":","function","log-likelihood","function",".","Receives","multiple","parameter","vectors",",","returns","vector","of","likelihood",".","transform",":","function","parameter","transform","from","unit","cube","to","physical","parameters",".","Receives","multiple","cube","vectors",",","returns","multiple","parameter","vectors",".","derived_param_names",":","list","of","str","Additional","derived","parameters","created","by","transform",".","(","empty","by","default",")","log_dir",":","str","where","to","store","output","files","resume",":","'resume","'",",","'resume-similar","'",",","'overwrite","'","or","'subfolder'","if","'overwrite","'",",","overwrite","previous","data",".","if","'subfolder","'",",","create","a","fresh","subdirectory","in","log_dir",".","if","'resume","'","or","True",",","continue","previous","run","if","available",".","Only","works","when","dimensionality",",","transform","or","likelihood","are","consistent",".","if","'resume-similar","'",",","continue","previous","run","if","available",".","Only","works","when","dimensionality","and","transform","are","consistent",".","If","a","likelihood","difference","is","detected",",","the","existing","likelihoods","are","updated","until","the","live","point","order","differs",".","Otherwise",",","behaves","like","resume",".","run_num",":","int","or","None","If","resume=='subfolder","'",",","this","is","the","subfolder","number",".","Automatically","increments","if","set","to","None",".","wrapped_params",":","list","of","bools","indicating","whether","this","parameter","wraps","around","(","circular","parameter",")",".","num_test_samples",":","int","test","transform","and","likelihood","with","this","number","of","random","points","for","errors","first",".","Useful","to","catch","bugs",".","vectorized",":","bool","If","true",",","loglike","and","transform","function","can","receive","arrays","of","points",".","draw_multiple",":","bool","If","efficiency","goes","down",",","dynamically","draw","more","points","from","the","region","between","`","ndraw_min","`","and","`","ndraw_max","`",".","If","set","to","False",",","few","points","are","sampled","at","once",".","ndraw_min",":","int","Minimum","number","of","points","to","simultaneously","propose",".","Increase","this","if","your","likelihood","makes","vectorization","very","cheap",".","ndraw_max",":","int","Maximum","number","of","points","to","simultaneously","propose",".","Increase","this","if","your","likelihood","makes","vectorization","very","cheap",".","Memory","allocation","may","be","slow","for","extremely","high","values",".","num_bootstraps",":","int","number","of","logZ","estimators","and","MLFriends","region","bootstrap","rounds",".","storage_backend",":","str","or","class","Class","to","use","for","storing","the","evaluated","points","(","see","ultranest.store",")","'hdf5","'","is","strongly","recommended",".","'tsv","'","and","'csv","'","are","also","possible",".","warmstart_max_tau",":","float","Maximum","disorder","to","accept","when","resume='resume-similar","'",";","Live","points","are","reused","as","long","as","the","live","point","order","is","below","this","normalised","Kendall","tau","distance",".","Values","from","0","(","highly","conservative",")","to","1","(","extremely","negligent",")","."]
code: def __init__(
      self,
      param_names,
      loglike,
      transform=None,
      derived_param_names=[],
      wrapped_params=None,
      resume="subfolder",
      run_num=None,
      log_dir=None,
      num_test_samples=2,
      draw_multiple=True,
      num_bootstraps=30,
      vectorized=False,
      ndraw_min=128,
      ndraw_max=65536,
      storage_backend="hdf5",
      warmstart_max_tau=-1,
  ):
      """Initialise nested sampler.
  
      Parameters
      -----------
      param_names: list of str, names of the parameters.
          Length gives dimensionality of the sampling problem.
  
      loglike: function
          log-likelihood function.
          Receives multiple parameter vectors, returns vector of likelihood.
      transform: function
          parameter transform from unit cube to physical parameters.
          Receives multiple cube vectors, returns multiple parameter vectors.
  
      derived_param_names: list of str
          Additional derived parameters created by transform. (empty by default)
  
      log_dir: str
          where to store output files
      resume: 'resume', 'resume-similar', 'overwrite' or 'subfolder'
  
          if 'overwrite', overwrite previous data.
  
          if 'subfolder', create a fresh subdirectory in log_dir.
  
          if 'resume' or True, continue previous run if available.
          Only works when dimensionality, transform or likelihood are consistent.
  
          if 'resume-similar', continue previous run if available.
          Only works when dimensionality and transform are consistent.
          If a likelihood difference is detected, the existing likelihoods
          are updated until the live point order differs.
          Otherwise, behaves like resume.
  
      run_num: int or None
          If resume=='subfolder', this is the subfolder number.
          Automatically increments if set to None.
  
      wrapped_params: list of bools
          indicating whether this parameter wraps around (circular parameter).
  
      num_test_samples: int
          test transform and likelihood with this number of
          random points for errors first. Useful to catch bugs.
  
      vectorized: bool
          If true, loglike and transform function can receive arrays
          of points.
  
      draw_multiple: bool
          If efficiency goes down, dynamically draw more points
          from the region between `ndraw_min` and `ndraw_max`.
          If set to False, few points are sampled at once.
  
      ndraw_min: int
          Minimum number of points to simultaneously propose.
          Increase this if your likelihood makes vectorization very cheap.
  
      ndraw_max: int
          Maximum number of points to simultaneously propose.
          Increase this if your likelihood makes vectorization very cheap.
          Memory allocation may be slow for extremely high values.
  
      num_bootstraps: int
          number of logZ estimators and MLFriends region
          bootstrap rounds.
  
      storage_backend: str or class
          Class to use for storing the evaluated points (see ultranest.store)
          'hdf5' is strongly recommended. 'tsv' and 'csv' are also possible.
  
      warmstart_max_tau: float
          Maximum disorder to accept when resume='resume-similar';
          Live points are reused as long as the live point order
          is below this normalised Kendall tau distance.
          Values from 0 (highly conservative) to 1 (extremely negligent).
      """
      self.paramnames = param_names
      x_dim = len(self.paramnames)
  
      self.sampler = "reactive-nested"
      self.x_dim = x_dim
      self.transform_layer_class = (
          AffineLayer if x_dim > 1 else ScalingLayer
      )
      self.derivedparamnames = derived_param_names
      self.num_bootstraps = int(num_bootstraps)
      num_derived = len(self.derivedparamnames)
      self.num_params = x_dim + num_derived
      if wrapped_params is None:
          self.wrapped_axes = []
      else:
          assert len(wrapped_params) == self.x_dim, (
              "wrapped_params has the number of entries:",
              wrapped_params,
              ", expected",
              self.x_dim,
          )
          self.wrapped_axes = np.where(wrapped_params)[0]
  
      self.use_mpi = False
      try:
          from mpi4py import MPI
  
          self.comm = MPI.COMM_WORLD
          self.mpi_size = self.comm.Get_size()
          self.mpi_rank = self.comm.Get_rank()
          if self.mpi_size > 1:
              self.use_mpi = True
              self._setup_distributed_seeds()
      except Exception:
          self.mpi_size = 1
          self.mpi_rank = 0
  
      self.log = self.mpi_rank == 0
      self.log_to_disk = self.log and log_dir is not None
      self.log_to_pointstore = self.log_to_disk
  
      assert resume in (
          True,
          "overwrite",
          "subfolder",
          "resume",
          "resume-similar",
      ), "resume should be one of 'overwrite' 'subfolder', 'resume' or 'resume-similar'"
      append_run_num = resume == "subfolder"
      resume_similar = resume == "resume-similar"
      resume = resume in ("resume-similar", "resume", True)
  
      if self.log and log_dir is not None:
          self.logs = make_run_dir(
              log_dir, run_num, append_run_num=append_run_num
          )
          log_dir = self.logs["run_dir"]
      else:
          log_dir = None
  
      if self.log:
          self.logger = create_logger("ultranest", log_dir=log_dir)
          self.logger.debug(
              "ReactiveNestedSampler: dims=%d+%d, resume=%s, log_dir=%s, backend=%s, vectorized=%s, nbootstraps=%s, ndraw=%s..%s"
              % (
                  x_dim,
                  num_derived,
                  resume,
                  log_dir,
                  storage_backend,
                  vectorized,
                  num_bootstraps,
                  ndraw_min,
                  ndraw_max,
              )
          )
      self.root = TreeNode(id=-1, value=-np.inf)
  
      self.pointpile = PointPile(self.x_dim, self.num_params)
      if self.log_to_pointstore:
          storage_filename = os.path.join(
              self.logs["results"], "points." + storage_backend
          )
          storage_num_cols = 3 + self.x_dim + self.num_params
          if storage_backend == "tsv":
              self.pointstore = TextPointStore(
                  storage_filename, storage_num_cols
              )
              self.pointstore.delimiter = "\n"
          elif storage_backend == "csv":
              self.pointstore = TextPointStore(
                  storage_filename, storage_num_cols
              )
              self.pointstore.delimiter = ","
          elif storage_backend == "hdf5":
              self.pointstore = HDF5PointStore(
                  storage_filename,
                  storage_num_cols,
                  mode="a" if resume else "w",
              )
          else:
              # use custom backend
              self.pointstore = storage_backend
      else:
          self.pointstore = NullPointStore(
              3 + self.x_dim + self.num_params
          )
      self.ncall = self.pointstore.ncalls
      self.ncall_region = 0
  
      if not vectorized:
          if transform is not None:
              transform = vectorize(transform)
          loglike = vectorize(loglike)
          draw_multiple = False
  
      self.draw_multiple = draw_multiple
      self.ndraw_min = ndraw_min
      self.ndraw_max = ndraw_max
      self.build_tregion = transform is not None
      if not self._check_likelihood_function(
          transform, loglike, num_test_samples
      ):
          assert self.log_to_disk
          if resume_similar and self.log_to_disk:
              assert (
                  storage_backend == "hdf5"
              ), "resume-similar is only supported for HDF5 files"
              assert (
                  0 <= warmstart_max_tau <= 1
              ), "warmstart_max_tau parameter needs to be set to a value between 0 and 1"
              # close
              self.pointstore.close()
              del self.pointstore
              # rewrite points file
              if self.log:
                  self.logger.info(
                      "trying to salvage points from previous, different run ..."
                  )
              resume_from_similar_file(
                  log_dir,
                  x_dim,
                  loglike,
                  transform,
                  ndraw=ndraw_min if vectorized else 1,
                  max_tau=warmstart_max_tau,
                  verbose=False,
              )
              self.pointstore = HDF5PointStore(
                  os.path.join(self.logs["results"], "points.hdf5"),
                  3 + self.x_dim + self.num_params,
                  mode="a" if resume else "w",
              )
          elif resume:
              raise Exception(
                  "Cannot resume because loglikelihood function changed, "
                  "unless resume=resume-similar. To start from scratch, delete '%s'."
                  % (log_dir)
              )
      self._set_likelihood_function(
          transform, loglike, num_test_samples
      )
      self.stepsampler = None
  
imports: from __future__ import print_function, division
  import os
  import sys
  import csv
  import json
  import operator
  import time
  import warnings
  from numpy import log, exp, logaddexp
  import numpy
  from .utils import create_logger, make_run_dir, resample_equal, vol_prefactor, vectorize, listify
  from .utils import is_affine_transform, normalised_kendall_tau_distance, distributed_work_chunk_size
  from ultranest.mlfriends import MLFriends, AffineLayer, ScalingLayer, find_nearby, WrappingEllipsoid, RobustEllipsoidRegion
  from .store import HDF5PointStore, TextPointStore, NullPointStore
  from .viz import get_default_viz_callback
  from .ordertest import UniformOrderAccumulator
  from .netiter import PointPile, SingleCounter, MultiCounter, BreadthFirstIterator, TreeNode, count_tree_between, find_nodes_before, logz_sequence
  from .netiter import dump_tree, combine_results
  from .hotstart import get_auxiliary_contbox_parameterization
label_desc: Use image node_id 1 to create a new ReactiveNestedSampler object from inherited base classes: object with example: obj = ReactiveNestedSampler(param_names, loglike, transform, derived_param_names, wrapped_params, resume, run_num, log_dir, num_test_samples, draw_multiple, num_bootstraps, vectorized, ndraw_min, ndraw_max, storage_backend, warmstart_max_tau)