Processes

Process modules are used to specify the latent-states (and their temporal dynamics) underlying your time-series(es):

  • LocalLevel - a random-walk.

  • LocalTrend - a random-walk with (optionally damped) velocity.

  • Season - a process with seasonal structure, implementing the fourier-series based model from De Livera, A.M., Hyndman, R.J., & Snyder, R. D. (2011).

  • LinearModel - a linear-model allowing for external predictors.


class torchcast.process.LinearModel(id: str, predictors: Sequence[str], measure: str | None = None, fixed: bool = True, decay: Tuple[float, float] | None = None, model_mat_kwarg_name: str = 'X')

A process which takes a model-matrix of predictors, and each state corresponds to the coefficient on each.

Parameters:
  • id – Unique identifier for the process

  • predictors – A sequence of strings with predictor-names.

  • measure – The name of the measure for this process.

  • fixed – By default, the regression-coefficients are assumed to be fixed: we are initially uncertain about their value at the start of each series, but we gradually grow more confident. If fixed=False then we continue to inject uncertainty at each timestep so that uncertainty asymptotes at some nonzero value. This amounts to dynamic-regression where the coefficients evolve over-time. Note only KalmanFilter (but not ExpSmoother) supports this.

  • decay – By default, the coefficient-values will remain as the forecast horizon increases. An alternative is to allow these to decay (i.e. pass True). If you’d like more fine-grained control over this decay, you can specify the min/max decay as a tuple (passing True uses a default value of (.98, 1.0)).

class torchcast.process.LocalLevel(id: str, measure: str | None = None, decay: Module | Tuple[float, float] | None = None)

A process representing a random-walk.

Parameters:
  • id – A unique identifier for this process.

  • decay – If the process has decay, then the random walk will tend towards zero as we forecast out further (note that this means you should center your time-series, or you should include another process that does not have this decaying behavior). Decay can be between 0 and 1, but values < .50 (or even .90) can often be too rapid and you will run into trouble with vanishing gradients. When passing a pair of floats, the nn.Module will assign a parameter representing the decay as a learned parameter somewhere between these bounds.

class torchcast.process.LocalTrend(id: str, measure: str | None = None, decay_velocity: Module | Tuple[float, float] | None = (0.95, 1.0), decay_position: Module | Tuple[float, float] | None = None, velocity_multi: float = 0.1)

A process representing an evolving trend.

Parameters:
  • id – A unique identifier for this process.

  • decay_velocity – If set, then the trend will decay to zero as we forecast out further. The default is to allow the trend to decay somewhere between .95 (moderate decay) and 1.00 (no decay), with the exact value being a learned parameter.

  • decay_position – See decay in LocalLevel. Default is no decay.

  • velocity_multi – Default 0.1. A multiplier on the velocity, so that next_position = position + velocity_multi * velocity. A value of << 1.0 can be helpful since the trend has such a large effect on the prediction, so that large values can lead to exploding predictions.

class torchcast.process.Season(id: str, period: float | str, dt_unit: str | None, K: int, measure: str | None = None, fixed: bool = False, decay: Tuple[float, float] | None = None)

Method from De Livera, A.M., Hyndman, R.J., & Snyder, R. D. (2011), specifically the novel approach to modeling seasonality that they proposed.

Parameters:
  • id – Unique identifier for this process.

  • dt_unit – A numpy.timedelta64 (or string that will be converted to one) that indicates the time-units used in the kalman-filter – i.e., how far we advance with every timestep. Can be None if the data are in arbitrary (non-datetime) units.

  • period – The number of timesteps it takes to get through a full seasonal cycle. Does not have to be an integer (e.g. 365.25 for yearly to account for leap-years). Can also be a numpy.timedelta64 (or string that will be converted to one).

  • K – The number of the fourier components.

  • measure – The name of the measure for this process.

  • fixed – Whether the seasonal-structure is allowed to evolve over time, or is fixed (default: fixed=False). Setting this to True can be helpful for limiting the uncertainty of long-range forecasts.

  • decay – By default, the seasonal structure will remain as the forecast horizon increases. An alternative is to allow this structure to decay (i.e. pass True). If you’d like more fine-grained control over this decay, you can specify the min/max decay as a tuple (passing True uses a default value of (.98, 1.0)).