class_docstr: Formal representation of a linear regression from provided covariates.
  
  This model defines a time series given by a linear combination of
  covariate time series provided in a design matrix:
  
  ```python
  observed_time_series = matmul(design_matrix, weights)
  ```
  
  The design matrix has shape `[num_timesteps, num_features]`. The weights
  are treated as an unknown random variable of size `[num_features]` (both
  components also support batch shape), and are integrated over using the same
  approximate inference tools as other model parameters, i.e., generally HMC or
  variational inference.
  
  This component does not itself include observation noise; it defines a
  deterministic distribution with mass at the point
  `matmul(design_matrix, weights)`. In practice, it should be combined with
  observation noise from another component such as `tfp.sts.Sum`, as
  demonstrated below.
  
  #### Examples
  
  Given `series1`, `series2` as `Tensors` each of shape `[num_timesteps]`
  representing covariate time series, we create a regression model that
  conditions on these covariates:
  
  ```python
  regression = tfp.sts.LinearRegression(
    design_matrix=tf.stack([series1, series2], axis=-1),
    weights_prior=tfd.Normal(loc=0., scale=1.))
  ```
  
  Here we've also demonstrated specifying a custom prior, using an informative
  `Normal(0., 1.)` prior instead of the default weakly-informative prior.
  
  As a more advanced application, we might use the design matrix to encode
  holiday effects. For example, suppose we are modeling data from the month of
  December. We can combine day-of-week seasonality with special effects for
  Christmas Eve (Dec 24), Christmas (Dec 25), and New Year's Eve (Dec 31),
  by constructing a design matrix with indicators for those dates.
  
  ```python
  holiday_indicators = np.zeros([31, 3])
  holiday_indicators[23, 0] = 1  # Christmas Eve
  holiday_indicators[24, 1] = 1  # Christmas Day
  holiday_indicators[30, 2] = 1  # New Year's Eve
  
  holidays = tfp.sts.LinearRegression(design_matrix=holiday_indicators,
                                      name='holidays')
  day_of_week = tfp.sts.Seasonal(num_seasons=7,
                                 observed_time_series=observed_time_series,
                                 name='day_of_week')
  model = tfp.sts.Sum(components=[holidays, seasonal],
                      observed_time_series=observed_time_series)
  ```
  
  Note that the `Sum` component in the above model also incorporates observation
  noise, with prior scale heuristically inferred from `observed_time_series`.
  
  In these examples, we've used a single design matrix, but batching is
  also supported. If the design matrix has batch shape, the default behavior
  constructs weights with matching batch shape, which will fit a separate
  regression for each design matrix. This can be overridden by passing an
  explicit weights prior with appropriate batch shape. For example, if each
  design matrix in a batch contains features with the same semantics
  (e.g., if they represent per-group or per-observation covariates), we might
  choose to share statistical strength by fitting a single weight vector that
  broadcasts across all design matrices:
  
  ```python
  design_matrix = get_batch_of_inputs()
  design_matrix.shape  # => concat([batch_shape, [num_timesteps, num_features]])
  
  # Construct a prior with batch shape `[]` and event shape `[num_features]`,
  # so that it describes a single vector of weights.
  weights_prior = tfd.Independent(
      tfd.StudentT(df=5,
                   loc=tf.zeros([num_features]),
                   scale=tf.ones([num_features])),
      reinterpreted_batch_ndims=1)
  linear_regression = LinearRegression(design_matrix=design_matrix,
                                       weights_prior=weights_prior)
  ```
class_docstr_tok: ["Formal","representation","of","a","linear","regression","from","provided","covariates",".","This","model","defines","a","time","series","given","by","a","linear","combination","of","covariate","time","series","provided","in","a","design","matrix",":","``","`","python","observed_time_series","=","matmul","(","design_matrix",",","weights",")","``","`","The","design","matrix","has","shape","`","[","num_timesteps",",","num_features","]","`",".","The","weights","are","treated","as","an","unknown","random","variable","of","size","`","[","num_features","]","`","(","both","components","also","support","batch","shape",")",",","and","are","integrated","over","using","the","same","approximate","inference","tools","as","other","model","parameters",",","i.e.",",","generally","HMC","or","variational","inference",".","This","component","does","not","itself","include","observation","noise",";","it","defines","a","deterministic","distribution","with","mass","at","the","point","`","matmul","(","design_matrix",",","weights",")","`",".","In","practice",",","it","should","be","combined","with","observation","noise","from","another","component","such","as","`","tfp.sts.Sum","`",",","as","demonstrated","below",".","#","#","#","#","Examples","Given","`","series1","`",",","`","series2","`","as","`","Tensors","`","each","of","shape","`","[","num_timesteps","]","`","representing","covariate","time","series",",","we","create","a","regression","model","that","conditions","on","these","covariates",":","``","`","python","regression","=","tfp.sts.LinearRegression","(","design_matrix=tf.stack","(","[","series1",",","series2","]",",","axis=-1",")",",","weights_prior=tfd.Normal","(","loc=0.",",","scale=1",".",")",")","``","`","Here","we","'ve","also","demonstrated","specifying","a","custom","prior",",","using","an","informative","`","Normal","(","0.",",","1",".",")","`","prior","instead","of","the","default","weakly-informative","prior",".","As","a","more","advanced","application",",","we","might","use","the","design","matrix","to","encode","holiday","effects",".","For","example",",","suppose","we","are","modeling","data","from","the","month","of","December",".","We","can","combine","day-of-week","seasonality","with","special","effects","for","Christmas","Eve","(","Dec","24",")",",","Christmas","(","Dec","25",")",",","and","New","Year","'s","Eve","(","Dec","31",")",",","by","constructing","a","design","matrix","with","indicators","for","those","dates",".","``","`","python","holiday_indicators","=","np.zeros","(","[","31",",","3","]",")","holiday_indicators","[","23",",","0","]","=","1","#","Christmas","Eve","holiday_indicators","[","24",",","1","]","=","1","#","Christmas","Day","holiday_indicators","[","30",",","2","]","=","1","#","New","Year","'s","Eve","holidays","=","tfp.sts.LinearRegression","(","design_matrix=holiday_indicators",",","name='holidays","'",")","day_of_week","=","tfp.sts.Seasonal","(","num_seasons=7",",","observed_time_series=observed_time_series",",","name='day_of_week","'",")","model","=","tfp.sts.Sum","(","components=","[","holidays",",","seasonal","]",",","observed_time_series=observed_time_series",")","``","`","Note","that","the","`","Sum","`","component","in","the","above","model","also","incorporates","observation","noise",",","with","prior","scale","heuristically","inferred","from","`","observed_time_series","`",".","In","these","examples",",","we","'ve","used","a","single","design","matrix",",","but","batching","is","also","supported",".","If","the","design","matrix","has","batch","shape",",","the","default","behavior","constructs","weights","with","matching","batch","shape",",","which","will","fit","a","separate","regression","for","each","design","matrix",".","This","can","be","overridden","by","passing","an","explicit","weights","prior","with","appropriate","batch","shape",".","For","example",",","if","each","design","matrix","in","a","batch","contains","features","with","the","same","semantics","(","e.g.",",","if","they","represent","per-group","or","per-observation","covariates",")",",","we","might","choose","to","share","statistical","strength","by","fitting","a","single","weight","vector","that","broadcasts","across","all","design","matrices",":","``","`","python","design_matrix","=","get_batch_of_inputs","(",")","design_matrix.shape","#","=",">","concat","(","[","batch_shape",",","[","num_timesteps",",","num_features","]","]",")","#","Construct","a","prior","with","batch","shape","`","[","]","`","and","event","shape","`","[","num_features","]","`",",","#","so","that","it","describes","a","single","vector","of","weights",".","weights_prior","=","tfd.Independent","(","tfd.StudentT","(","df=5",",","loc=tf.zeros","(","[","num_features","]",")",",","scale=tf.ones","(","[","num_features","]",")",")",",","reinterpreted_batch_ndims=1",")","linear_regression","=","LinearRegression","(","design_matrix=design_matrix",",","weights_prior=weights_prior",")","``","`"]
code: def _make_state_space_model(
      self,
      num_timesteps,
      param_map,
      initial_state_prior=None,
      **linear_gaussian_ssm_kwargs,
  ):
      # TODO(b/215267145): Automatically ensure that sample dimensions of
      # `weights` do not collide with batch dimensions of `design_matrix`.
      weights = param_map["weights"]  # shape: [B, num_features]
      predicted_timeseries = self.design_matrix.matmul(
          weights[..., tf.newaxis]
      )
      # Move timestep to the first dim (before any batch dimensions).
      predicted_timeseries = distribution_util.move_dimension(
          predicted_timeseries, -2, 0
      )
  
      dtype = self.design_matrix.dtype
  
      # Since this model has `latent_size=0`, the latent prior and
      # transition model are dummy objects (zero-dimensional MVNs).
      dummy_mvndiag = _zero_dimensional_mvndiag(dtype)
      if initial_state_prior is None:
          initial_state_prior = dummy_mvndiag
  
      return linear_gaussian_ssm.LinearGaussianStateSpaceModel(
          num_timesteps=num_timesteps,
          transition_matrix=tf.zeros([0, 0], dtype=dtype),
          transition_noise=dummy_mvndiag,
          observation_matrix=tf.zeros([1, 0], dtype=dtype),
          observation_noise=_observe_timeseries_fn(
              predicted_timeseries
          ),
          initial_state_prior=initial_state_prior,
          **linear_gaussian_ssm_kwargs,
      )
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import inverse_gamma
  from tensorflow_probability.python.distributions import linear_gaussian_ssm
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_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 3 for calling the LinearRegression obj's underlying member method code with example usage: obj._make_state_space_model(num_timesteps, param_map, initial_state_prior) and returns: linear_gaussian_ssm