code: def test_weighted_waic():
      a = 1 + torch.rand(10)
      b = 1 + torch.rand(10)
      c = 1 + torch.rand(10)
      expanded_x = torch.stack([a, b, c, a, b, a, c, a, c]).log()
      x = torch.stack([a, b, c]).log()
      log_weights = torch.tensor([4.0, 2, 3]).log()
      # assume weights are unnormalized
      log_weights = log_weights - torch.randn(1)
  
      w1, p1 = waic(x, log_weights)
      w2, p2 = waic(expanded_x)
  
      # test lpd
      lpd1 = -0.5 * w1 + p1
      lpd2 = -0.5 * w2 + p2
      assert_equal(lpd1, lpd2)
  
      # test p_waic (also test for weighted_variance)
      unbiased_p1 = p1 * 2 / 3
      unbiased_p2 = p2 * 8 / 9
      assert_equal(unbiased_p1, unbiased_p2)
  
      # test correctness for dim=-1
      w3, p3 = waic(x.t(), log_weights, dim=-1)
      assert_equal(w1, w3)
      assert_equal(p1, p3)
  
imports: import warnings
  import pytest
  import torch
  from pyro.ops.stats import _cummin, autocorrelation, autocovariance, crps_empirical, effective_sample_size, fit_generalized_pareto, gelman_rubin, hpdi, pi, quantile, resample, split_gelman_rubin, waic
  from tests.common import assert_close, assert_equal, xfail_if_not_implemented
label_desc: Use image node_id 20 for calling a global function with example usage: test_weighted_waic() without return types