class_docstr: Sum of structural time series components.
  
  This class enables compositional specification of a structural time series
  model from basic components. Given a list of component models, it represents
  an additive model, i.e., a model of time series that may be decomposed into a
  sum of terms corresponding to the component models.
  
  Formally, the additive model represents a random process
  `g[t] = f1[t] + f2[t] + ... + fN[t] + eps[t]`, where the `f`'s are the
  random processes represented by the components, and
  `eps[t] ~ Normal(loc=0, scale=observation_noise_scale)` is an observation
  noise term. See the `AdditiveStateSpaceModel` documentation for mathematical
  details.
  
  This model inherits the parameters (with priors) of its components, and
  adds an `observation_noise_scale` parameter governing the level of noise in
  the observed time series.
  
  #### Examples
  
  To construct a model combining a local linear trend with a day-of-week effect:
  
  ```
    local_trend = tfp.sts.LocalLinearTrend(
        observed_time_series=observed_time_series,
        name='local_trend')
    day_of_week_effect = tfp.sts.Seasonal(
        num_seasons=7,
        observed_time_series=observed_time_series,
        name='day_of_week_effect')
    additive_model = tfp.sts.Sum(
        components=[local_trend, day_of_week_effect],
        observed_time_series=observed_time_series)
  
    print([p.name for p in additive_model.parameters])
    # => `[observation_noise_scale,
    #      local_trend_level_scale,
    #      local_trend_slope_scale,
    #      day_of_week_effect_drift_scale`]
  
    print(local_trend.latent_size,
          seasonal.latent_size,
          additive_model.latent_size)
    # => `2`, `7`, `9`
  ```
class_docstr_tok: ["Sum","of","structural","time","series","components",".","This","class","enables","compositional","specification","of","a","structural","time","series","model","from","basic","components",".","Given","a","list","of","component","models",",","it","represents","an","additive","model",",","i.e.",",","a","model","of","time","series","that","may","be","decomposed","into","a","sum","of","terms","corresponding","to","the","component","models",".","Formally",",","the","additive","model","represents","a","random","process","`","g","[","t","]","=","f1","[","t","]","+","f2","[","t","]","+","...","+","fN","[","t","]","+","eps","[","t","]","`",",","where","the","`","f","`","'s","are","the","random","processes","represented","by","the","components",",","and","`","eps","[","t","]","~","Normal","(","loc=0",",","scale=observation_noise_scale",")","`","is","an","observation","noise","term",".","See","the","`","AdditiveStateSpaceModel","`","documentation","for","mathematical","details",".","This","model","inherits","the","parameters","(","with","priors",")","of","its","components",",","and","adds","an","`","observation_noise_scale","`","parameter","governing","the","level","of","noise","in","the","observed","time","series",".","#","#","#","#","Examples","To","construct","a","model","combining","a","local","linear","trend","with","a","day-of-week","effect",":","``","`","local_trend","=","tfp.sts.LocalLinearTrend","(","observed_time_series=observed_time_series",",","name='local_trend","'",")","day_of_week_effect","=","tfp.sts.Seasonal","(","num_seasons=7",",","observed_time_series=observed_time_series",",","name='day_of_week_effect","'",")","additive_model","=","tfp.sts.Sum","(","components=","[","local_trend",",","day_of_week_effect","]",",","observed_time_series=observed_time_series",")","print","(","[","p.name","for","p","in","additive_model.parameters","]",")","#","=",">","`","[","observation_noise_scale",",","#","local_trend_level_scale",",","#","local_trend_slope_scale",",","#","day_of_week_effect_drift_scale","`","]","print","(","local_trend.latent_size",",","seasonal.latent_size",",","additive_model.latent_size",")","#","=",">","`","2","`",",","`","7","`",",","`","9","`","``","`"]
docstr: Specify a structural time series model representing a sum of components.
  
  Args:
    components: Python `list` of one or more StructuralTimeSeries instances.
      These must have unique names.
    constant_offset: optional `float` `Tensor` of shape broadcasting to
      `concat([batch_shape, [num_timesteps]]`) specifying a constant value
      added to the sum of outputs from the component models.
      This allows the components to model the shifted series
      `observed_time_series - constant_offset`. If `None`, this is set to the
      mean of the provided `observed_time_series`.
      Default value: `None`.
    observation_noise_scale_prior: optional `tfd.Distribution` instance
      specifying a prior on `observation_noise_scale`. 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: Python `str` name of this model component; used as `name_scope`
      for ops created by this class.
      Default value: 'Sum'.
  
  Raises:
    ValueError: if components do not have unique names.
docstr_tok: ["Specify","a","structural","time","series","model","representing","a","sum","of","components",".","Args",":","components",":","Python","`","list","`","of","one","or","more","StructuralTimeSeries","instances",".","These","must","have","unique","names",".","constant_offset",":","optional","`","float","`","`","Tensor","`","of","shape","broadcasting","to","`","concat","(","[","batch_shape",",","[","num_timesteps","]","]","`",")","specifying","a","constant","value","added","to","the","sum","of","outputs","from","the","component","models",".","This","allows","the","components","to","model","the","shifted","series","`","observed_time_series","-","constant_offset","`",".","If","`","None","`",",","this","is","set","to","the","mean","of","the","provided","`","observed_time_series","`",".","Default","value",":","`","None","`",".","observation_noise_scale_prior",":","optional","`","tfd.Distribution","`","instance","specifying","a","prior","on","`","observation_noise_scale","`",".","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",":","Python","`","str","`","name","of","this","model","component",";","used","as","`","name_scope","`","for","ops","created","by","this","class",".","Default","value",":","'Sum","'",".","Raises",":","ValueError",":","if","components","do","not","have","unique","names","."]
code: def __init__(
      self,
      components,
      constant_offset=None,
      observation_noise_scale_prior=None,
      observed_time_series=None,
      name=None,
  ):
      """Specify a structural time series model representing a sum of components.
  
      Args:
        components: Python `list` of one or more StructuralTimeSeries instances.
          These must have unique names.
        constant_offset: optional `float` `Tensor` of shape broadcasting to
          `concat([batch_shape, [num_timesteps]]`) specifying a constant value
          added to the sum of outputs from the component models.
          This allows the components to model the shifted series
          `observed_time_series - constant_offset`. If `None`, this is set to the
          mean of the provided `observed_time_series`.
          Default value: `None`.
        observation_noise_scale_prior: optional `tfd.Distribution` instance
          specifying a prior on `observation_noise_scale`. 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: Python `str` name of this model component; used as `name_scope`
          for ops created by this class.
          Default value: 'Sum'.
  
      Raises:
        ValueError: if components do not have unique names.
      """
      init_parameters = dict(locals())
      with tf.name_scope(name or "Sum") as name:
          if observed_time_series is not None:
              (
                  observed_mean,
                  observed_stddev,
                  _,
              ) = sts_util.empirical_statistics(observed_time_series)
          else:
              observed_mean, observed_stddev = 0.0, 1.0
  
          if observation_noise_scale_prior is None:
              observation_noise_scale_prior = lognormal.LogNormal(
                  loc=tf.math.log(0.01 * observed_stddev), scale=2.0
              )
  
          dtype = dtype_util.common_dtype(
              [
                  constant_offset,
                  observation_noise_scale_prior,
                  observed_mean,
                  observed_stddev,
              ]
          )
  
          # Ensure that offsets have canonical shape `[..., num_timesteps]`.
          if constant_offset is None:
              constant_offset = tf.convert_to_tensor(
                  observed_mean, dtype=dtype
              )[..., tf.newaxis]
          constant_offset *= tf.ones([1], dtype=dtype)
  
          # Check that components have unique names, to ensure that inherited
          # parameters will be assigned unique names.
          component_names = [c.name for c in components]
          if len(component_names) != len(set(component_names)):
              raise ValueError(
                  "Components must have unique names: {}".format(
                      component_names
                  )
              )
          components_by_name = collections.OrderedDict(
              [(c.name, c) for c in components]
          )
  
          # Build parameters list for the combined model, by inheriting parameters
          # from the component models in canonical order.
          parameters = [
              Parameter(
                  "observation_noise_scale",
                  observation_noise_scale_prior,
                  chain.Chain(
                      [
                          scale.Scale(scale=observed_stddev),
                          softplus.Softplus(low=dtype_util.eps(dtype)),
                      ]
                  ),
              )
          ]
          for component in components:
              for parameter in component.parameters:
                  parameters.append(
                      Parameter(
                          name="{}_{}".format(
                              component.name, parameter.name
                          ),
                          prior=parameter.prior,
                          bijector=parameter.bijector,
                      )
                  )
  
          self._components = components
          self._components_by_name = components_by_name
          self._constant_offset = constant_offset
  
          super(Sum, self).__init__(
              parameters=parameters,
              latent_size=sum(
                  component.latent_size for component in components
              ),
              init_parameters=init_parameters,
              name=name,
          )
  
imports: import collections
  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.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 Sum object from inherited base classes: StructuralTimeSeries with example: obj = Sum(components, constant_offset, observation_noise_scale_prior, observed_time_series, name)