class_docstr: :class:`AutoMessenger` with mean-field normal posterior.
  
  The mean-field posterior at any site is a transformed normal distribution.
  This posterior is equivalent to :class:`~pyro.infer.autoguide.AutoNormal`
  or :class:`~pyro.infer.autoguide.AutoDiagonalNormal`, but allows
  customization via subclassing.
  
  Derived classes may override the :meth:`get_posterior` behavior at
  particular sites and use the mean-field normal behavior simply as a
  default, e.g.::
  
      def model(data):
          a = pyro.sample("a", dist.Normal(0, 1))
          b = pyro.sample("b", dist.Normal(0, 1))
          c = pyro.sample("c", dist.Normal(a + b, 1))
          pyro.sample("obs", dist.Normal(c, 1), obs=data)
  
      class MyGuideMessenger(AutoNormalMessenger):
          def get_posterior(self, name, prior):
              if name == "c":
                  # Use a custom distribution at site c.
                  bias = pyro.param("c_bias", lambda: torch.zeros(()))
                  weight = pyro.param("c_weight", lambda: torch.ones(()),
                                      constraint=constraints.positive)
                  scale = pyro.param("c_scale", lambda: torch.ones(()),
                                     constraint=constraints.positive)
                  a = self.upstream_value("a")
                  b = self.upstream_value("b")
                  loc = bias + weight * (a + b)
                  return dist.Normal(loc, scale)
              # Fall back to mean field.
              return super().get_posterior(name, prior)
  
  Note that above we manually computed ``loc = bias + weight * (a + b)``.
  Alternatively we could reuse the model-side computation by setting ``loc =
  bias + weight * prior.loc``::
  
      class MyGuideMessenger_v2(AutoNormalMessenger):
          def get_posterior(self, name, prior):
              if name == "c":
                  # Use a custom distribution at site c.
                  bias = pyro.param("c_bias", lambda: torch.zeros(()))
                  scale = pyro.param("c_scale", lambda: torch.ones(()),
                                     constraint=constraints.positive)
                  weight = pyro.param("c_weight", lambda: torch.ones(()),
                                      constraint=constraints.positive)
                  loc = bias + weight * prior.loc
                  return dist.Normal(loc, scale)
              # Fall back to mean field.
              return super().get_posterior(name, prior)
  
  :param callable model: A Pyro model.
  :param callable init_loc_fn: A per-site initialization function.
      See :ref:`autoguide-initialization` section for available functions.
  :param float init_scale: Initial scale for the standard deviation of each
      (unconstrained transformed) latent variable.
  :param tuple amortized_plates: A tuple of names of plates over which guide
      parameters should be shared. This is useful for subsampling, where a
      guide parameter can be shared across all plates.
class_docstr_tok: [":","class",":","`","AutoMessenger","`","with","mean-field","normal","posterior",".","The","mean-field","posterior","at","any","site","is","a","transformed","normal","distribution",".","This","posterior","is","equivalent","to",":","class",":","`","~pyro.infer.autoguide.AutoNormal","`","or",":","class",":","`","~pyro.infer.autoguide.AutoDiagonalNormal","`",",","but","allows","customization","via","subclassing",".","Derived","classes","may","override","the",":","meth",":","`","get_posterior","`","behavior","at","particular","sites","and","use","the","mean-field","normal","behavior","simply","as","a","default",",","e.g",".",":",":","def","model","(","data",")",":","a","=","pyro.sample","(","``","a","''",",","dist.Normal","(","0",",","1",")",")","b","=","pyro.sample","(","``","b","''",",","dist.Normal","(","0",",","1",")",")","c","=","pyro.sample","(","``","c","''",",","dist.Normal","(","a","+","b",",","1",")",")","pyro.sample","(","``","obs","''",",","dist.Normal","(","c",",","1",")",",","obs=data",")","class","MyGuideMessenger","(","AutoNormalMessenger",")",":","def","get_posterior","(","self",",","name",",","prior",")",":","if","name","==","``","c","''",":","#","Use","a","custom","distribution","at","site","c.","bias","=","pyro.param","(","``","c_bias","''",",","lambda",":","torch.zeros","(","(",")",")",")","weight","=","pyro.param","(","``","c_weight","''",",","lambda",":","torch.ones","(","(",")",")",",","constraint=constraints.positive",")","scale","=","pyro.param","(","``","c_scale","''",",","lambda",":","torch.ones","(","(",")",")",",","constraint=constraints.positive",")","a","=","self.upstream_value","(","``","a","''",")","b","=","self.upstream_value","(","``","b","''",")","loc","=","bias","+","weight","*","(","a","+","b",")","return","dist.Normal","(","loc",",","scale",")","#","Fall","back","to","mean","field",".","return","super","(",")",".get_posterior","(","name",",","prior",")","Note","that","above","we","manually","computed","``","loc","=","bias","+","weight","*","(","a","+","b",")","``",".","Alternatively","we","could","reuse","the","model-side","computation","by","setting","``","loc","=","bias","+","weight","*","prior.loc","``",":",":","class","MyGuideMessenger_v2","(","AutoNormalMessenger",")",":","def","get_posterior","(","self",",","name",",","prior",")",":","if","name","==","``","c","''",":","#","Use","a","custom","distribution","at","site","c.","bias","=","pyro.param","(","``","c_bias","''",",","lambda",":","torch.zeros","(","(",")",")",")","scale","=","pyro.param","(","``","c_scale","''",",","lambda",":","torch.ones","(","(",")",")",",","constraint=constraints.positive",")","weight","=","pyro.param","(","``","c_weight","''",",","lambda",":","torch.ones","(","(",")",")",",","constraint=constraints.positive",")","loc","=","bias","+","weight","*","prior.loc","return","dist.Normal","(","loc",",","scale",")","#","Fall","back","to","mean","field",".","return","super","(",")",".get_posterior","(","name",",","prior",")",":","param","callable","model",":","A","Pyro","model",".",":","param","callable","init_loc_fn",":","A","per-site","initialization","function",".","See",":","ref",":","`","autoguide-initialization","`","section","for","available","functions",".",":","param","float","init_scale",":","Initial","scale","for","the","standard","deviation","of","each","(","unconstrained","transformed",")","latent","variable",".",":","param","tuple","amortized_plates",":","A","tuple","of","names","of","plates","over","which","guide","parameters","should","be","shared",".","This","is","useful","for","subsampling",",","where","a","guide","parameter","can","be","shared","across","all","plates","."]
code: def _get_posterior_median(self, name, prior):
      transform = biject_to(prior.support)
      loc, scale = self._get_params(name, prior)
      return transform(loc)
  
imports: from typing import Callable, Optional, Tuple, Union
  import torch
  from torch.distributions import biject_to, constraints
  import pyro.distributions
  from pyro.distributions.distribution import Distribution
  from pyro.nn.module import PyroModule, PyroParam, pyro_method
  from pyro.ops.tensor_utils import periodic_repeat
  from pyro.poutine.guide import GuideMessenger
  from pyro.poutine.runtime import get_plates
  from .initialization import init_to_feasible, init_to_mean
  from .utils import deep_getattr, deep_setattr, helpful_support_errors
label_desc: Use image node_id 5 for calling the AutoNormalMessenger obj's underlying member method code with example usage: obj._get_posterior_median(name, prior) and returns: transform