class_docstr: Class for performing sampling in Continuous model
  using No U Turn Sampler (a variant of Hamiltonian Monte Carlo)
  
  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
  
  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","(","a","variant","of","Hamiltonian","Monte","Carlo",")","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","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: Returns a sample using a single iteration of NUTS
docstr_tok: ["Returns","a","sample","using","a","single","iteration","of","NUTS"]
code: def _sample(self, position, stepsize):
      """
      Returns a sample using a single iteration of NUTS
      """
  
      # Re-sampling momentum
      momentum = np.random.normal(0, 1, len(position))
  
      # Initializations
      depth = 0
      position_backward, position_forward = position, position
      momentum_backward, momentum_forward = momentum, momentum
      candidate_set_size = accept_set_bool = 1
      log_pdf = self.model.logp(position)
  
      # Resample slice variable `u`
      slice_var = np.random.uniform(
          0, np.exp(log_pdf - 0.5 * np.dot(momentum, momentum))
      )
  
      while accept_set_bool == 1:
          direction = np.random.choice([-1, 1], p=[0.5, 0.5])
          if direction == -1:
              # Build a tree in backward direction
              (
                  position_backward,
                  momentum_backward,
                  _,
                  _,
                  position_bar,
                  candidate_set_size2,
                  accept_set_bool2,
              ) = self._build_tree(
                  position_backward,
                  momentum_backward,
                  slice_var,
                  direction,
                  depth,
                  stepsize,
              )
          else:
              # Build tree in forward direction
              (
                  _,
                  _,
                  position_forward,
                  momentum_forward,
                  position_bar,
                  candidate_set_size2,
                  accept_set_bool2,
              ) = self._build_tree(
                  position_forward,
                  momentum_forward,
                  slice_var,
                  direction,
                  depth,
                  stepsize,
              )
          if accept_set_bool2 == 1:
              if np.random.rand() < min(
                  1, candidate_set_size2 / candidate_set_size
              ):
                  position = position_bar.copy()
  
          (
              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,
          )
          depth += 1
  
      return position
  
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 5 for calling the NoUTurnSampler obj's underlying member method code with example usage: obj._sample(position, stepsize) and returns: position