class_docstr: Class for performing sampling in Continuous model
  using No U Turn Sampler (a variant of Hamiltonian Monte Carlo)
  
  Parameters
  ----------
  model: An instance pgmpy.models
      Model from which sampling has to be done
  
  grad_log_pdf: A subclass of pgmpy.inference.continuous.GradientLogPDF
      Class to compute the log and gradient log of distribution
  
  simulate_dynamics: A subclass of pgmpy.inference.continuous.BaseSimulateHamiltonianDynamics
      Class to propose future states of position and momentum in time by simulating
      HamiltonianDynamics
  
  Public Methods
  --------------
  sample()
  generate_sample()
  
  Example
  -------
  >>> from pgmpy.sampling import NoUTurnSampler as NUTS, LeapFrog, GradLogPDFGaussian
  >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
  >>> import numpy as np
  >>> mean = np.array([1, 2, 3])
  >>> covariance = np.array([[4, 0.1, 0.2], [0.1, 1, 0.3], [0.2, 0.3, 8]])
  >>> model = JGD(['x', 'y', 'z'], mean, covariance)
  >>> sampler = NUTS(model=model, grad_log_pdf=GradLogPDFGaussian, simulate_dynamics=LeapFrog)
  >>> samples = sampler.sample(initial_pos=np.array([0.1, 0.9, 0.3]), num_samples=20000,
  ...                          stepsize=0.4, return_type='recarray')
  >>> samples
  rec.array([(0.1, 0.9, 0.3),
   (-0.27303886844752756, 0.5028580705249155, 0.2895768065049909),
   (1.7139810571103862, 2.809135711303245, 5.690811523613858), ...,
   (-0.7742669710786649, 2.092867703984895, 6.139480724333439),
   (1.3916152816323692, 1.394952482021687, 3.446906546649354),
   (-0.2726336476939125, 2.6230854954595357, 2.923948403903159)],
            dtype=[('x', '<f8'), ('y', '<f8'), ('z', '<f8')])
  
  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
  Algorithm 3 : Efficient No-U-Turn Sampler
class_docstr_tok: ["Class","for","performing","sampling","in","Continuous","model","using","No","U","Turn","Sampler","(","a","variant","of","Hamiltonian","Monte","Carlo",")","Parameters","--","--","--","--","--","model",":","An","instance","pgmpy.models","Model","from","which","sampling","has","to","be","done","grad_log_pdf",":","A","subclass","of","pgmpy.inference.continuous.GradientLogPDF","Class","to","compute","the","log","and","gradient","log","of","distribution","simulate_dynamics",":","A","subclass","of","pgmpy.inference.continuous.BaseSimulateHamiltonianDynamics","Class","to","propose","future","states","of","position","and","momentum","in","time","by","simulating","HamiltonianDynamics","Public","Methods","--","--","--","--","--","--","--","sample","(",")","generate_sample","(",")","Example","--","--","--","-",">",">",">","from","pgmpy.sampling","import","NoUTurnSampler","as","NUTS",",","LeapFrog",",","GradLogPDFGaussian",">",">",">","from","pgmpy.factors.continuous","import","GaussianDistribution","as","JGD",">",">",">","import","numpy","as","np",">",">",">","mean","=","np.array","(","[","1",",","2",",","3","]",")",">",">",">","covariance","=","np.array","(","[","[","4",",","0.1",",","0.2","]",",","[","0.1",",","1",",","0.3","]",",","[","0.2",",","0.3",",","8","]","]",")",">",">",">","model","=","JGD","(","[","'","x","'",",","'","y","'",",","'","z","'","]",",","mean",",","covariance",")",">",">",">","sampler","=","NUTS","(","model=model",",","grad_log_pdf=GradLogPDFGaussian",",","simulate_dynamics=LeapFrog",")",">",">",">","samples","=","sampler.sample","(","initial_pos=np.array","(","[","0.1",",","0.9",",","0.3","]",")",",","num_samples=20000",",","...","stepsize=0.4",",","return_type='recarray","'",")",">",">",">","samples","rec.array","(","[","(","0.1",",","0.9",",","0.3",")",",","(","-0.27303886844752756",",","0.5028580705249155",",","0.2895768065049909",")",",","(","1.7139810571103862",",","2.809135711303245",",","5.690811523613858",")",",","...",",","(","-0.7742669710786649",",","2.092867703984895",",","6.139480724333439",")",",","(","1.3916152816323692",",","1.394952482021687",",","3.446906546649354",")",",","(","-0.2726336476939125",",","2.6230854954595357",",","2.923948403903159",")","]",",","dtype=","[","(","'","x","'",",","'","<","f8","'",")",",","(","'","y","'",",","'","<","f8","'",")",",","(","'","z","'",",","'","<","f8","'",")","]",")","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","Algorithm","3",":","Efficient","No-U-Turn","Sampler"]
docstr: Returns a generator type object whose each iteration yields a sample
  
  Parameters
  ----------
  initial_pos: A 1d array like object
      Vector representing values of parameter position, the starting
      state in markov chain.
  
  num_samples: int
      Number of samples to be generated
  
  stepsize: float , defaults to None
      The stepsize for proposing new values of position and momentum in simulate_dynamics
      If None, then will be chosen suitably
  
  Returns
  -------
  generator: yielding a numpy.array type object for a sample
  
  Examples
  ---------
  >>> from pgmpy.sampling import NoUTurnSampler as NUTS, GradLogPDFGaussian
  >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
  >>> import numpy as np
  >>> mean = np.array([11, -6])
  >>> covariance = np.array([[0.7, 0.2], [0.2, 14]])
  >>> model = JGD(['x', 'y'], mean, covariance)
  >>> sampler = NUTS(model=model, grad_log_pdf=GradLogPDFGaussian)
  >>> samples = sampler.generate_sample(initial_pos=np.array([1, 1]), num_samples=10, stepsize=0.4)
  >>> samples = np.array([sample for sample in samples])
  >>> samples
  array([[ 10.26357538,   0.10062725],
         [ 12.70600336,   0.63392499],
         [ 10.95523217,  -0.62079273],
         [ 10.66263031,  -4.08135962],
         [ 10.59255762,  -8.48085076],
         [  9.99860242,  -9.47096032],
         [ 10.5733564 ,  -9.83504745],
         [ 11.51302059,  -9.49919523],
         [ 11.31892143,  -8.5873259 ],
         [ 11.29008667,  -0.43809674]])
docstr_tok: ["Returns","a","generator","type","object","whose","each","iteration","yields","a","sample","Parameters","--","--","--","--","--","initial_pos",":","A","1d","array","like","object","Vector","representing","values","of","parameter","position",",","the","starting","state","in","markov","chain",".","num_samples",":","int","Number","of","samples","to","be","generated","stepsize",":","float",",","defaults","to","None","The","stepsize","for","proposing","new","values","of","position","and","momentum","in","simulate_dynamics","If","None",",","then","will","be","chosen","suitably","Returns","--","--","--","-","generator",":","yielding","a","numpy.array","type","object","for","a","sample","Examples","--","--","--","--","-",">",">",">","from","pgmpy.sampling","import","NoUTurnSampler","as","NUTS",",","GradLogPDFGaussian",">",">",">","from","pgmpy.factors.continuous","import","GaussianDistribution","as","JGD",">",">",">","import","numpy","as","np",">",">",">","mean","=","np.array","(","[","11",",","-6","]",")",">",">",">","covariance","=","np.array","(","[","[","0.7",",","0.2","]",",","[","0.2",",","14","]","]",")",">",">",">","model","=","JGD","(","[","'","x","'",",","'","y","'","]",",","mean",",","covariance",")",">",">",">","sampler","=","NUTS","(","model=model",",","grad_log_pdf=GradLogPDFGaussian",")",">",">",">","samples","=","sampler.generate_sample","(","initial_pos=np.array","(","[","1",",","1","]",")",",","num_samples=10",",","stepsize=0.4",")",">",">",">","samples","=","np.array","(","[","sample","for","sample","in","samples","]",")",">",">",">","samples","array","(","[","[","10.26357538",",","0.10062725","]",",","[","12.70600336",",","0.63392499","]",",","[","10.95523217",",","-0.62079273","]",",","[","10.66263031",",","-4.08135962","]",",","[","10.59255762",",","-8.48085076","]",",","[","9.99860242",",","-9.47096032","]",",","[","10.5733564",",","-9.83504745","]",",","[","11.51302059",",","-9.49919523","]",",","[","11.31892143",",","-8.5873259","]",",","[","11.29008667",",","-0.43809674","]","]",")"]
code: def generate_sample(self, initial_pos, num_samples, stepsize=None):
      """
      Returns a generator type object whose each iteration yields a sample
  
      Parameters
      ----------
      initial_pos: A 1d array like object
          Vector representing values of parameter position, the starting
          state in markov chain.
  
      num_samples: int
          Number of samples to be generated
  
      stepsize: float , defaults to None
          The stepsize for proposing new values of position and momentum in simulate_dynamics
          If None, then will be chosen suitably
  
      Returns
      -------
      generator: yielding a numpy.array type object for a sample
  
      Examples
      ---------
      >>> from pgmpy.sampling import NoUTurnSampler as NUTS, GradLogPDFGaussian
      >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
      >>> import numpy as np
      >>> mean = np.array([11, -6])
      >>> covariance = np.array([[0.7, 0.2], [0.2, 14]])
      >>> model = JGD(['x', 'y'], mean, covariance)
      >>> sampler = NUTS(model=model, grad_log_pdf=GradLogPDFGaussian)
      >>> samples = sampler.generate_sample(initial_pos=np.array([1, 1]), num_samples=10, stepsize=0.4)
      >>> samples = np.array([sample for sample in samples])
      >>> samples
      array([[ 10.26357538,   0.10062725],
             [ 12.70600336,   0.63392499],
             [ 10.95523217,  -0.62079273],
             [ 10.66263031,  -4.08135962],
             [ 10.59255762,  -8.48085076],
             [  9.99860242,  -9.47096032],
             [ 10.5733564 ,  -9.83504745],
             [ 11.51302059,  -9.49919523],
             [ 11.31892143,  -8.5873259 ],
             [ 11.29008667,  -0.43809674]])
      """
      initial_pos = _check_1d_array_object(initial_pos, "initial_pos")
      _check_length_equal(
          initial_pos,
          self.model.variables,
          "initial_pos",
          "model.variables",
      )
  
      if stepsize is None:
          stepsize = self._find_reasonable_stepsize(initial_pos)
  
      position_m = initial_pos
  
      for _ in range(0, num_samples):
          position_m = self._sample(position_m, stepsize)
  
          yield position_m
  
file_path: pgmpy/pgmpy/sampling/NUTS.py
imports: import numpy
  from tqdm.auto import tqdm
  from pgmpy.sampling import HamiltonianMCDA, LeapFrog, _return_samples
  from pgmpy.utils import _check_1d_array_object, _check_length_equal
label_desc: Use image node_id 7 for calling the NoUTurnSampler obj's underlying member method code with example usage: obj.generate_sample(initial_pos, num_samples, stepsize) without return types