class_docstr: Class for performing sampling using simple
  Hamiltonian Monte Carlo
  
  Parameters:
  -----------
  model: Model from which sampling has to be done
  
  simulate_dynamics: A class to propose future values of
    momentum and position in time by simulating
    Hamiltonian Dynamics
  
  References
  ----------
  R.Neal. Handbook of Markov Chain Monte Carlo,
  chapter 5: MCMC Using Hamiltonian Dynamics.
  CRC Press, 2011.
class_docstr_tok: ["Class","for","performing","sampling","using","simple","Hamiltonian","Monte","Carlo","Parameters",":","--","--","--","--","--","-","model",":","Model","from","which","sampling","has","to","be","done","simulate_dynamics",":","A","class","to","propose","future","values","of","momentum","and","position","in","time","by","simulating","Hamiltonian","Dynamics","References","--","--","--","--","--","R.Neal",".","Handbook","of","Markov","Chain","Monte","Carlo",",","chapter","5",":","MCMC","Using","Hamiltonian","Dynamics",".","CRC","Press",",","2011","."]
docstr: Runs a single sampling iteration to return a sample
docstr_tok: ["Runs","a","single","sampling","iteration","to","return","a","sample"]
code: def _sample(self, position, trajectory_length, stepsize, lsteps=None):
      """
      Runs a single sampling iteration to return a sample
      """
      # Resampling momentum
      momentum = np.reshape(
          np.random.normal(0, 1, len(position)), position.shape
      )
  
      # position_m here will be the previous sampled value of position
      position_bar, momentum_bar = position.copy(), momentum
  
      # Number of steps L to simulate dynamics
      if lsteps is None:
          lsteps = int(max(1, round(trajectory_length / stepsize, 0)))
  
      grad_bar = self.model.grad_logp(position_bar)
  
      for _ in range(lsteps):
          position_bar, momentum_bar, grad_bar = self.simulate_dynamics(
              self.model, position_bar, momentum_bar, stepsize, grad_bar
          ).get_proposed_values()
  
      acceptance_prob = self._acceptance_prob(
          position, position_bar, momentum, momentum_bar
      )
  
      # Metropolis acceptance probability
      alpha = 1
      if acceptance_prob < 0:
          alpha = np.exp(acceptance_prob)
  
      # Accept or reject the new proposed value of position, i.e position_bar
      if np.random.rand() < alpha:
          position = position_bar.copy()
          self.accepted_proposals += 1.0
  
      return position, alpha
  
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 5 for calling the HamiltonianMC obj's underlying member method code with example usage: obj._sample(position, trajectory_length, stepsize, lsteps) and returns: position,  alpha