class_docstr: Base class for structural time series models.
  
  A StructuralTimeSeries object represents a declarative specification of a
  structural time series model, including priors on model parameters.
  It implements a joint probability model
    `p(params, y) = p(params) p(y | params)`,
  where `params` denotes a list of real-valued parameters specified by the child
  class, and `p(y | params)` is a linear Gaussian state space model with
  structure determined by the child class.
class_docstr_tok: ["Base","class","for","structural","time","series","models",".","A","StructuralTimeSeries","object","represents","a","declarative","specification","of","a","structural","time","series","model",",","including","priors","on","model","parameters",".","It","implements","a","joint","probability","model","`","p","(","params",",","y",")","=","p","(","params",")","p","(","y","|","params",")","`",",","where","`","params","`","denotes","a","list","of","real-valued","parameters","specified","by","the","child","class",",","and","`","p","(","y","|","params",")","`","is","a","linear","Gaussian","state","space","model","with","structure","determined","by","the","child","class","."]
docstr: Build the joint density `log p(params) + log p(y|params)` as a callable.
  
  Args:
    observed_time_series: Observed `Tensor` trajectories of shape
      `sample_shape + batch_shape + [num_timesteps, 1]` (the trailing
      `1` dimension is optional if `num_timesteps > 1`), where
      `batch_shape` should match `self.batch_shape` (the broadcast batch
      shape of all priors on parameters for this structural time series
      model). Any `NaN`s are interpreted as missing observations; missingness
      may be also be explicitly specified by passing a
      `tfp.sts.MaskedTimeSeries` instance.
  
  Returns:
   log_joint_fn: A function taking a `Tensor` argument for each model
     parameter, in canonical order, and returning a `Tensor` log probability
     of shape `batch_shape`. Note that, *unlike* `tfp.Distributions`
     `log_prob` methods, the `log_joint` sums over the `sample_shape` from y,
     so that `sample_shape` does not appear in the output log_prob. This
     corresponds to viewing multiple samples in `y` as iid observations from a
     single model, which is typically the desired behavior for parameter
     inference.
docstr_tok: ["Build","the","joint","density","`","log","p","(","params",")","+","log","p","(","y|params",")","`","as","a","callable",".","Args",":","observed_time_series",":","Observed","`","Tensor","`","trajectories","of","shape","`","sample_shape","+","batch_shape","+","[","num_timesteps",",","1","]","`","(","the","trailing","`","1","`","dimension","is","optional","if","`","num_timesteps",">","1","`",")",",","where","`","batch_shape","`","should","match","`","self.batch_shape","`","(","the","broadcast","batch","shape","of","all","priors","on","parameters","for","this","structural","time","series","model",")",".","Any","`","NaN","`","s","are","interpreted","as","missing","observations",";","missingness","may","be","also","be","explicitly","specified","by","passing","a","`","tfp.sts.MaskedTimeSeries","`","instance",".","Returns",":","log_joint_fn",":","A","function","taking","a","`","Tensor","`","argument","for","each","model","parameter",",","in","canonical","order",",","and","returning","a","`","Tensor","`","log","probability","of","shape","`","batch_shape","`",".","Note","that",",","*","unlike","*","`","tfp.Distributions","`","`","log_prob","`","methods",",","the","`","log_joint","`","sums","over","the","`","sample_shape","`","from","y",",","so","that","`","sample_shape","`","does","not","appear","in","the","output","log_prob",".","This","corresponds","to","viewing","multiple","samples","in","`","y","`","as","iid","observations","from","a","single","model",",","which","is","typically","the","desired","behavior","for","parameter","inference","."]
code: def joint_log_prob(self, observed_time_series):
      """Build the joint density `log p(params) + log p(y|params)` as a callable.
  
      Args:
        observed_time_series: Observed `Tensor` trajectories of shape
          `sample_shape + batch_shape + [num_timesteps, 1]` (the trailing
          `1` dimension is optional if `num_timesteps > 1`), where
          `batch_shape` should match `self.batch_shape` (the broadcast batch
          shape of all priors on parameters for this structural time series
          model). Any `NaN`s are interpreted as missing observations; missingness
          may be also be explicitly specified by passing a
          `tfp.sts.MaskedTimeSeries` instance.
  
      Returns:
       log_joint_fn: A function taking a `Tensor` argument for each model
         parameter, in canonical order, and returning a `Tensor` log probability
         of shape `batch_shape`. Note that, *unlike* `tfp.Distributions`
         `log_prob` methods, the `log_joint` sums over the `sample_shape` from y,
         so that `sample_shape` does not appear in the output log_prob. This
         corresponds to viewing multiple samples in `y` as iid observations from a
         single model, which is typically the desired behavior for parameter
         inference.
      """
      with tf.name_scope("joint_log_prob"):
          [
              observed_time_series,
              mask,
          ] = sts_util.canonicalize_observed_time_series_with_mask(
              observed_time_series
          )
  
          num_timesteps = ps.shape(observed_time_series)[-2]
          parameter_prior = self._joint_prior_distribution()
  
          def log_joint_fn(*param_vals, **param_kwargs):
              """Generated log-density function."""
  
              if param_kwargs:
                  if param_vals:
                      raise ValueError(
                          "log_joint_fn saw both positional args ({}) and named args ({}). "
                          "This is not supported: you have to choose!".format(
                              param_vals, param_kwargs
                          )
                      )
                  param_vals = [
                      param_kwargs[p.name] for p in self.parameters
                  ]
  
              param_lp = parameter_prior.log_prob(*param_vals)
  
              # Build a linear Gaussian state space model and evaluate the marginal
              # log_prob on observations.
              lgssm = self.make_state_space_model(
                  param_vals=param_vals, num_timesteps=num_timesteps
              )
              observation_lp = lgssm.log_prob(
                  observed_time_series, mask=mask
              )
  
              # Sum over likelihoods from iid observations. Without this sum,
              # adding `param_lp + observation_lp` would broadcast the param priors
              # over the sample shape, which incorrectly multi-counts the param
              # priors.
              sample_ndims = ps.maximum(
                  0, ps.rank(observation_lp) - ps.rank(param_lp)
              )
              observation_lp = tf.reduce_sum(
                  observation_lp, axis=ps.range(sample_ndims)
              )
  
              return param_lp + observation_lp
  
      return log_joint_fn
  
imports: import collections
  import types
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import joint_distribution_auto_batched
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.internal import distribution_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.python.util import deprecation
label_desc: Use image node_id 16 for calling the StructuralTimeSeries obj's underlying member method code with example usage: obj.joint_log_prob(observed_time_series) and returns: log_joint_fn, unknown