class_docstr: Sampling form the inverse of the metric volume element of a :class:`~pythae.models.RHVAE`
  model.
  
  Args:
      model (RHVAE): The VAE model to sample from
      sampler_config (RHVAESamplerConfig): A RHVAESamplerConfig instance containing the main
          parameters of the sampler. If None, a pre-defined configuration is used. Default: None
class_docstr_tok: ["Sampling","form","the","inverse","of","the","metric","volume","element","of","a",":","class",":","`","~pythae.models.RHVAE","`","model",".","Args",":","model","(","RHVAE",")",":","The","VAE","model","to","sample","from","sampler_config","(","RHVAESamplerConfig",")",":","A","RHVAESamplerConfig","instance","containing","the","main","parameters","of","the","sampler",".","If","None",",","a","pre-defined","configuration","is","used",".","Default",":","None"]
code: def hmc_sampling(self, n_samples: int):
      with torch.no_grad():
          idx = torch.randint(
              len(self.model.centroids_tens), (n_samples,)
          )
  
          z0 = self.model.centroids_tens[idx]
  
          beta_sqrt_old = self.beta_zero_sqrt
          z = z0
          for i in range(self.mcmc_steps_nbr):
              gamma = torch.randn_like(z, device=self.device)
              rho = gamma / self.beta_zero_sqrt
  
              H0 = (
                  -self.log_pi(z, self.model)
                  + 0.5 * torch.norm(rho, dim=1) ** 2
              )
              # print(model.G_inv(z).det())
  
              for k in range(self.n_lf):
                  g = -self.grad_func(z, self.model).reshape(
                      n_samples, self.model.latent_dim
                  )
                  # step 1
                  rho_ = rho - (self.eps_lf / 2) * g
  
                  # step 2
                  z = z + self.eps_lf * rho_
  
                  g = -self.grad_func(z, self.model).reshape(
                      n_samples, self.model.latent_dim
                  )
                  # g = (Sigma_inv @ (z - mu).T).reshape(n_samples, 2)
  
                  # step 3
                  rho__ = rho_ - (self.eps_lf / 2) * g
  
                  # tempering
                  beta_sqrt = RHVAESampler.tempering(
                      k + 1, self.n_lf, self.beta_zero_sqrt
                  )
  
                  rho = (beta_sqrt_old / beta_sqrt) * rho__
                  beta_sqrt_old = beta_sqrt
  
              H = (
                  -self.log_pi(z, self.model)
                  + 0.5 * torch.norm(rho, dim=1) ** 2
              )
              alpha = torch.exp(-H) / (torch.exp(-H0))
              acc = torch.rand(n_samples).to(self.device)
              moves = (
                  (acc < alpha).type(torch.int).reshape(n_samples, 1)
              )
  
              z = z * moves + (1 - moves) * z0
  
              z0 = z
  
          return z
  
file_path: benchmark_VAE/src/pythae/samplers/manifold_sampler/rhvae_sampler.py
imports: import torch
  from ...models import RHVAE
  from ..base import BaseSampler
  from .rhvae_sampler_config import RHVAESamplerConfig
label_desc: Use image node_id 3 for calling the RHVAESampler obj's underlying member method code with example usage: obj.hmc_sampling(n_samples) and returns: z