class_docstr: Class for performing sampling in Continuous model
  using Hamiltonian Monte Carlo with dual averaging for
  adaptaion 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","Hamiltonian","Monte","Carlo","with","dual","averaging","for","adaptaion","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: Method to return samples using Hamiltonian Monte Carlo
  
  Parameters
  ----------
  initial_pos: A 1d array like object
    Vector representing values of parameter position, the starting
    state in markov chain.
  
  num_adapt: int
    The number of interations to run the adaptation of stepsize
  
  num_samples: int
    Number of samples to be generated
  
  trajectory_length: int or float
    Target trajectory length, stepsize * number of steps(L),
    where L is the number of steps taken per HMC iteration,
    and stepsize is step size for splitting time method.
  
  stepsize: float , defaults to None
    The stepsize for proposing new values of position and momentum in simulate_dynamics
    If None, then will be choosen suitably
  
  burn: int, defaults to 1000
    Number of samples to ignore in the beginning
docstr_tok: ["Method","to","return","samples","using","Hamiltonian","Monte","Carlo","Parameters","--","--","--","--","--","initial_pos",":","A","1d","array","like","object","Vector","representing","values","of","parameter","position",",","the","starting","state","in","markov","chain",".","num_adapt",":","int","The","number","of","interations","to","run","the","adaptation","of","stepsize","num_samples",":","int","Number","of","samples","to","be","generated","trajectory_length",":","int","or","float","Target","trajectory","length",",","stepsize","*","number","of","steps","(","L",")",",","where","L","is","the","number","of","steps","taken","per","HMC","iteration",",","and","stepsize","is","step","size","for","splitting","time","method",".","stepsize",":","float",",","defaults","to","None","The","stepsize","for","proposing","new","values","of","position","and","momentum","in","simulate_dynamics","If","None",",","then","will","be","choosen","suitably","burn",":","int",",","defaults","to","1000","Number","of","samples","to","ignore","in","the","beginning"]
code: def sample(
      self,
      initial_pos,
      num_adapt,
      num_samples,
      trajectory_length,
      stepsize=None,
      burn=1000,
  ):
      """
      Method to return samples using Hamiltonian Monte Carlo
  
      Parameters
      ----------
      initial_pos: A 1d array like object
        Vector representing values of parameter position, the starting
        state in markov chain.
  
      num_adapt: int
        The number of interations to run the adaptation of stepsize
  
      num_samples: int
        Number of samples to be generated
  
      trajectory_length: int or float
        Target trajectory length, stepsize * number of steps(L),
        where L is the number of steps taken per HMC iteration,
        and stepsize is step size for splitting time method.
  
      stepsize: float , defaults to None
        The stepsize for proposing new values of position and momentum in simulate_dynamics
        If None, then will be choosen suitably
  
      burn: int, defaults to 1000
        Number of samples to ignore in the beginning
      """
  
      self.accepted_proposals = 1.0
  
      initial_pos = _check_1d_array_object(initial_pos, "initial_pos")
  
      if stepsize is None:
          stepsize = self._find_reasonable_stepsize(initial_pos)
  
      if (
          num_adapt <= 1
      ):  # Return samples genrated using Simple HMC algorithm
          return HamiltonianMC.sample(
              self,
              initial_pos,
              num_samples,
              trajectory_length,
              stepsize,
          )
  
      # stepsize is epsilon
      # freely chosen point, after each iteration xt(/position) is shrunk towards it
      mu = np.log(10.0 * stepsize)
      # log(10 * stepsize) large values to save computation
      # stepsize_bar is epsilon_bar
      stepsize_bar = 1.0
      h_bar = 0.0
      # See equation (6) section 3.2.1 for details
  
      # samples = np.zeros(num_samples, dtype=types).view(np.recarray)
      samples = np.zeros(num_samples, dtype=float)
      position_m = initial_pos
  
      for i in range(1, num_samples + burn + 1):
          # Genrating sample
          position_m, alpha = self._sample(
              position_m, trajectory_length, stepsize
          )
          # ignore first few samples
          if i >= burn:
              samples[i - burn - 1] = position_m
  
          # Adaptation of stepsize till num_adapt iterations
          if i <= num_adapt:
              stepsize, stepsize_bar, h_bar = self._adapt_params(
                  stepsize, stepsize_bar, h_bar, mu, i, alpha
              )
          else:
              stepsize = stepsize_bar
  
      self.acceptance_rate = self.accepted_proposals / num_samples
  
      return samples
  
file_path: dragonfly/dragonfly/sampling/hmc.py
imports: from __future__ import division
  from math import sqrt
  import numpy
  from .check_functions import _check_1d_array_object
  from .base import LeapFrog, BaseSimulateHamiltonianDynamics
label_desc: Use image node_id 3 for calling the HamiltonianMCDA obj's underlying member method code with example usage: obj.sample(initial_pos, num_adapt, num_samples, trajectory_length, stepsize, burn) and returns: samples, HamiltonianMC