class_docstr: Class for performing sampling in Continuous model
  using No U Turn sampler with dual averaging for
  adaptation of parameter stepsize.
  
  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
  
  delta: float (in between 0 and 1), defaults to 0.65
      The target HMC acceptance probability
  
  Example
  -------
  >>> from pgmpy.sampling import NoUTurnSamplerDA as NUTSda, GradLogPDFGaussian
  >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
  >>> import numpy as np
  >>> mean = np.array([-1, 12, -3])
  >>> covariance = np.array([[-2, 7, 2], [7, 14, 4], [2, 4, -1]])
  >>> model = JGD(['x', 'v', 't'], mean, covariance)
  >>> sampler = NUTSda(model=model, grad_log_pdf=GradLogPDFGaussian)
  >>> samples = sampler.sample(initial_pos=np.array([0, 0, 0]), num_adapt=10, num_samples=10,
  ...                          stepsize=0.25, return_type='recarray')
  >>> samples
  rec.array([(0.0, 0.0, 0.0),
   (0.06100992691638076, -0.17118088764170125, 0.14048470935160887),
   (0.06100992691638076, -0.17118088764170125, 0.14048470935160887),
   (-0.7451883138013118, 1.7975387358691155, 2.3090698721374436),
   (-0.6207457594500309, 1.4611049498441024, 2.5890867012835574),
   (0.24043604780911487, 1.8660976216530618, 3.2508715592645347),
   (0.21509819341468212, 2.157760225367607, 3.5749582768731476),
   (0.20699150582681913, 2.0605044285377305, 3.8588980251618135),
   (0.20699150582681913, 2.0605044285377305, 3.8588980251618135),
   (0.085332419611991, 1.7556171374575567, 4.49985082288814)],
            dtype=[('x', '<f8'), ('v', '<f8'), ('t', '<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 6 : No-U-Turn Sampler with Dual Averaging
class_docstr_tok: ["Class","for","performing","sampling","in","Continuous","model","using","No","U","Turn","sampler","with","dual","averaging","for","adaptation","of","parameter","stepsize",".","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","delta",":","float","(","in","between","0","and","1",")",",","defaults","to","0.65","The","target","HMC","acceptance","probability","Example","--","--","--","-",">",">",">","from","pgmpy.sampling","import","NoUTurnSamplerDA","as","NUTSda",",","GradLogPDFGaussian",">",">",">","from","pgmpy.factors.continuous","import","GaussianDistribution","as","JGD",">",">",">","import","numpy","as","np",">",">",">","mean","=","np.array","(","[","-1",",","12",",","-3","]",")",">",">",">","covariance","=","np.array","(","[","[","-2",",","7",",","2","]",",","[","7",",","14",",","4","]",",","[","2",",","4",",","-1","]","]",")",">",">",">","model","=","JGD","(","[","'","x","'",",","'","v","'",",","'t","'","]",",","mean",",","covariance",")",">",">",">","sampler","=","NUTSda","(","model=model",",","grad_log_pdf=GradLogPDFGaussian",")",">",">",">","samples","=","sampler.sample","(","initial_pos=np.array","(","[","0",",","0",",","0","]",")",",","num_adapt=10",",","num_samples=10",",","...","stepsize=0.25",",","return_type='recarray","'",")",">",">",">","samples","rec.array","(","[","(","0.0",",","0.0",",","0.0",")",",","(","0.06100992691638076",",","-0.17118088764170125",",","0.14048470935160887",")",",","(","0.06100992691638076",",","-0.17118088764170125",",","0.14048470935160887",")",",","(","-0.7451883138013118",",","1.7975387358691155",",","2.3090698721374436",")",",","(","-0.6207457594500309",",","1.4611049498441024",",","2.5890867012835574",")",",","(","0.24043604780911487",",","1.8660976216530618",",","3.2508715592645347",")",",","(","0.21509819341468212",",","2.157760225367607",",","3.5749582768731476",")",",","(","0.20699150582681913",",","2.0605044285377305",",","3.8588980251618135",")",",","(","0.20699150582681913",",","2.0605044285377305",",","3.8588980251618135",")",",","(","0.085332419611991",",","1.7556171374575567",",","4.49985082288814",")","]",",","dtype=","[","(","'","x","'",",","'","<","f8","'",")",",","(","'","v","'",",","'","<","f8","'",")",",","(","'t","'",",","'","<","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","6",":","No-U-Turn","Sampler","with","Dual","Averaging"]
docstr: Returns samples using No U Turn Sampler with dual averaging
  
  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 iterations to run the adaptation of stepsize
  
  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
  
  return_type: string (dataframe | recarray)
      Return type for samples, either of 'dataframe' or 'recarray'.
      Defaults to 'dataframe'
  
  Returns
  -------
  sampled: A pandas.DataFrame or a numpy.recarray object depending upon return_type argument
  
  
  Examples
  ---------
  >>> from pgmpy.sampling import NoUTurnSamplerDA as NUTSda, GradLogPDFGaussian, LeapFrog
  >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
  >>> import numpy as np
  >>> mean = np.array([10, -13])
  >>> covariance = np.array([[16, -3], [-3, 13]])
  >>> model = JGD(['x', 'y'], mean, covariance)
  >>> sampler = NUTSda(model=model, grad_log_pdf=GradLogPDFGaussian, simulate_dynamics=LeapFrog)
  >>> samples = sampler.sample(initial_pos=np.array([12, -4]), num_adapt=10, num_samples=10,
  ...                          stepsize=0.1, return_type='dataframe')
  >>> samples
             x          y
  0  12.000000  -4.000000
  1  11.864821  -3.696109
  2  10.546986  -4.892169
  3   8.526596 -21.555793
  4   8.526596 -21.555793
  5  11.343194  -6.353789
  6  -1.583269 -12.802931
  7  12.411957 -11.704859
  8  13.253336 -20.169492
  9  11.295901  -7.665058
docstr_tok: ["Returns","samples","using","No","U","Turn","Sampler","with","dual","averaging","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","iterations","to","run","the","adaptation","of","stepsize","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","return_type",":","string","(","dataframe","|","recarray",")","Return","type","for","samples",",","either","of","'dataframe","'","or","'recarray","'",".","Defaults","to","'dataframe'","Returns","--","--","--","-","sampled",":","A","pandas.DataFrame","or","a","numpy.recarray","object","depending","upon","return_type","argument","Examples","--","--","--","--","-",">",">",">","from","pgmpy.sampling","import","NoUTurnSamplerDA","as","NUTSda",",","GradLogPDFGaussian",",","LeapFrog",">",">",">","from","pgmpy.factors.continuous","import","GaussianDistribution","as","JGD",">",">",">","import","numpy","as","np",">",">",">","mean","=","np.array","(","[","10",",","-13","]",")",">",">",">","covariance","=","np.array","(","[","[","16",",","-3","]",",","[","-3",",","13","]","]",")",">",">",">","model","=","JGD","(","[","'","x","'",",","'","y","'","]",",","mean",",","covariance",")",">",">",">","sampler","=","NUTSda","(","model=model",",","grad_log_pdf=GradLogPDFGaussian",",","simulate_dynamics=LeapFrog",")",">",">",">","samples","=","sampler.sample","(","initial_pos=np.array","(","[","12",",","-4","]",")",",","num_adapt=10",",","num_samples=10",",","...","stepsize=0.1",",","return_type='dataframe","'",")",">",">",">","samples","x","y","0","12.000000","-4.000000","1","11.864821","-3.696109","2","10.546986","-4.892169","3","8.526596","-21.555793","4","8.526596","-21.555793","5","11.343194","-6.353789","6","-1.583269","-12.802931","7","12.411957","-11.704859","8","13.253336","-20.169492","9","11.295901","-7.665058"]
code: def sample(
      self,
      initial_pos,
      num_adapt,
      num_samples,
      stepsize=None,
      return_type="dataframe",
  ):
      """
      Returns samples using No U Turn Sampler with dual averaging
  
      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 iterations to run the adaptation of stepsize
  
      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
  
      return_type: string (dataframe | recarray)
          Return type for samples, either of 'dataframe' or 'recarray'.
          Defaults to 'dataframe'
  
      Returns
      -------
      sampled: A pandas.DataFrame or a numpy.recarray object depending upon return_type argument
  
  
      Examples
      ---------
      >>> from pgmpy.sampling import NoUTurnSamplerDA as NUTSda, GradLogPDFGaussian, LeapFrog
      >>> from pgmpy.factors.continuous import GaussianDistribution as JGD
      >>> import numpy as np
      >>> mean = np.array([10, -13])
      >>> covariance = np.array([[16, -3], [-3, 13]])
      >>> model = JGD(['x', 'y'], mean, covariance)
      >>> sampler = NUTSda(model=model, grad_log_pdf=GradLogPDFGaussian, simulate_dynamics=LeapFrog)
      >>> samples = sampler.sample(initial_pos=np.array([12, -4]), num_adapt=10, num_samples=10,
      ...                          stepsize=0.1, return_type='dataframe')
      >>> samples
                 x          y
      0  12.000000  -4.000000
      1  11.864821  -3.696109
      2  10.546986  -4.892169
      3   8.526596 -21.555793
      4   8.526596 -21.555793
      5  11.343194  -6.353789
      6  -1.583269 -12.802931
      7  12.411957 -11.704859
      8  13.253336 -20.169492
      9  11.295901  -7.665058
      """
      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)
  
      if num_adapt <= 1:
          return NoUTurnSampler(
              self.model, self.grad_log_pdf, self.simulate_dynamics
          ).sample(initial_pos, num_samples, stepsize)
  
      mu = np.log(10.0 * stepsize)
      stepsize_bar = 1.0
      h_bar = 0.0
  
      types = [(var_name, "float") for var_name in self.model.variables]
      samples = np.zeros(num_samples, dtype=types).view(np.recarray)
      samples[0] = tuple(initial_pos)
      position_m = initial_pos
  
      for i in tqdm(range(1, num_samples)):
          position_m, alpha, n_alpha = self._sample(
              position_m, stepsize
          )
          samples[i] = tuple(position_m)
  
          if i <= num_adapt:
              stepsize, stepsize_bar, h_bar = self._adapt_params(
                  stepsize, stepsize_bar, h_bar, mu, i, alpha, n_alpha
              )
          else:
              stepsize = stepsize_bar
  
      return _return_samples(samples)
  
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 4 for calling the NoUTurnSamplerDA obj's underlying member method code with example usage: obj.sample(initial_pos, num_adapt, num_samples, stepsize, return_type) and returns: _return_samples, NoUTurnSampler