class_docstr: Metropolis-Hastings SMC_kernel
docstr: Update proposal scales for each particle dimension and update number of MH steps
docstr_tok: ["Update","proposal","scales","for","each","particle","dimension","and","update","number","of","MH","steps"]
code: def tune(self):
      """Update proposal scales for each particle dimension and update number of MH steps"""
      if self.iteration > 1:
          # Rescale based on distance to 0.234 acceptance rate
          chain_scales = np.exp(
              np.log(self.proposal_scales)
              + (self.chain_acc_rate - 0.234)
          )
          # Interpolate between individual and population scales
          self.proposal_scales = 0.5 * (
              chain_scales + chain_scales.mean()
          )
  
      # Update MVNormal proposal based on the covariance of the tempered posterior.
      cov = np.cov(self.tempered_posterior, ddof=0, rowvar=0)
      cov = np.atleast_2d(cov)
      cov += 1e-6 * np.eye(cov.shape[0])
      if np.isnan(cov).any() or np.isinf(cov).any():
          raise ValueError(
              'Sample covariances not valid! Likely "draws" is too small!'
          )
      self.proposal_dist = MultivariateNormalProposal(cov)
  
imports: import abc
  import sys
  import warnings
  from abc import ABC
  from typing import Dict, Union, cast
  import numpy
  import pytensor.tensor
  from pytensor.graph.replace import clone_replace
  from scipy.special import logsumexp
  from scipy.stats import multivariate_normal
  from typing_extensions import TypeAlias
  from pymc.backends.ndarray import NDArray
  from pymc.blocking import DictToArrayBijection
  from pymc.initial_point import make_initial_point_expression
  from pymc.model import Point, modelcontext
  from pymc.pytensorf import compile_pymc, floatX, join_nonshared_inputs, make_shared_replacements
  from pymc.sampling.forward import draw
  from pymc.step_methods.metropolis import MultivariateNormalProposal
  from pymc.vartypes import discrete_types
label_desc: Use image node_id 4 for calling the MH obj's underlying member method code with example usage: obj.tune() without return types