code: def test_information_criterion():
      # milk dataset: https://github.com/rmcelreath/rethinking/blob/master/data/milk.csv
      kcal = torch.tensor(
          [
              0.49,
              0.47,
              0.56,
              0.89,
              0.92,
              0.8,
              0.46,
              0.71,
              0.68,
              0.97,
              0.84,
              0.62,
              0.54,
              0.49,
              0.48,
              0.55,
              0.71,
          ]
      )
      kcal_mean = kcal.mean()
      kcal_logstd = kcal.std().log()
  
      def model():
          mu = pyro.sample("mu", dist.Normal(kcal_mean, 1))
          log_sigma = pyro.sample(
              "log_sigma", dist.Normal(kcal_logstd, 1)
          )
          with pyro.plate("plate"):
              pyro.sample(
                  "kcal", dist.Normal(mu, log_sigma.exp()), obs=kcal
              )
  
      delta_guide = AutoLaplaceApproximation(model)
  
      svi = SVI(
          model,
          delta_guide,
          optim.Adam({"lr": 0.05}),
          loss=Trace_ELBO(),
          num_steps=0,
          num_samples=3000,
      )
      for i in range(100):
          svi.step()
  
      svi.guide = delta_guide.laplace_approximation()
      posterior = svi.run()
  
      ic = posterior.information_criterion()
      assert_equal(ic["waic"], torch.tensor(-8.3), prec=0.2)
      assert_equal(ic["p_waic"], torch.tensor(1.8), prec=0.2)
  
file_path: pyro/tests/infer/test_abstract_infer.py
imports: import pytest
  import torch
  import pyro
  import pyro.distributions
  import pyro.optim
  import pyro.poutine
  from pyro.infer import SVI, Trace_ELBO
  from pyro.infer.autoguide import AutoLaplaceApproximation
  from pyro.infer.mcmc import MCMC, NUTS
  from tests.common import assert_equal
label_desc: Use image node_id 3 for calling a global function with example usage: test_information_criterion() without return types