class_docstr: State space model for a smooth seasonal effect.
  
  A state space model (SSM) posits a set of latent (unobserved) variables that
  evolve over time with dynamics specified by a probabilistic transition model
  `p(z[t+1] | z[t])`. At each timestep, we observe a value sampled from an
  observation model conditioned on the current state, `p(x[t] | z[t])`. The
  special case where both the transition and observation models are Gaussians
  with mean specified as a linear function of the inputs, is known as a linear
  Gaussian state space model and supports tractable exact probabilistic
  calculations; see `tfp.distributions.LinearGaussianStateSpaceModel` for
  details.
  
  A smooth seasonal effect model is a special case of a linear Gaussian SSM. It
  is the sum of a set of "cyclic" components, with one component for each
  frequency:
  
  ```python
  frequencies[j] = 2. * pi * frequency_multipliers[j] / period
  ```
  
  Each cyclic component contains two latent states which we denote `effect` and
  `auxiliary`. The two latent states for component `j` drift over time via:
  
  ```python
  effect[t] = (effect[t - 1] * cos(frequencies[j]) +
               auxiliary[t - 1] * sin(frequencies[j]) +
               Normal(0., drift_scale))
  
  auxiliary[t] = (-effect[t - 1] * sin(frequencies[j]) +
                  auxiliary[t - 1] * cos(frequencies[j]) +
                  Normal(0., drift_scale))
  ```
  
  The `auxiliary` latent state only appears as a matter of construction and thus
  its interpretation is not particularly important. The total smooth seasonal
  effect is the sum of the `effect` values from each of the cyclic components.
  
  The parameters `drift_scale` and `observation_noise_scale` are each (a batch
  of) scalars. The batch shape of this `Distribution` is the broadcast batch
  shape of these parameters and of the `initial_state_prior`.
  
  #### Mathematical Details
  
  The smooth seasonal effect model implements a
  `tfp.distributions.LinearGaussianStateSpaceModel` with `latent_size = 2 *
  len(frequency_multipliers)` and `observation_size = 1`. The latent state is
  the concatenation of the cyclic latent states which themselves comprise an
  `effect` and an `auxiliary` state. The transition matrix is a block diagonal
  matrix where block `j` is:
  
  ```python
  transition_matrix[j] =  [[cos(frequencies[j]), sin(frequencies[j])],
                           [-sin(frequencies[j]), cos(frequencies[j])]]
  ```
  
  The observation model picks out the cyclic `effect` values from the latent
  state:
  
  ```
  observation_matrix = [[1., 0., 1., 0., ..., 1., 0.]]
  observation_noise ~ Normal(loc=0, scale=observation_noise_scale)
  ```
  
  For further mathematical details please see [1].
  
  #### Examples
  
  A state space model with smooth daily seasonality on hourly data. In other
  words, each day there is a pattern which broadly repeats itself over the
  course of the day and doesn't change too much from one hour to the next. Four
  random samples from such a model can be obtained via:
  
  ```python
  from matplotlib import pylab as plt
  
  ssm = SmoothSeasonalStateSpaceModel(
      num_timesteps=100,
      period=24,
      frequency_multipliers=[1, 4],
      drift_scale=0.1,
      initial_state_prior=tfd.MultivariateNormalDiag(
          scale_diag=tf.fill([4], 2.0)),
  )
  
  fig, axes = plt.subplots(4)
  
  series = ssm.sample(4)
  
  for series, ax in zip(series[..., 0], axes):
    ax.set_xticks(tf.range(ssm.num_timesteps, delta=ssm.period))
    ax.grid()
    ax.plot(series)
  
  plt.show()
  ```
  
  A comparison of the above with a comparable `Seasonal` component gives an
  example of the difference between these two components:
  
  ```python
  ssm = SeasonalStateSpaceModel(
      num_timesteps=100,
      num_seasons=24,
      num_steps_per_season=1,
      drift_scale=0.1,
      initial_state_prior=tfd.MultivariateNormalDiag(
          scale_diag=tf.fill([24], 2.0)),
  )
  ```
  
  #### References
  
  [1]: Harvey, A. Forecasting, Structural Time Series Models and the Kalman
    Filter. Cambridge: Cambridge University Press, 1990.
class_docstr_tok: ["State","space","model","for","a","smooth","seasonal","effect",".","A","state","space","model","(","SSM",")","posits","a","set","of","latent","(","unobserved",")","variables","that","evolve","over","time","with","dynamics","specified","by","a","probabilistic","transition","model","`","p","(","z","[","t+1","]","|","z","[","t","]",")","`",".","At","each","timestep",",","we","observe","a","value","sampled","from","an","observation","model","conditioned","on","the","current","state",",","`","p","(","x","[","t","]","|","z","[","t","]",")","`",".","The","special","case","where","both","the","transition","and","observation","models","are","Gaussians","with","mean","specified","as","a","linear","function","of","the","inputs",",","is","known","as","a","linear","Gaussian","state","space","model","and","supports","tractable","exact","probabilistic","calculations",";","see","`","tfp.distributions.LinearGaussianStateSpaceModel","`","for","details",".","A","smooth","seasonal","effect","model","is","a","special","case","of","a","linear","Gaussian","SSM",".","It","is","the","sum","of","a","set","of","``","cyclic","''","components",",","with","one","component","for","each","frequency",":","``","`","python","frequencies","[","j","]","=","2",".","*","pi","*","frequency_multipliers","[","j","]","\/","period","``","`","Each","cyclic","component","contains","two","latent","states","which","we","denote","`","effect","`","and","`","auxiliary","`",".","The","two","latent","states","for","component","`","j","`","drift","over","time","via",":","``","`","python","effect","[","t","]","=","(","effect","[","t","-","1","]","*","cos","(","frequencies","[","j","]",")","+","auxiliary","[","t","-","1","]","*","sin","(","frequencies","[","j","]",")","+","Normal","(","0.",",","drift_scale",")",")","auxiliary","[","t","]","=","(","-effect","[","t","-","1","]","*","sin","(","frequencies","[","j","]",")","+","auxiliary","[","t","-","1","]","*","cos","(","frequencies","[","j","]",")","+","Normal","(","0.",",","drift_scale",")",")","``","`","The","`","auxiliary","`","latent","state","only","appears","as","a","matter","of","construction","and","thus","its","interpretation","is","not","particularly","important",".","The","total","smooth","seasonal","effect","is","the","sum","of","the","`","effect","`","values","from","each","of","the","cyclic","components",".","The","parameters","`","drift_scale","`","and","`","observation_noise_scale","`","are","each","(","a","batch","of",")","scalars",".","The","batch","shape","of","this","`","Distribution","`","is","the","broadcast","batch","shape","of","these","parameters","and","of","the","`","initial_state_prior","`",".","#","#","#","#","Mathematical","Details","The","smooth","seasonal","effect","model","implements","a","`","tfp.distributions.LinearGaussianStateSpaceModel","`","with","`","latent_size","=","2","*","len","(","frequency_multipliers",")","`","and","`","observation_size","=","1","`",".","The","latent","state","is","the","concatenation","of","the","cyclic","latent","states","which","themselves","comprise","an","`","effect","`","and","an","`","auxiliary","`","state",".","The","transition","matrix","is","a","block","diagonal","matrix","where","block","`","j","`","is",":","``","`","python","transition_matrix","[","j","]","=","[","[","cos","(","frequencies","[","j","]",")",",","sin","(","frequencies","[","j","]",")","]",",","[","-sin","(","frequencies","[","j","]",")",",","cos","(","frequencies","[","j","]",")","]","]","``","`","The","observation","model","picks","out","the","cyclic","`","effect","`","values","from","the","latent","state",":","``","`","observation_matrix","=","[","[","1.",",","0.",",","1.",",","0.",",","...",",","1.",",","0",".","]","]","observation_noise","~","Normal","(","loc=0",",","scale=observation_noise_scale",")","``","`","For","further","mathematical","details","please","see","[","1","]",".","#","#","#","#","Examples","A","state","space","model","with","smooth","daily","seasonality","on","hourly","data",".","In","other","words",",","each","day","there","is","a","pattern","which","broadly","repeats","itself","over","the","course","of","the","day","and","does","n't","change","too","much","from","one","hour","to","the","next",".","Four","random","samples","from","such","a","model","can","be","obtained","via",":","``","`","python","from","matplotlib","import","pylab","as","plt","ssm","=","SmoothSeasonalStateSpaceModel","(","num_timesteps=100",",","period=24",",","frequency_multipliers=","[","1",",","4","]",",","drift_scale=0.1",",","initial_state_prior=tfd.MultivariateNormalDiag","(","scale_diag=tf.fill","(","[","4","]",",","2.0",")",")",",",")","fig",",","axes","=","plt.subplots","(","4",")","series","=","ssm.sample","(","4",")","for","series",",","ax","in","zip","(","series","[","...",",","0","]",",","axes",")",":","ax.set_xticks","(","tf.range","(","ssm.num_timesteps",",","delta=ssm.period",")",")","ax.grid","(",")","ax.plot","(","series",")","plt.show","(",")","``","`","A","comparison","of","the","above","with","a","comparable","`","Seasonal","`","component","gives","an","example","of","the","difference","between","these","two","components",":","``","`","python","ssm","=","SeasonalStateSpaceModel","(","num_timesteps=100",",","num_seasons=24",",","num_steps_per_season=1",",","drift_scale=0.1",",","initial_state_prior=tfd.MultivariateNormalDiag","(","scale_diag=tf.fill","(","[","24","]",",","2.0",")",")",",",")","``","`","#","#","#","#","References","[","1","]",":","Harvey",",","A",".","Forecasting",",","Structural","Time","Series","Models","and","the","Kalman","Filter",".","Cambridge",":","Cambridge","University","Press",",","1990","."]
docstr: Multipliers of the fundamental frequency.
docstr_tok: ["Multipliers","of","the","fundamental","frequency","."]
code: def frequency_multipliers(self):
      """Multipliers of the fundamental frequency."""
      return self._frequency_multipliers
  
imports: import numpy
  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.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 5 for calling the SmoothSeasonalStateSpaceModel obj's underlying member method code with example usage: obj.frequency_multipliers() and returns: self