code: def test_parameterized():
      class Linear(Parameterized):
          def __init__(self):
              super().__init__()
              self._pyro_name = "Linear"
              self.a = PyroParam(
                  torch.tensor(1.0), constraints.positive
              )
              self.b = PyroSample(dist.Normal(0, 1))
              self.c = PyroSample(dist.Normal(0, 1))
              self.d = PyroSample(
                  dist.Normal(0, 4).expand([1]).to_event()
              )
              self.e = PyroSample(dist.LogNormal(0, 1))
              self.f = PyroSample(
                  dist.MultivariateNormal(torch.zeros(2), torch.eye(2))
              )
              self.g = PyroSample(dist.Exponential(1))
  
          def forward(self, x):
              return (
                  self.a * x
                  + self.b
                  + self.c
                  + self.d
                  + self.e
                  + self.f
                  + self.g
                  + self.e
              )
  
      linear = Linear()
      linear.autoguide("c", dist.Normal)
      linear.autoguide("d", dist.MultivariateNormal)
      linear.autoguide("e", dist.Normal)
  
      assert set(dict(linear.named_parameters()).keys()) == {
          "a_unconstrained",
          "b_map",
          "c_loc",
          "c_scale_unconstrained",
          "d_loc",
          "d_scale_tril_unconstrained",
          "e_loc",
          "e_scale_unconstrained",
          "f_map",
          "g_map_unconstrained",
      }
  
      def model(x):
          linear.mode = "model"
          return linear(x)
  
      def guide(x):
          linear.mode = "guide"
          return linear(x)
  
      model_trace = pyro.poutine.trace(model).get_trace(
          torch.tensor(5.0)
      )
      guide_trace = pyro.poutine.trace(guide).get_trace(
          torch.tensor(5.0)
      )
      for p in ["b", "c", "d"]:
          assert "Linear.{}".format(p) in model_trace.nodes
          assert "Linear.{}".format(p) in guide_trace.nodes
  
      assert isinstance(guide_trace.nodes["Linear.b"]["fn"], dist.Delta)
      c_dist = guide_trace.nodes["Linear.c"]["fn"]
      assert isinstance(
          getattr(c_dist, "base_dist", c_dist), dist.Normal
      )
      d_dist = guide_trace.nodes["Linear.d"]["fn"]
      assert isinstance(
          getattr(d_dist, "base_dist", d_dist), dist.MultivariateNormal
      )
  
file_path: pyro/tests/contrib/gp/test_parameterized.py
imports: import torch
  from torch.distributions import constraints
  from torch.nn import Parameter
  import pyro
  import pyro.distributions
  from pyro.contrib.gp.parameterized import Parameterized
  from pyro.nn.module import PyroParam, PyroSample
  from tests.common import assert_equal
label_desc: Use image node_id 1 for calling a global function with example usage: test_parameterized() and returns: linear, linear, unknown