code: def test_elbo():
      mu0 = 1.5
      sigma = 1.0
      y_obs = np.array([1.6, 1.4])
  
      post_mu = np.array([1.88], dtype=pytensor.config.floatX)
      post_sigma = np.array([1], dtype=pytensor.config.floatX)
      # Create a model for test
      with pm.Model() as model:
          mu = pm.Normal("mu", mu=mu0, sigma=sigma)
          pm.Normal("y", mu=mu, sigma=1, observed=y_obs)
  
      # Create variational gradient tensor
      mean_field = MeanField(model=model)
      with pytensor.config.change_flags(compute_test_value="off"):
          elbo = -pm.operators.KL(mean_field)()(10000)
  
      mean_field.shared_params["mu"].set_value(post_mu)
      mean_field.shared_params["rho"].set_value(
          np.log(np.exp(post_sigma) - 1)
      )
  
      f = pytensor.function([], elbo)
      elbo_mc = f()
  
      # Exact value
      elbo_true = -0.5 * (
          3
          + 3 * post_mu**2
          - 2 * (y_obs[0] + y_obs[1] + mu0) * post_mu
          + y_obs[0] ** 2
          + y_obs[1] ** 2
          + mu0**2
          + 3 * np.log(2 * np.pi)
      ) + 0.5 * (np.log(2 * np.pi) + 1)
      np.testing.assert_allclose(elbo_mc, elbo_true, rtol=0, atol=1e-1)
  
file_path: pymc/tests/variational/test_approximations.py
imports: import numpy
  import pytensor
  import pytest
  import pymc
  from pymc.variational.approximations import Empirical, MeanField
  from tests import models
label_desc: Use image node_id 3 for calling a global function with example usage: test_elbo() without return types