class_docstr: State space model for an autoregressive process.
  
  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.
  
  In an autoregressive process, the expected level at each timestep is a linear
  function of previous levels, with added Gaussian noise:
  
  ```python
  level[t+1] = (sum(coefficients * levels[t:t-order:-1]) +
                Normal(0., level_scale))
  ```
  
  The process is characterized by a vector `coefficients` whose size determines
  the order of the process (how many previous values it looks at), and by
  `level_scale`, the standard deviation of the noise added at each step.
  
  This is formulated as a state space model by letting the latent state encode
  the most recent values; see 'Mathematical Details' below.
  
  The parameters `level_scale` and `observation_noise_scale` are each (a batch
  of) scalars, and `coefficients` is a (batch) vector of size `[order]`. The
  batch shape of this `Distribution` is the broadcast batch
  shape of these parameters and of the `initial_state_prior`.
  
  #### Mathematical Details
  
  The autoregressive model implements a
  `tfp.distributions.LinearGaussianStateSpaceModel` with `latent_size = order`
  and `observation_size = 1`. The latent state vector encodes the recent history
  of the process, with the current value in the topmost dimension. At each
  timestep, the transition sums the previous values to produce the new expected
  value, shifts all other values down by a dimension, and adds noise to the
  current value. This is formally encoded by the transition model:
  
  ```
  transition_matrix = [ coefs[0], coefs[1], ..., coefs[order]
                        1.,       0 ,       ..., 0.
                        0.,       1.,       ..., 0.
                        ...
                        0.,       0.,  ...,  1.,  0.            ]
  transition_noise ~ N(loc=0., scale=diag([level_scale, 0., 0., ..., 0.]))
  ```
  
  The observation model simply extracts the current (topmost) value, and
  optionally adds independent noise at each step:
  
  ```
  observation_matrix = [[1., 0., ..., 0.]]
  observation_noise ~ N(loc=0, scale=observation_noise_scale)
  ```
  
  Models with `observation_noise_scale = 0.` are AR processes in the formal
  sense. Setting `observation_noise_scale` to a nonzero value corresponds to a
  latent AR process observed under an iid noise model.
  
  #### Examples
  
  A simple model definition:
  
  ```python
  ar_model = AutoregressiveStateSpaceModel(
      num_timesteps=50,
      coefficients=[0.8, -0.1],
      level_scale=0.5,
      initial_state_prior=tfd.MultivariateNormalDiag(
        scale_diag=[1., 1.]))
  
  y = ar_model.sample() # y has shape [50, 1]
  lp = ar_model.log_prob(y) # log_prob is scalar
  ```
  
  Passing additional parameter dimensions constructs a batch of models. The
  overall batch shape is the broadcast batch shape of the parameters:
  
  ```python
  ar_model = AutoregressiveStateSpaceModel(
      num_timesteps=50,
      coefficients=[0.8, -0.1],
      level_scale=tf.ones([10]),
      initial_state_prior=tfd.MultivariateNormalDiag(
        scale_diag=tf.ones([10, 10, 2])))
  
  y = ar_model.sample(5) # y has shape [5, 10, 10, 50, 1]
  lp = ar_model.log_prob(y) # has shape [5, 10, 10]
  ```
class_docstr_tok: ["State","space","model","for","an","autoregressive","process",".","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",".","In","an","autoregressive","process",",","the","expected","level","at","each","timestep","is","a","linear","function","of","previous","levels",",","with","added","Gaussian","noise",":","``","`","python","level","[","t+1","]","=","(","sum","(","coefficients","*","levels","[","t",":","t-order",":","-1","]",")","+","Normal","(","0.",",","level_scale",")",")","``","`","The","process","is","characterized","by","a","vector","`","coefficients","`","whose","size","determines","the","order","of","the","process","(","how","many","previous","values","it","looks","at",")",",","and","by","`","level_scale","`",",","the","standard","deviation","of","the","noise","added","at","each","step",".","This","is","formulated","as","a","state","space","model","by","letting","the","latent","state","encode","the","most","recent","values",";","see","'Mathematical","Details","'","below",".","The","parameters","`","level_scale","`","and","`","observation_noise_scale","`","are","each","(","a","batch","of",")","scalars",",","and","`","coefficients","`","is","a","(","batch",")","vector","of","size","`","[","order","]","`",".","The","batch","shape","of","this","`","Distribution","`","is","the","broadcast","batch","shape","of","these","parameters","and","of","the","`","initial_state_prior","`",".","#","#","#","#","Mathematical","Details","The","autoregressive","model","implements","a","`","tfp.distributions.LinearGaussianStateSpaceModel","`","with","`","latent_size","=","order","`","and","`","observation_size","=","1","`",".","The","latent","state","vector","encodes","the","recent","history","of","the","process",",","with","the","current","value","in","the","topmost","dimension",".","At","each","timestep",",","the","transition","sums","the","previous","values","to","produce","the","new","expected","value",",","shifts","all","other","values","down","by","a","dimension",",","and","adds","noise","to","the","current","value",".","This","is","formally","encoded","by","the","transition","model",":","``","`","transition_matrix","=","[","coefs","[","0","]",",","coefs","[","1","]",",","...",",","coefs","[","order","]","1.",",","0",",","...",",","0",".","0.",",","1.",",","...",",","0",".","...","0.",",","0.",",","...",",","1.",",","0",".","]","transition_noise","~","N","(","loc=0.",",","scale=diag","(","[","level_scale",",","0.",",","0.",",","...",",","0",".","]",")",")","``","`","The","observation","model","simply","extracts","the","current","(","topmost",")","value",",","and","optionally","adds","independent","noise","at","each","step",":","``","`","observation_matrix","=","[","[","1.",",","0.",",","...",",","0",".","]","]","observation_noise","~","N","(","loc=0",",","scale=observation_noise_scale",")","``","`","Models","with","`","observation_noise_scale","=","0.","`","are","AR","processes","in","the","formal","sense",".","Setting","`","observation_noise_scale","`","to","a","nonzero","value","corresponds","to","a","latent","AR","process","observed","under","an","iid","noise","model",".","#","#","#","#","Examples","A","simple","model","definition",":","``","`","python","ar_model","=","AutoregressiveStateSpaceModel","(","num_timesteps=50",",","coefficients=","[","0.8",",","-0.1","]",",","level_scale=0.5",",","initial_state_prior=tfd.MultivariateNormalDiag","(","scale_diag=","[","1.",",","1",".","]",")",")","y","=","ar_model.sample","(",")","#","y","has","shape","[","50",",","1","]","lp","=","ar_model.log_prob","(","y",")","#","log_prob","is","scalar","``","`","Passing","additional","parameter","dimensions","constructs","a","batch","of","models",".","The","overall","batch","shape","is","the","broadcast","batch","shape","of","the","parameters",":","``","`","python","ar_model","=","AutoregressiveStateSpaceModel","(","num_timesteps=50",",","coefficients=","[","0.8",",","-0.1","]",",","level_scale=tf.ones","(","[","10","]",")",",","initial_state_prior=tfd.MultivariateNormalDiag","(","scale_diag=tf.ones","(","[","10",",","10",",","2","]",")",")",")","y","=","ar_model.sample","(","5",")","#","y","has","shape","[","5",",","10",",","10",",","50",",","1","]","lp","=","ar_model.log_prob","(","y",")","#","has","shape","[","5",",","10",",","10","]","``","`"]
code: def level_scale(self):
      return self._level_scale
  
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.bijectors import tanh
  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 distribution_util
  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 4 for calling the AutoregressiveStateSpaceModel obj's underlying member method code with example usage: obj.level_scale() and returns: self