class_docstr: A sampler for continuous variables based on Hamiltonian mechanics.
  
  NUTS automatically tunes the step size and the number of steps per
  sample. A detailed description can be found at [1], "Algorithm 6:
  Efficient No-U-Turn Sampler with Dual Averaging".
  
  NUTS provides a number of statistics that can be accessed with
  `trace.get_sampler_stats`:
  
  - `mean_tree_accept`: The mean acceptance probability for the tree
    that generated this sample. The mean of these values across all
    samples but the burn-in should be approximately `target_accept`
    (the default for this is 0.8).
  - `diverging`: Whether the trajectory for this sample diverged. If
    there are any divergences after burnin, this indicates that
    the results might not be reliable. Reparametrization can
    often help, but you can also try to increase `target_accept` to
    something like 0.9 or 0.95.
  - `energy`: The energy at the point in phase-space where the sample
    was accepted. This can be used to identify posteriors with
    problematically long tails. See below for an example.
  - `energy_change`: The difference in energy between the start and
    the end of the trajectory. For a perfect integrator this would
    always be zero.
  - `max_energy_change`: The maximum difference in energy along the
    whole trajectory.
  - `depth`: The depth of the tree that was used to generate this sample
  - `tree_size`: The number of leafs of the sampling tree, when the
    sample was accepted. This is usually a bit less than
    `2 ** depth`. If the tree size is large, the sampler is
    using a lot of leapfrog steps to find the next sample. This can for
    example happen if there are strong correlations in the posterior,
    if the posterior has long tails, if there are regions of high
    curvature ("funnels"), or if the variance estimates in the mass
    matrix are inaccurate. Reparametrisation of the model or estimating
    the posterior variances from past samples might help.
  - `tune`: This is `True`, if step size adaptation was turned on when
    this sample was generated.
  - `step_size`: The step size used for this sample.
  - `step_size_bar`: The current best known step-size. After the tuning
    samples, the step size is set to this value. This should converge
    during tuning.
  - `model_logp`: The model log-likelihood for this sample.
  - `process_time_diff`: The time it took to draw the sample, as defined
    by the python standard library `time.process_time`. This counts all
    the CPU time, including worker processes in BLAS and OpenMP.
  - `perf_counter_diff`: The time it took to draw the sample, as defined
    by the python standard library `time.perf_counter` (wall time).
  - `perf_counter_start`: The value of `time.perf_counter` at the beginning
    of the computation of the draw.
  - `index_in_trajectory`: This is usually only interesting for debugging
    purposes. This indicates the position of the posterior draw in the
    trajectory. Eg a -4 would indicate that the draw was the result of the
    fourth leapfrog step in negative direction.
  - `largest_eigval` and `smallest_eigval`: Experimental statistics for
    some mass matrix adaptation algorithms. This is nan if it is not used.
  
  References
  ----------
  .. [1] Hoffman, Matthew D., & Gelman, Andrew. (2011). The No-U-Turn
     Sampler: Adaptively Setting Path Lengths in Hamiltonian Monte Carlo.
docstr: Set up the No-U-Turn sampler.
  
  Parameters
  ----------
  vars: list, default=None
      List of value variables. If None, all continuous RVs from the
      model are included.
  Emax: float, default 1000
      Maximum energy change allowed during leapfrog steps. Larger
      deviations will abort the integration.
  target_accept: float, default .8
      Adapt the step size such that the average acceptance
      probability across the trajectories are close to target_accept.
      Higher values for target_accept lead to smaller step sizes.
      Setting this to higher values like 0.9 or 0.99 can help
      with sampling from difficult posteriors. Valid values are
      between 0 and 1 (exclusive).
  step_scale: float, default 0.25
      Size of steps to take, automatically scaled down by `1/n**(1/4)`.
      If step size adaptation is switched off, the resulting step size
      is used. If adaptation is enabled, it is used as initial guess.
  gamma: float, default .05
  k: float, default .75
      Parameter for dual averaging for step size adaptation. Values
      between 0.5 and 1 (exclusive) are admissible. Higher values
      correspond to slower adaptation.
  t0: int, default 10
      Parameter for dual averaging. Higher values slow initial
      adaptation.
  adapt_step_size: bool, default=True
      Whether step size adaptation should be enabled. If this is
      disabled, `k`, `t0`, `gamma` and `target_accept` are ignored.
  max_treedepth: int, default=10
      The maximum tree depth. Trajectories are stopped when this
      depth is reached.
  early_max_treedepth: int, default=8
      The maximum tree depth during the first 200 tuning samples.
  scaling: array_like, ndim = {1,2}
      The inverse mass, or precision matrix. One dimensional arrays are
      interpreted as diagonal matrices. If `is_cov` is set to True,
      this will be interpreted as the mass or covariance matrix.
  is_cov: bool, default=False
      Treat the scaling as mass or covariance matrix.
  potential: Potential, optional
      An object that represents the Hamiltonian with methods `velocity`,
      `energy`, and `random` methods. It can be specified instead
      of the scaling matrix.
  model: pymc.Model
      The model
  kwargs: passed to BaseHMC
  
  Notes
  -----
  The step size adaptation stops when `self.tune` is set to False.
  This is usually achieved by setting the `tune` parameter if
  `pm.sample` to the desired number of tuning steps.
docstr_tok: ["Set","up","the","No-U-Turn","sampler",".","Parameters","--","--","--","--","--","vars",":","list",",","default=None","List","of","value","variables",".","If","None",",","all","continuous","RVs","from","the","model","are","included",".","Emax",":","float",",","default","1000","Maximum","energy","change","allowed","during","leapfrog","steps",".","Larger","deviations","will","abort","the","integration",".","target_accept",":","float",",","default",".8","Adapt","the","step","size","such","that","the","average","acceptance","probability","across","the","trajectories","are","close","to","target_accept",".","Higher","values","for","target_accept","lead","to","smaller","step","sizes",".","Setting","this","to","higher","values","like","0.9","or","0.99","can","help","with","sampling","from","difficult","posteriors",".","Valid","values","are","between","0","and","1","(","exclusive",")",".","step_scale",":","float",",","default","0.25","Size","of","steps","to","take",",","automatically","scaled","down","by","`","1\/n","*","*","(","1\/4",")","`",".","If","step","size","adaptation","is","switched","off",",","the","resulting","step","size","is","used",".","If","adaptation","is","enabled",",","it","is","used","as","initial","guess",".","gamma",":","float",",","default",".05","k",":","float",",","default",".75","Parameter","for","dual","averaging","for","step","size","adaptation",".","Values","between","0.5","and","1","(","exclusive",")","are","admissible",".","Higher","values","correspond","to","slower","adaptation",".","t0",":","int",",","default","10","Parameter","for","dual","averaging",".","Higher","values","slow","initial","adaptation",".","adapt_step_size",":","bool",",","default=True","Whether","step","size","adaptation","should","be","enabled",".","If","this","is","disabled",",","`","k","`",",","`","t0","`",",","`","gamma","`","and","`","target_accept","`","are","ignored",".","max_treedepth",":","int",",","default=10","The","maximum","tree","depth",".","Trajectories","are","stopped","when","this","depth","is","reached",".","early_max_treedepth",":","int",",","default=8","The","maximum","tree","depth","during","the","first","200","tuning","samples",".","scaling",":","array_like",",","ndim","=","{","1,2","}","The","inverse","mass",",","or","precision","matrix",".","One","dimensional","arrays","are","interpreted","as","diagonal","matrices",".","If","`","is_cov","`","is","set","to","True",",","this","will","be","interpreted","as","the","mass","or","covariance","matrix",".","is_cov",":","bool",",","default=False","Treat","the","scaling","as","mass","or","covariance","matrix",".","potential",":","Potential",",","optional","An","object","that","represents","the","Hamiltonian","with","methods","`","velocity","`",",","`","energy","`",",","and","`","random","`","methods",".","It","can","be","specified","instead","of","the","scaling","matrix",".","model",":","pymc.Model","The","model","kwargs",":","passed","to","BaseHMC","Notes","--","--","-","The","step","size","adaptation","stops","when","`","self.tune","`","is","set","to","False",".","This","is","usually","achieved","by","setting","the","`","tune","`","parameter","if","`","pm.sample","`","to","the","desired","number","of","tuning","steps","."]
code: def __init__(
      self, vars=None, max_treedepth=10, early_max_treedepth=8, **kwargs
  ):
      r"""Set up the No-U-Turn sampler.
  
      Parameters
      ----------
      vars: list, default=None
          List of value variables. If None, all continuous RVs from the
          model are included.
      Emax: float, default 1000
          Maximum energy change allowed during leapfrog steps. Larger
          deviations will abort the integration.
      target_accept: float, default .8
          Adapt the step size such that the average acceptance
          probability across the trajectories are close to target_accept.
          Higher values for target_accept lead to smaller step sizes.
          Setting this to higher values like 0.9 or 0.99 can help
          with sampling from difficult posteriors. Valid values are
          between 0 and 1 (exclusive).
      step_scale: float, default 0.25
          Size of steps to take, automatically scaled down by `1/n**(1/4)`.
          If step size adaptation is switched off, the resulting step size
          is used. If adaptation is enabled, it is used as initial guess.
      gamma: float, default .05
      k: float, default .75
          Parameter for dual averaging for step size adaptation. Values
          between 0.5 and 1 (exclusive) are admissible. Higher values
          correspond to slower adaptation.
      t0: int, default 10
          Parameter for dual averaging. Higher values slow initial
          adaptation.
      adapt_step_size: bool, default=True
          Whether step size adaptation should be enabled. If this is
          disabled, `k`, `t0`, `gamma` and `target_accept` are ignored.
      max_treedepth: int, default=10
          The maximum tree depth. Trajectories are stopped when this
          depth is reached.
      early_max_treedepth: int, default=8
          The maximum tree depth during the first 200 tuning samples.
      scaling: array_like, ndim = {1,2}
          The inverse mass, or precision matrix. One dimensional arrays are
          interpreted as diagonal matrices. If `is_cov` is set to True,
          this will be interpreted as the mass or covariance matrix.
      is_cov: bool, default=False
          Treat the scaling as mass or covariance matrix.
      potential: Potential, optional
          An object that represents the Hamiltonian with methods `velocity`,
          `energy`, and `random` methods. It can be specified instead
          of the scaling matrix.
      model: pymc.Model
          The model
      kwargs: passed to BaseHMC
  
      Notes
      -----
      The step size adaptation stops when `self.tune` is set to False.
      This is usually achieved by setting the `tune` parameter if
      `pm.sample` to the desired number of tuning steps.
      """
      super().__init__(vars, **kwargs)
  
      self.max_treedepth = max_treedepth
      self.early_max_treedepth = early_max_treedepth
      self._reached_max_treedepth = 0
  
imports: from __future__ import annotations
  from collections import namedtuple
  import numpy
  from pymc.math import logbern
  from pymc.pytensorf import floatX
  from pymc.stats.convergence import SamplerWarning
  from pymc.step_methods.compound import Competence
  from pymc.step_methods.hmc import integration
  from pymc.step_methods.hmc.base_hmc import BaseHMC, DivergenceInfo, HMCStepData
  from pymc.step_methods.hmc.integration import IntegrationError, State
  from pymc.vartypes import continuous_types
label_desc: Use image node_id 1 to create a new NUTS object from inherited base classes: BaseHMC with example: obj = NUTS(vars, max_treedepth, early_max_treedepth)