class_docstr: Base class for proposing new values of position and momentum by simulating Hamiltonian Dynamics.
  
  Classes inheriting this base class can be passed as an argument for
  simulate_dynamics in inference algorithms.
  
  Parameters
  ----------
  model : An instance of pgmpy.models
      Model for which DiscretizeTime object is initialized
  
  position : A 1d array like object (numpy.ndarray or list)
      Vector representing values of parameter position( or X)
  
  momentum: A 1d array like object (numpy.ndarray or list)
      Vector representing the proposed value for momentum (velocity)
  
  stepsize: Float
      stepsize for the simulating dynamics
  
  grad_log_pdf : A subclass of pgmpy.inference.continuous.BaseGradLogPDF
      A class for finding gradient log and log of distribution
  
  grad_log_position: A 1d array like object, defaults to None
      Vector representing gradient log at given position
      If None, then will be calculated
  
  Examples
  --------
  >>> from pgmpy.sampling import BaseSimulateHamiltonianDynamics
  >>> from pgmpy.factors.continuous import GaussianDistribution
  >>> from pgmpy.sampling import GradLogPDFGaussian
  >>> import numpy as np
  >>> # Class should initialize self.new_position, self.new_momentum and self.new_grad_logp
  >>> # self.new_grad_logp represents gradient log at new proposed value of position
  >>> class ModifiedEuler(BaseSimulateHamiltonianDynamics):
  ...     def __init__(self, model, position, momentum, stepsize, grad_log_pdf, grad_log_position=None):
  ...         BaseSimulateHamiltonianDynamics.__init__(self, model, position, momentum,
  ...                                                  stepsize, grad_log_pdf, grad_log_position)
  ...         self.new_position, self.new_momentum, self.new_grad_logp = self._get_proposed_values()
  ...     def _get_proposed_values(self):
  ...         momentum_bar = self.momentum + self.stepsize * self.grad_log_position
  ...         position_bar = self.position + self.stepsize * momentum_bar
  ...         grad_log_position, _ = self.grad_log_pdf(position_bar, self.model).get_gradient_log_pdf()
  ...         return position_bar, momentum_bar, grad_log_position
  >>> pos = np.array([1, 2])
  >>> momentum = np.array([0, 0])
  >>> mean = np.array([0, 0])
  >>> covariance = np.eye(2)
  >>> model = GaussianDistribution(['x', 'y'], mean, covariance)
  >>> new_pos, new_momentum, new_grad = ModifiedEuler(model, pos, momentum,
  ...                                                 0.25, GradLogPDFGaussian).get_proposed_values()
  >>> new_pos
  array([0.9375, 1.875])
  >>> new_momentum
  array([-0.25, -0.5])
  >>> new_grad
  array([-0.9375, -1.875])
class_docstr_tok: ["Base","class","for","proposing","new","values","of","position","and","momentum","by","simulating","Hamiltonian","Dynamics",".","Classes","inheriting","this","base","class","can","be","passed","as","an","argument","for","simulate_dynamics","in","inference","algorithms",".","Parameters","--","--","--","--","--","model",":","An","instance","of","pgmpy.models","Model","for","which","DiscretizeTime","object","is","initialized","position",":","A","1d","array","like","object","(","numpy.ndarray","or","list",")","Vector","representing","values","of","parameter","position","(","or","X",")","momentum",":","A","1d","array","like","object","(","numpy.ndarray","or","list",")","Vector","representing","the","proposed","value","for","momentum","(","velocity",")","stepsize",":","Float","stepsize","for","the","simulating","dynamics","grad_log_pdf",":","A","subclass","of","pgmpy.inference.continuous.BaseGradLogPDF","A","class","for","finding","gradient","log","and","log","of","distribution","grad_log_position",":","A","1d","array","like","object",",","defaults","to","None","Vector","representing","gradient","log","at","given","position","If","None",",","then","will","be","calculated","Examples","--","--","--","--",">",">",">","from","pgmpy.sampling","import","BaseSimulateHamiltonianDynamics",">",">",">","from","pgmpy.factors.continuous","import","GaussianDistribution",">",">",">","from","pgmpy.sampling","import","GradLogPDFGaussian",">",">",">","import","numpy","as","np",">",">",">","#","Class","should","initialize","self.new_position",",","self.new_momentum","and","self.new_grad_logp",">",">",">","#","self.new_grad_logp","represents","gradient","log","at","new","proposed","value","of","position",">",">",">","class","ModifiedEuler","(","BaseSimulateHamiltonianDynamics",")",":","...","def","__init__","(","self",",","model",",","position",",","momentum",",","stepsize",",","grad_log_pdf",",","grad_log_position=None",")",":","...","BaseSimulateHamiltonianDynamics.__init__","(","self",",","model",",","position",",","momentum",",","...","stepsize",",","grad_log_pdf",",","grad_log_position",")","...","self.new_position",",","self.new_momentum",",","self.new_grad_logp","=","self._get_proposed_values","(",")","...","def","_get_proposed_values","(","self",")",":","...","momentum_bar","=","self.momentum","+","self.stepsize","*","self.grad_log_position","...","position_bar","=","self.position","+","self.stepsize","*","momentum_bar","...","grad_log_position",",","_","=","self.grad_log_pdf","(","position_bar",",","self.model",")",".get_gradient_log_pdf","(",")","...","return","position_bar",",","momentum_bar",",","grad_log_position",">",">",">","pos","=","np.array","(","[","1",",","2","]",")",">",">",">","momentum","=","np.array","(","[","0",",","0","]",")",">",">",">","mean","=","np.array","(","[","0",",","0","]",")",">",">",">","covariance","=","np.eye","(","2",")",">",">",">","model","=","GaussianDistribution","(","[","'","x","'",",","'","y","'","]",",","mean",",","covariance",")",">",">",">","new_pos",",","new_momentum",",","new_grad","=","ModifiedEuler","(","model",",","pos",",","momentum",",","...","0.25",",","GradLogPDFGaussian",")",".get_proposed_values","(",")",">",">",">","new_pos","array","(","[","0.9375",",","1.875","]",")",">",">",">","new_momentum","array","(","[","-0.25",",","-0.5","]",")",">",">",">","new_grad","array","(","[","-0.9375",",","-1.875","]",")"]
code: def __init__(
      self,
      model,
      position,
      momentum,
      stepsize,
      grad_log_pdf,
      grad_log_position=None,
  ):
      position = _check_1d_array_object(position, "position")
  
      momentum = _check_1d_array_object(momentum, "momentum")
  
      if not issubclass(grad_log_pdf, BaseGradLogPDF):
          raise TypeError(
              "grad_log_pdf must be an instance"
              + " of pgmpy.inference.continuous.base.BaseGradLogPDF"
          )
  
      _check_length_equal(position, momentum, "position", "momentum")
      _check_length_equal(
          position, model.variables, "position", "model.variables"
      )
  
      if grad_log_position is None:
          grad_log_position, _ = grad_log_pdf(
              position, model
          ).get_gradient_log_pdf()
  
      else:
          grad_log_position = _check_1d_array_object(
              grad_log_position, "grad_log_position"
          )
          _check_length_equal(
              grad_log_position,
              position,
              "grad_log_position",
              "position",
          )
  
      self.position = position
      self.momentum = momentum
      self.stepsize = stepsize
      self.model = model
      self.grad_log_pdf = grad_log_pdf
      self.grad_log_position = grad_log_position
  
      # new_position is the new proposed position, new_momentum is the new proposed momentum, new_grad_lop
      # is the value of grad log at new_position
      self.new_position = self.new_momentum = self.new_grad_logp = None
  
imports: import itertools
  import math
  import os
  import networkx
  import numpy
  import pandas
  from joblib import Parallel, delayed
  from pgmpy.inference import Inference
  from pgmpy.utils import _check_1d_array_object, _check_length_equal, compat_fns
label_desc: Use image node_id 1 to create a new BaseSimulateHamiltonianDynamics object from inherited base classes: object with example: obj = BaseSimulateHamiltonianDynamics(model, position, momentum, stepsize, grad_log_pdf, grad_log_position)