A pre-canned builder for diagonal gaussian posterior distributions.

  Given a true `getter` function and arguments forwarded from `tf.get_variable`,
  return a distribution object for a diagonal posterior over a variable of the
  requisite shape.

  Args:
    getter: The `getter` passed to a `custom_getter`. Please see the
      documentation for `tf.get_variable`.
    name: The `name` argument passed to `tf.get_variable`.
    shape: The `shape` argument passed to `tf.get_variable`.
    *args: See positional arguments passed to `tf.get_variable`.
    **kwargs: See keyword arguments passed to `tf.get_variable`.

  Returns:
    An instance of `tfp.distributions.Normal` representing the posterior
    distribution over the variable in question.

def diagonal_gaussian_posterior_builder(
    getter, name, shape=None, *args, **kwargs):
  """A pre-canned builder for diagonal gaussian posterior distributions.

  Given a true `getter` function and arguments forwarded from `tf.get_variable`,
  return a distribution object for a diagonal posterior over a variable of the
  requisite shape.

  Args:
    getter: The `getter` passed to a `custom_getter`. Please see the
      documentation for `tf.get_variable`.
    name: The `name` argument passed to `tf.get_variable`.
    shape: The `shape` argument passed to `tf.get_variable`.
    *args: See positional arguments passed to `tf.get_variable`.
    **kwargs: See keyword arguments passed to `tf.get_variable`.

  Returns:
    An instance of `tfp.distributions.Normal` representing the posterior
    distribution over the variable in question.
  """
  # Please see the documentation for
  # `tfp.distributions.param_static_shapes`.
  parameter_shapes = tfp.distributions.Normal.param_static_shapes(shape)

  loc_var = getter(
      name + "/posterior_loc", shape=parameter_shapes["loc"], *args, **kwargs)
  scale_var = getter(
      name + "/posterior_scale",
      shape=parameter_shapes["scale"],
      *args,
      **kwargs)
  posterior = tfp.distributions.Normal(
      loc=loc_var,
      scale=tf.nn.softplus(scale_var),
      name="{}_posterior_dist".format(name))
  return posterior