class_docstr: Class for performing sampling in Continuous model
  using No U Turn sampler with dual averaging for
  adaptation of parameter stepsize.
  
  Parameters:
  -----------
  model: Model from which sampling has to be done
  
  simulate_dynamics: Class to propose future states of position
      and momentum in time by simulating HamiltonianDynamics
  
  delta: float (in between 0 and 1), defaults to 0.65
      The target HMC acceptance probability
  
  References
  ----------
  Matthew D. Hoffman, Andrew Gelman, The No-U-Turn Sampler: Adaptively
  Setting Path Lengths in Hamiltonian Monte Carlo. Journal of
  Machine Learning Research 15 (2014) 1351-1381
class_docstr_tok: ["Class","for","performing","sampling","in","Continuous","model","using","No","U","Turn","sampler","with","dual","averaging","for","adaptation","of","parameter","stepsize",".","Parameters",":","--","--","--","--","--","-","model",":","Model","from","which","sampling","has","to","be","done","simulate_dynamics",":","Class","to","propose","future","states","of","position","and","momentum","in","time","by","simulating","HamiltonianDynamics","delta",":","float","(","in","between","0","and","1",")",",","defaults","to","0.65","The","target","HMC","acceptance","probability","References","--","--","--","--","--","Matthew","D.","Hoffman",",","Andrew","Gelman",",","The","No-U-Turn","Sampler",":","Adaptively","Setting","Path","Lengths","in","Hamiltonian","Monte","Carlo",".","Journal","of","Machine","Learning","Research","15","(","2014",")","1351-1381"]
docstr: Recursively builds a tree for proposing new position and momentum
docstr_tok: ["Recursively","builds","a","tree","for","proposing","new","position","and","momentum"]
code: def _build_tree(
      self,
      position,
      momentum,
      slice_var,
      direction,
      depth,
      stepsize,
      position0,
      momentum0,
  ):
      """
      Recursively builds a tree for proposing new position and momentum
      """
      if depth == 0:
          (
              position_bar,
              momentum_bar,
              candidate_set_size,
              accept_set_bool,
          ) = self._initalize_tree(
              position, momentum, slice_var, direction * stepsize
          )
  
          # alpha =\
          #      min(1, self._acceptance_prob(position, position_bar, momentum, momentum_bar))
          acceptance_prob = self._acceptance_prob(
              position, position_bar, momentum, momentum_bar
          )
          alpha = 1
          if acceptance_prob < 0:
              alpha = np.exp(acceptance_prob)
  
          return (
              position_bar,
              momentum_bar,
              position_bar,
              momentum_bar,
              position_bar,
              candidate_set_size,
              accept_set_bool,
              alpha,
              1,
          )
  
      else:
          (
              position_backward,
              momentum_backward,
              position_forward,
              momentum_forward,
              position_bar,
              candidate_set_size,
              accept_set_bool,
              alpha,
              n_alpha,
          ) = self._build_tree(
              position,
              momentum,
              slice_var,
              direction,
              depth - 1,
              stepsize,
              position0,
              momentum0,
          )
  
          if accept_set_bool == 1:
              if direction == -1:
                  # Build tree in backward direction
                  (
                      position_backward,
                      momentum_backward,
                      _,
                      _,
                      position_bar2,
                      candidate_set_size2,
                      accept_set_bool2,
                      alpha2,
                      n_alpha2,
                  ) = self._build_tree(
                      position_backward,
                      momentum_backward,
                      slice_var,
                      direction,
                      depth - 1,
                      stepsize,
                      position0,
                      momentum0,
                  )
              else:
                  # Build tree in forward direction
                  (
                      _,
                      _,
                      position_forward,
                      momentum_forward,
                      position_bar2,
                      candidate_set_size2,
                      accept_set_bool2,
                      alpha2,
                      n_alpha2,
                  ) = self._build_tree(
                      position_forward,
                      momentum_forward,
                      slice_var,
                      direction,
                      depth - 1,
                      stepsize,
                      position0,
                      momentum0,
                  )
  
              if (candidate_set_size2 + candidate_set_size) != 0:
                  if np.random.rand() < min(
                      1,
                      candidate_set_size2
                      / (candidate_set_size2 + candidate_set_size),
                  ):
                      position_bar = position_bar2
              else:
                  position_bar = position_bar2
  
              alpha += alpha2
              n_alpha += n_alpha2
              (
                  accept_set_bool,
                  candidate_set_size,
              ) = self._update_acceptance_criteria(
                  position_forward,
                  position_backward,
                  momentum_forward,
                  momentum_backward,
                  accept_set_bool2,
                  candidate_set_size,
                  candidate_set_size2,
              )
  
          return (
              position_backward,
              momentum_backward,
              position_forward,
              momentum_forward,
              position_bar,
              candidate_set_size,
              accept_set_bool,
              alpha,
              n_alpha,
          )
  
file_path: dragonfly/dragonfly/sampling/nuts.py
imports: from __future__ import division
  import numpy
  from .base import LeapFrog
  from .hmc import HamiltonianMCDA
  from .check_functions import _check_1d_array_object
label_desc: Use image node_id 2 for calling the NoUTurnSamplerDA obj's underlying member method code with example usage: obj._build_tree(position, momentum, slice_var, direction, depth, stepsize, position0, momentum0) and returns: position_bar,  momentum_bar,  position_bar,  momentum_bar,  position_bar,  candidate_set_size,  accept_set_bool,  alpha,  int, position_backward,  momentum_backward,  position_forward,  momentum_forward,  position_bar,  candidate_set_size,  accept_set_bool,  alpha,  n_alpha