class_docstr: Dynamic Constrained Hamiltonian/Hybrid Monte Carlo technique
  
  Run a billiard ball inside the likelihood constrained.
  The ball reflects off the constraint.
  
  The trajectory is explored in steps of stepsize epsilon.
  A No-U-turn criterion and randomized doubling of forward or backward
  steps is used to avoid repeating circular trajectories.
  Because of this, the number of steps is dynamic.
  
  Parameters
  -----------
  nsteps: int
      number of accepted steps until the sample is considered independent.
  adaptive_nsteps: False, 'proposal-distance', 'move-distance'
      if not false, allow earlier termination than nsteps.
      The 'proposal-distance' strategy stops when the sum of
      all proposed vectors exceeds the mean distance
      between pairs of live points.
      As distance, the Mahalanobis distance is used.
      The 'move-distance' strategy stops when the distance between
      start point and current position exceeds the mean distance
      between pairs of live points.
  delta: float
      step size
  nudge: float
      change in step size, must be >1.
class_docstr_tok: ["Dynamic","Constrained","Hamiltonian\/Hybrid","Monte","Carlo","technique","Run","a","billiard","ball","inside","the","likelihood","constrained",".","The","ball","reflects","off","the","constraint",".","The","trajectory","is","explored","in","steps","of","stepsize","epsilon",".","A","No-U-turn","criterion","and","randomized","doubling","of","forward","or","backward","steps","is","used","to","avoid","repeating","circular","trajectories",".","Because","of","this",",","the","number","of","steps","is","dynamic",".","Parameters","--","--","--","--","--","-","nsteps",":","int","number","of","accepted","steps","until","the","sample","is","considered","independent",".","adaptive_nsteps",":","False",",","'proposal-distance","'",",","'move-distance'","if","not","false",",","allow","earlier","termination","than","nsteps",".","The","'proposal-distance","'","strategy","stops","when","the","sum","of","all","proposed","vectors","exceeds","the","mean","distance","between","pairs","of","live","points",".","As","distance",",","the","Mahalanobis","distance","is","used",".","The","'move-distance","'","strategy","stops","when","the","distance","between","start","point","and","current","position","exceeds","the","mean","distance","between","pairs","of","live","points",".","delta",":","float","step","size","nudge",":","float","change","in","step","size",",","must","be",">","1","."]
code: def adjust_nsteps(self, region, history):
      if not self.adaptive_nsteps:
          return
      elif len(history) < self.nsteps:
          # incomplete or aborted for some reason
          print(
              "not adapting, incomplete history",
              len(history),
              self.nsteps,
          )
          return
  
      # assert self.nrejects < len(history), (self.nsteps, self.nrejects, len(history))
      # assert self.nrejects <= self.nsteps, (self.nsteps, self.nrejects, len(history))
      assert np.isfinite(self.mean_pair_distance)
      nlive, ndim = region.u.shape
      if self.adaptive_nsteps == "proposal-total-distances":
          # compute mean vector of each proposed jump
          # compute total distance of all jumps
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          assert len(tproposed.sum(axis=1)) == len(tproposed)
          d2 = (
              (((tproposed[0] - tproposed) ** 2).sum(axis=1)) ** 0.5
          ).sum()
          far_enough = d2 > self.mean_pair_distance / ndim
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              self.mean_pair_distance,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, self.mean_pair_distance, d2)
      elif self.adaptive_nsteps == "proposal-total-distances-NN":
          # compute mean vector of each proposed jump
          # compute total distance of all jumps
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          assert len(tproposed.sum(axis=1)) == len(tproposed)
          d2 = (
              (((tproposed[0] - tproposed) ** 2).sum(axis=1)) ** 0.5
          ).sum()
          far_enough = d2 > region.maxradiussq**0.5
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "proposal-summed-distances":
          # compute sum of distances from each jump
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          d2 = (
              ((tproposed[1:, :] - tproposed[:-1, :]) ** 2).sum(axis=1)
              ** 0.5
          ).sum()
          far_enough = d2 > self.mean_pair_distance / ndim
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, self.mean_pair_distance, d2)
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              self.mean_pair_distance,
          ]
      elif self.adaptive_nsteps == "proposal-summed-distances-NN":
          # compute sum of distances from each jump
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          d2 = (
              ((tproposed[1:, :] - tproposed[:-1, :]) ** 2).sum(axis=1)
              ** 0.5
          ).sum()
          far_enough = d2 > region.maxradiussq**0.5
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "proposal-summed-distances-min-NN":
          # compute sum of distances from each jump
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          d2 = (
              np.abs(tproposed[1:, :] - tproposed[:-1, :]).sum(axis=1)
          ).min()
          far_enough = d2 > region.maxradiussq**0.5
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "proposal-variance-min":
          # compute sum of distances from each jump
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          d2 = tproposed.std(axis=0).min()
          far_enough = d2 > self.mean_pair_distance / ndim
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              self.mean_pair_distance,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "proposal-variance-min-NN":
          # compute sum of distances from each jump
          tproposed = region.transformLayer.transform(
              np.asarray([u for u, _ in history])
          )
          d2 = tproposed.std(axis=0).min()
          far_enough = d2 > region.maxradiussq**0.5
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "move-distance":
          # compute distance from start to end
          ustart, _ = history[0]
          ufinal, _ = history[-1]
          tstart, tfinal = region.transformLayer.transform(
              np.vstack((ustart, ufinal))
          )
          d2 = ((tstart - tfinal) ** 2).sum()
          far_enough = d2 > region.maxradiussq
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      elif self.adaptive_nsteps == "move-distance-midway":
          # compute distance from start to end
          ustart, _ = history[0]
          middle = max(1, len(history) // 2)
          ufinal, _ = history[middle]
          tstart, tfinal = region.transformLayer.transform(
              np.vstack((ustart, ufinal))
          )
          d2 = ((tstart - tfinal) ** 2).sum()
          far_enough = d2 > region.maxradiussq
  
          self.logstat[-1] = self.logstat[-1] + [
              d2,
              region.maxradiussq**0.5,
          ]
          # print(self.adaptive_nsteps, self.nsteps, self.nrejects, far_enough, region.maxradiussq**0.5, d2)
      else:
          assert False, self.adaptive_nsteps
  
      # adjust nsteps
      if far_enough:
          self.nsteps = min(
              self.nsteps - 1, int(self.nsteps / self.nsteps_nudge)
          )
      else:
          self.nsteps = max(
              self.nsteps + 1, int(self.nsteps * self.nsteps_nudge)
          )
      self.nsteps = max(1, min(1000, self.nsteps))
      if len(self.logstat) % 50 == 0:
          print("updating number of steps: %d " % (self.nsteps))
  
file_path: ultranest/ultranest/dychmc.py
imports: from __future__ import print_function, division
  import numpy
  import matplotlib.pyplot
label_desc: Use image node_id 10 for calling the DynamicCHMCSampler obj's underlying member method code with example usage: obj.adjust_nsteps(region, history) without return types