class_docstr: Dynamic Hamiltonian/Hybrid Monte Carlo technique
  
  Typically, HMC operates on the posterior. It has the benefit
  of producing "orbit" trajectories, that can follow the guidance
  of gradients.
  
  In nested sampling, we need to sample the prior subject to the
  likelihood constraint. This means a HMC would most of the time
  go in straight lines, until it steps outside the boundary.
  Techniques such as Constrained HMC and Galilean MC use the
  gradient outside to select the reflection direction.
  
  However, it would be beneficial to be repelled by the likelihood
  boundary, and to take advantage of gradient guidance.
  This implements a new technique that does this.
  
  The trick is to define a auxiliary distribution from the likelihood,
  generate HMC trajectories from it, and draw points from the
  trajectory with inverse the probability of the auxiliary distribution
  to sample from the prior. Thus, the auxiliary distribution should be
  mostly flat, and go to zero at the boundaries to repell the HMC.
  
  Given Lmin and Lmax from the live points,
  use a beta approximation of log-likelihood
  
  p=1 if L>Lmin
  u = (L - Lmin) / (Lmax - Lmin)
  p = Beta_PDF(u; alpha, beta)
  
  then define
   d log(p) / dx = dlog(p_orig)/dlog(p) * dlog(p_orig) / dx
   new gradient  = conversion           * original gradient
  
  with conversion
   dlogp/du = 0 if u>1; otherwise:
   dlogp/du =  u**(1-alpha) * (1-u)**(1-beta) / Ic(u; alpha, beta) / Beta_PDF(u, alpha, beta)
   du/dL = 1 / (Lmax - Lmin)
  
  The beta distribution achieves:
  * a flattening of the loglikelihood to avoid seeing only "walls"
  * using the gradient to identify how to orbit the likelihood contour
  * at higher, unseen likelihoods, the exploration is in straight lines
  * trajectory do not have the energy to go below Lmin.
  * alpha and beta parameters allow flexible choice of "contour avoidance"
  
  Run HMC trajectory on p
  This will draw samples proportional to p
  Modify multinomial acceptance by 1/p to get uniform samples.
  and  reject porig < p_1
  
  The remaining choices for HMC are how long the trajectories should
  run (number of steps) and the step size. The former is solved
  by No-U-Turn Sampler or dynamic HMC, which randomly build
  forward and backward paths until the trajectory turns around.
  Then, a random point from the trajectory is chosen.
  
  The step size is chosen by targeting an acceptance rate of
  delta~0.95, and decreasing(increasing) every time the region is
  rebuilt if the acceptance rate is below(above).
class_docstr_tok: ["Dynamic","Hamiltonian\/Hybrid","Monte","Carlo","technique","Typically",",","HMC","operates","on","the","posterior",".","It","has","the","benefit","of","producing","``","orbit","''","trajectories",",","that","can","follow","the","guidance","of","gradients",".","In","nested","sampling",",","we","need","to","sample","the","prior","subject","to","the","likelihood","constraint",".","This","means","a","HMC","would","most","of","the","time","go","in","straight","lines",",","until","it","steps","outside","the","boundary",".","Techniques","such","as","Constrained","HMC","and","Galilean","MC","use","the","gradient","outside","to","select","the","reflection","direction",".","However",",","it","would","be","beneficial","to","be","repelled","by","the","likelihood","boundary",",","and","to","take","advantage","of","gradient","guidance",".","This","implements","a","new","technique","that","does","this",".","The","trick","is","to","define","a","auxiliary","distribution","from","the","likelihood",",","generate","HMC","trajectories","from","it",",","and","draw","points","from","the","trajectory","with","inverse","the","probability","of","the","auxiliary","distribution","to","sample","from","the","prior",".","Thus",",","the","auxiliary","distribution","should","be","mostly","flat",",","and","go","to","zero","at","the","boundaries","to","repell","the","HMC",".","Given","Lmin","and","Lmax","from","the","live","points",",","use","a","beta","approximation","of","log-likelihood","p=1","if","L",">","Lmin","u","=","(","L","-","Lmin",")","\/","(","Lmax","-","Lmin",")","p","=","Beta_PDF","(","u",";","alpha",",","beta",")","then","define","d","log","(","p",")","\/","dx","=","dlog","(","p_orig",")","\/dlog","(","p",")","*","dlog","(","p_orig",")","\/","dx","new","gradient","=","conversion","*","original","gradient","with","conversion","dlogp\/du","=","0","if","u",">","1",";","otherwise",":","dlogp\/du","=","u","*","*","(","1-alpha",")","*","(","1-u",")","*","*","(","1-beta",")","\/","Ic","(","u",";","alpha",",","beta",")","\/","Beta_PDF","(","u",",","alpha",",","beta",")","du\/dL","=","1","\/","(","Lmax","-","Lmin",")","The","beta","distribution","achieves",":","*","a","flattening","of","the","loglikelihood","to","avoid","seeing","only","``","walls","''","*","using","the","gradient","to","identify","how","to","orbit","the","likelihood","contour","*","at","higher",",","unseen","likelihoods",",","the","exploration","is","in","straight","lines","*","trajectory","do","not","have","the","energy","to","go","below","Lmin",".","*","alpha","and","beta","parameters","allow","flexible","choice","of","``","contour","avoidance","''","Run","HMC","trajectory","on","p","This","will","draw","samples","proportional","to","p","Modify","multinomial","acceptance","by","1\/p","to","get","uniform","samples",".","and","reject","porig","<","p_1","The","remaining","choices","for","HMC","are","how","long","the","trajectories","should","run","(","number","of","steps",")","and","the","step","size",".","The","former","is","solved","by","No-U-Turn","Sampler","or","dynamic","HMC",",","which","randomly","build","forward","and","backward","paths","until","the","trajectory","turns","around",".","Then",",","a","random","point","from","the","trajectory","is","chosen",".","The","step","size","is","chosen","by","targeting","an","acceptance","rate","of","delta~0.95",",","and","decreasing","(","increasing",")","every","time","the","region","is","rebuilt","if","the","acceptance","rate","is","below","(","above",")","."]
code: def region_changed(self, Ls, region):
      self.adjust_stepsize()
      self.create_problem(Ls, region)
  
imports: import numpy
  import matplotlib.pyplot
  import scipy.special
  import scipy.stats
label_desc: Use image node_id 8 for calling the DynamicHMCSampler obj's underlying member method code with example usage: obj.region_changed(Ls, region) without return types