class_docstr: A wrapper of :class:`~pyro.nn.module.PyroModule` whose parameters can be set
  constraints, set priors.
  
  By default, when we set a prior to a parameter, an auto Delta guide will be
  created. We can use the method :meth:`autoguide` to setup other auto guides.
  
  Example::
  
      >>> class Linear(Parameterized):
      ...     def __init__(self, a, b):
      ...         super().__init__()
      ...         self.a = Parameter(a)
      ...         self.b = Parameter(b)
      ...
      ...     def forward(self, x):
      ...         return self.a * x + self.b
      ...
      >>> linear = Linear(torch.tensor(1.), torch.tensor(0.))
      >>> linear.a = PyroParam(torch.tensor(1.), constraints.positive)
      >>> linear.b = PyroSample(dist.Normal(0, 1))
      >>> linear.autoguide("b", dist.Normal)
      >>> assert "a_unconstrained" in dict(linear.named_parameters())
      >>> assert "b_loc" in dict(linear.named_parameters())
      >>> assert "b_scale_unconstrained" in dict(linear.named_parameters())
  
  Note that by default, data of a parameter is a float :class:`torch.Tensor`
  (unless we use :func:`torch.set_default_dtype` to change default
  tensor type). To cast these parameters to a correct data type or GPU device,
  we can call methods such as :meth:`~torch.nn.Module.double` or
  :meth:`~torch.nn.Module.cuda`. See :class:`torch.nn.Module` for more
  information.
class_docstr_tok: ["A","wrapper","of",":","class",":","`","~pyro.nn.module.PyroModule","`","whose","parameters","can","be","set","constraints",",","set","priors",".","By","default",",","when","we","set","a","prior","to","a","parameter",",","an","auto","Delta","guide","will","be","created",".","We","can","use","the","method",":","meth",":","`","autoguide","`","to","setup","other","auto","guides",".","Example",":",":",">",">",">","class","Linear","(","Parameterized",")",":","...","def","__init__","(","self",",","a",",","b",")",":","...","super","(",")",".__init__","(",")","...","self.a","=","Parameter","(","a",")","...","self.b","=","Parameter","(","b",")","...","...","def","forward","(","self",",","x",")",":","...","return","self.a","*","x","+","self.b","...",">",">",">","linear","=","Linear","(","torch.tensor","(","1",".",")",",","torch.tensor","(","0",".",")",")",">",">",">","linear.a","=","PyroParam","(","torch.tensor","(","1",".",")",",","constraints.positive",")",">",">",">","linear.b","=","PyroSample","(","dist.Normal","(","0",",","1",")",")",">",">",">","linear.autoguide","(","``","b","''",",","dist.Normal",")",">",">",">","assert","``","a_unconstrained","''","in","dict","(","linear.named_parameters","(",")",")",">",">",">","assert","``","b_loc","''","in","dict","(","linear.named_parameters","(",")",")",">",">",">","assert","``","b_scale_unconstrained","''","in","dict","(","linear.named_parameters","(",")",")","Note","that","by","default",",","data","of","a","parameter","is","a","float",":","class",":","`","torch.Tensor","`","(","unless","we","use",":","func",":","`","torch.set_default_dtype","`","to","change","default","tensor","type",")",".","To","cast","these","parameters","to","a","correct","data","type","or","GPU","device",",","we","can","call","methods","such","as",":","meth",":","`","~torch.nn.Module.double","`","or",":","meth",":","`","~torch.nn.Module.cuda","`",".","See",":","class",":","`","torch.nn.Module","`","for","more","information","."]
docstr: Sets an autoguide for an existing parameter with name ``name`` (mimic
  the behavior of module :mod:`pyro.infer.autoguide`).
  
  .. note:: `dist_constructor` should be one of
      :class:`~pyro.distributions.Delta`,
      :class:`~pyro.distributions.Normal`, and
      :class:`~pyro.distributions.MultivariateNormal`. More distribution
      constructor will be supported in the future if needed.
  
  :param str name: Name of the parameter.
  :param dist_constructor: A
      :class:`~pyro.distributions.distribution.Distribution` constructor.
docstr_tok: ["Sets","an","autoguide","for","an","existing","parameter","with","name","``","name","``","(","mimic","the","behavior","of","module",":","mod",":","`","pyro.infer.autoguide","`",")",".","..","note",":",":","`","dist_constructor","`","should","be","one","of",":","class",":","`","~pyro.distributions.Delta","`",",",":","class",":","`","~pyro.distributions.Normal","`",",","and",":","class",":","`","~pyro.distributions.MultivariateNormal","`",".","More","distribution","constructor","will","be","supported","in","the","future","if","needed",".",":","param","str","name",":","Name","of","the","parameter",".",":","param","dist_constructor",":","A",":","class",":","`","~pyro.distributions.distribution.Distribution","`","constructor","."]
code: def autoguide(self, name, dist_constructor):
      """
      Sets an autoguide for an existing parameter with name ``name`` (mimic
      the behavior of module :mod:`pyro.infer.autoguide`).
  
      .. note:: `dist_constructor` should be one of
          :class:`~pyro.distributions.Delta`,
          :class:`~pyro.distributions.Normal`, and
          :class:`~pyro.distributions.MultivariateNormal`. More distribution
          constructor will be supported in the future if needed.
  
      :param str name: Name of the parameter.
      :param dist_constructor: A
          :class:`~pyro.distributions.distribution.Distribution` constructor.
      """
      if name not in self._priors:
          raise ValueError(
              "There is no prior for parameter: {}".format(name)
          )
  
      if dist_constructor not in [
          dist.Delta,
          dist.Normal,
          dist.MultivariateNormal,
      ]:
          raise NotImplementedError(
              "Unsupported distribution type: {}".format(
                  dist_constructor
              )
          )
  
      # delete old guide
      if name in self._guides:
          dist_args = self._guides[name][1]
          for arg in dist_args:
              delattr(self, "{}_{}".format(name, arg))
  
      p = self._priors[name]()  # init_to_sample strategy
      if dist_constructor is dist.Delta:
          support = self._priors[name].support
          if _is_real_support(support):
              p_map = Parameter(p.detach())
          else:
              p_map = PyroParam(p.detach(), support)
          setattr(self, "{}_map".format(name), p_map)
          dist_args = ("map",)
      elif dist_constructor is dist.Normal:
          loc = Parameter(
              biject_to(self._priors[name].support).inv(p).detach()
          )
          scale = PyroParam(
              loc.new_ones(loc.shape), constraints.positive
          )
          setattr(self, "{}_loc".format(name), loc)
          setattr(self, "{}_scale".format(name), scale)
          dist_args = ("loc", "scale")
      elif dist_constructor is dist.MultivariateNormal:
          loc = Parameter(
              biject_to(self._priors[name].support).inv(p).detach()
          )
          identity = eye_like(loc, loc.size(-1))
          scale_tril = PyroParam(
              identity.repeat(loc.shape[:-1] + (1, 1)),
              constraints.lower_cholesky,
          )
          setattr(self, "{}_loc".format(name), loc)
          setattr(self, "{}_scale_tril".format(name), scale_tril)
          dist_args = ("loc", "scale_tril")
      else:
          raise NotImplementedError
  
      self._guides[name] = (dist_constructor, dist_args)
  
imports: import warnings
  from collections import OrderedDict
  from functools import partial
  from torch.distributions import biject_to, constraints
  from torch.nn import Parameter
  import pyro
  import pyro.distributions
  from pyro.distributions.util import eye_like
  from pyro.nn.module import PyroModule, PyroParam, PyroSample, pyro_method
label_desc: Use image node_id 4 for calling the Parameterized obj's underlying member method code with example usage: obj.autoguide(name, dist_constructor) without return types