class_docstr: Formal representation of a local linear trend model.
  
  The local linear trend model posits a `level` and `slope`, each
  evolving via a Gaussian random walk:
  
  ```
  level[t] = level[t-1] + slope[t-1] + Normal(0., level_scale)
  slope[t] = slope[t-1] + Normal(0., slope_scale)
  ```
  
  The latent state is the two-dimensional tuple `[level, slope]`. At each
  timestep we observe a noisy realization of the current level:
  `f[t] = level[t] + Normal(0., observation_noise_scale)`. This model
  is appropriate for data where the trend direction and magnitude (latent
  `slope`) is consistent within short periods but may evolve over time.
  
  Note that this model can produce very high uncertainty forecasts, as
  uncertainty over the slope compounds quickly. If you expect your data to
  have nonzero long-term trend, i.e. that slopes tend to revert to some mean,
  then the `SemiLocalLinearTrend` model may produce sharper forecasts.
class_docstr_tok: ["Formal","representation","of","a","local","linear","trend","model",".","The","local","linear","trend","model","posits","a","`","level","`","and","`","slope","`",",","each","evolving","via","a","Gaussian","random","walk",":","``","`","level","[","t","]","=","level","[","t-1","]","+","slope","[","t-1","]","+","Normal","(","0.",",","level_scale",")","slope","[","t","]","=","slope","[","t-1","]","+","Normal","(","0.",",","slope_scale",")","``","`","The","latent","state","is","the","two-dimensional","tuple","`","[","level",",","slope","]","`",".","At","each","timestep","we","observe","a","noisy","realization","of","the","current","level",":","`","f","[","t","]","=","level","[","t","]","+","Normal","(","0.",",","observation_noise_scale",")","`",".","This","model","is","appropriate","for","data","where","the","trend","direction","and","magnitude","(","latent","`","slope","`",")","is","consistent","within","short","periods","but","may","evolve","over","time",".","Note","that","this","model","can","produce","very","high","uncertainty","forecasts",",","as","uncertainty","over","the","slope","compounds","quickly",".","If","you","expect","your","data","to","have","nonzero","long-term","trend",",","i.e",".","that","slopes","tend","to","revert","to","some","mean",",","then","the","`","SemiLocalLinearTrend","`","model","may","produce","sharper","forecasts","."]
docstr: Specify a local linear trend 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`.
    slope_scale_prior: optional `tfd.Distribution` instance specifying a prior
      on the `slope_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`.
    initial_slope_prior: optional `tfd.Distribution` instance specifying a
      prior on the initial slope. 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: 'LocalLinearTrend'.
docstr_tok: ["Specify","a","local","linear","trend","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","`",".","slope_scale_prior",":","optional","`","tfd.Distribution","`","instance","specifying","a","prior","on","the","`","slope_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","`",".","initial_slope_prior",":","optional","`","tfd.Distribution","`","instance","specifying","a","prior","on","the","initial","slope",".","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",":","'LocalLinearTrend","'","."]
code: def __init__(
      self,
      level_scale_prior=None,
      slope_scale_prior=None,
      initial_level_prior=None,
      initial_slope_prior=None,
      observed_time_series=None,
      name=None,
  ):
      """Specify a local linear trend 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`.
        slope_scale_prior: optional `tfd.Distribution` instance specifying a prior
          on the `slope_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`.
        initial_slope_prior: optional `tfd.Distribution` instance specifying a
          prior on the initial slope. 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: 'LocalLinearTrend'.
      """
      init_parameters = dict(locals())
      with tf.name_scope(name or "LocalLinearTrend") as name:
          _, observed_stddev, observed_initial = (
              sts_util.empirical_statistics(observed_time_series)
              if observed_time_series is not None
              else (0.0, 1.0, 0.0)
          )
  
          # 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 slope_scale_prior is None:
              slope_scale_prior = lognormal.LogNormal(
                  loc=tf.math.log(0.05 * observed_stddev),
                  scale=3.0,
                  name="slope_scale_prior",
              )
          if initial_level_prior is None:
              initial_level_prior = normal.Normal(
                  loc=observed_initial,
                  scale=tf.abs(observed_initial) + observed_stddev,
                  name="initial_level_prior",
              )
          if initial_slope_prior is None:
              initial_slope_prior = normal.Normal(
                  loc=0.0,
                  scale=observed_stddev,
                  name="initial_slope_prior",
              )
  
          dtype = dtype_util.common_dtype(
              [
                  level_scale_prior,
                  slope_scale_prior,
                  initial_level_prior,
                  initial_slope_prior,
              ]
          )
  
          self._initial_state_prior = mvn_diag.MultivariateNormalDiag(
              loc=tf.stack(
                  [
                      initial_level_prior.mean(),
                      initial_slope_prior.mean(),
                  ],
                  axis=-1,
              ),
              scale_diag=tf.stack(
                  [
                      initial_level_prior.stddev(),
                      initial_slope_prior.stddev(),
                  ],
                  axis=-1,
              ),
          )
  
          scaled_softplus = chain.Chain(
              [
                  scale.Scale(scale=observed_stddev),
                  softplus.Softplus(low=dtype_util.eps(dtype)),
              ]
          )
          super(LocalLinearTrend, self).__init__(
              parameters=[
                  Parameter(
                      "level_scale", level_scale_prior, scaled_softplus
                  ),
                  Parameter(
                      "slope_scale", slope_scale_prior, scaled_softplus
                  ),
              ],
              latent_size=2,
              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.distributions import normal
  from tensorflow_probability.python.internal import distribution_util
  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 LocalLinearTrend object from inherited base classes: StructuralTimeSeries with example: obj = LocalLinearTrend(level_scale_prior, slope_scale_prior, initial_level_prior, initial_slope_prior, observed_time_series, name)