class_docstr: Formal representation of a local level model.
  
  The local level model posits a `level` evolving via a Gaussian random walk:
  
  ```
  level[t] = level[t-1] + Normal(0., level_scale)
  ```
  
  The latent state is `[level]`. We observe a noisy realization of the current
  level: `f[t] = level[t] + Normal(0., observation_noise_scale)` at each
  timestep.
class_docstr_tok: ["Formal","representation","of","a","local","level","model",".","The","local","level","model","posits","a","`","level","`","evolving","via","a","Gaussian","random","walk",":","``","`","level","[","t","]","=","level","[","t-1","]","+","Normal","(","0.",",","level_scale",")","``","`","The","latent","state","is","`","[","level","]","`",".","We","observe","a","noisy","realization","of","the","current","level",":","`","f","[","t","]","=","level","[","t","]","+","Normal","(","0.",",","observation_noise_scale",")","`","at","each","timestep","."]
docstr: Specify a local level model.
  
  Args:
    level_scale_prior: optional `tfd.Distribution` instance specifying a prior
      on the `level_scale` parameter. If `None`, a heuristic default prior is
      constructed based on the provided `observed_time_series`.
      Default value: `None`.
    initial_level_prior: optional `tfd.Distribution` instance specifying a
      prior on the initial level. If `None`, a heuristic default prior is
      constructed based on the provided `observed_time_series`.
      Default value: `None`.
    observed_time_series: optional `float` `Tensor` of shape
      `batch_shape + [T, 1]` (omitting the trailing unit dimension is also
      supported when `T > 1`), specifying an observed time series. Any `NaN`s
      are interpreted as missing observations; missingness may be also be
      explicitly specified by passing a `tfp.sts.MaskedTimeSeries` instance.
      Any priors not explicitly set will be given default values according to
      the scale of the observed time series (or batch of time series).
      Default value: `None`.
    name: the name of this model component.
      Default value: 'LocalLevel'.
docstr_tok: ["Specify","a","local","level","model",".","Args",":","level_scale_prior",":","optional","`","tfd.Distribution","`","instance","specifying","a","prior","on","the","`","level_scale","`","parameter",".","If","`","None","`",",","a","heuristic","default","prior","is","constructed","based","on","the","provided","`","observed_time_series","`",".","Default","value",":","`","None","`",".","initial_level_prior",":","optional","`","tfd.Distribution","`","instance","specifying","a","prior","on","the","initial","level",".","If","`","None","`",",","a","heuristic","default","prior","is","constructed","based","on","the","provided","`","observed_time_series","`",".","Default","value",":","`","None","`",".","observed_time_series",":","optional","`","float","`","`","Tensor","`","of","shape","`","batch_shape","+","[","T",",","1","]","`","(","omitting","the","trailing","unit","dimension","is","also","supported","when","`","T",">","1","`",")",",","specifying","an","observed","time","series",".","Any","`","NaN","`","s","are","interpreted","as","missing","observations",";","missingness","may","be","also","be","explicitly","specified","by","passing","a","`","tfp.sts.MaskedTimeSeries","`","instance",".","Any","priors","not","explicitly","set","will","be","given","default","values","according","to","the","scale","of","the","observed","time","series","(","or","batch","of","time","series",")",".","Default","value",":","`","None","`",".","name",":","the","name","of","this","model","component",".","Default","value",":","'LocalLevel","'","."]
code: def __init__(
      self,
      level_scale_prior=None,
      initial_level_prior=None,
      observed_time_series=None,
      name=None,
  ):
      """Specify a local level model.
  
      Args:
        level_scale_prior: optional `tfd.Distribution` instance specifying a prior
          on the `level_scale` parameter. If `None`, a heuristic default prior is
          constructed based on the provided `observed_time_series`.
          Default value: `None`.
        initial_level_prior: optional `tfd.Distribution` instance specifying a
          prior on the initial level. If `None`, a heuristic default prior is
          constructed based on the provided `observed_time_series`.
          Default value: `None`.
        observed_time_series: optional `float` `Tensor` of shape
          `batch_shape + [T, 1]` (omitting the trailing unit dimension is also
          supported when `T > 1`), specifying an observed time series. Any `NaN`s
          are interpreted as missing observations; missingness may be also be
          explicitly specified by passing a `tfp.sts.MaskedTimeSeries` instance.
          Any priors not explicitly set will be given default values according to
          the scale of the observed time series (or batch of time series).
          Default value: `None`.
        name: the name of this model component.
          Default value: 'LocalLevel'.
      """
      init_parameters = dict(locals())
      with tf.name_scope(name or "LocalLevel") as name:
          if observed_time_series is not None:
              (
                  _,
                  observed_stddev,
                  observed_initial,
              ) = sts_util.empirical_statistics(observed_time_series)
          else:
              observed_stddev, observed_initial = 1.0, 0.0
  
          dtype = dtype_util.common_dtype(
              [
                  level_scale_prior,
                  initial_level_prior,
                  observed_stddev,
                  observed_initial,
              ],
              dtype_hint=tf.float32,
          )
  
          # Heuristic default priors. Overriding these may dramatically
          # change inference performance and results.
          if level_scale_prior is None:
              level_scale_prior = lognormal.LogNormal(
                  loc=tf.math.log(0.05 * observed_stddev),
                  scale=3.0,
                  name="level_scale_prior",
              )
          if initial_level_prior is None:
              self._initial_state_prior = (
                  mvn_diag.MultivariateNormalDiag(
                      loc=tf.convert_to_tensor(observed_initial)[
                          ..., tf.newaxis
                      ],
                      scale_diag=(
                          tf.abs(observed_initial) + observed_stddev
                      )[..., tf.newaxis],
                      name="initial_level_prior",
                  )
              )
          else:
              self._initial_state_prior = (
                  mvn_diag.MultivariateNormalDiag(
                      loc=initial_level_prior.mean()[..., tf.newaxis],
                      scale_diag=initial_level_prior.stddev()[
                          ..., tf.newaxis
                      ],
                  )
              )
  
          super(LocalLevel, self).__init__(
              parameters=[
                  Parameter(
                      "level_scale",
                      level_scale_prior,
                      chain.Chain(
                          [
                              scale.Scale(scale=observed_stddev),
                              softplus.Softplus(
                                  low=dtype_util.eps(dtype)
                              ),
                          ]
                      ),
                  ),
              ],
              latent_size=1,
              init_parameters=init_parameters,
              name=name,
          )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import chain
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import linear_gaussian_ssm
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.sts.internal import util
  from tensorflow_probability.python.sts.structural_time_series import Parameter
  from tensorflow_probability.python.sts.structural_time_series import StructuralTimeSeries
label_desc: Use image node_id 1 to create a new LocalLevel object from inherited base classes: StructuralTimeSeries with example: obj = LocalLevel(level_scale_prior, initial_level_prior, observed_time_series, name)