Binomial Filter

The BinomialFilter is a KalmanFilter with (1) one or more sigmoid measurement-functions and (2) with a log_prob that use binomial likelihood (using monte-carlo approximation).

class torchcast.kalman_filter.binomial_filter.BinomialFilter(processes: Sequence[Process], measures: Sequence[str] | None, binary_measures: Sequence[str] | None = None, observed_counts: bool | None = None, do_post_hoc_correction: Literal['none', 'static', 'num_obs', 'auto'] = 'auto', measure_covariance: Covariance | dict | None = None, process_covariance: Covariance | None = None, initial_covariance: Covariance | None = None, adaptive_scaling: bool = False, joseph_form: bool = True, mixture: MixtureModel | Sequence[MixtureComponent] | None = None)

Bases: KalmanFilter

Parameters:
  • processes – A list of Process modules.

  • measures – A list of strings specifying the names of the dimensions of the time-series being measured.

  • binary_measures – A subset of measures with binary (binomial) outcomes.

  • observed_counts – If True, then y is interpreted as counts; if False then as probabilities 0-1.

  • do_post_hoc_correction – BinomialFilter uses the EKF approximation, which isn’t terribly accurate for binomial data, especially when num_obs is low. This option allows the module to apply a correction factor for the filter, learned from the data. If ‘static’, then a single correction-factor is applied to all data; if ‘num_obs’, it changes with log(num_obs) (a learned slope, only use if num_obs varies in your data); if ‘auto’ (the default), then ‘static’ or ‘num_obs’ will be chosen at fit time, depending on whether the provided data has varying num_obs; if 'none' then no correction.

  • measure_covariance – A module created with Covariance.from_measures(measures).

  • process_covariance – A module created with Covariance.from_processes(processes, type='process').

  • initial_covariance – A module created with Covariance.from_processes(measures, type='initial').

  • adaptive_scaling – Experimental feature to adaptively scale the covariance as a function of residuals. This is useful if different groups have very different magnitudes.

  • joseph_form – See KalmanFilter. (Binary measures whose probability is near 0 or 1 have a small variance, which makes the update less well-conditioned – where the Joseph form helps most.)

  • mixture – Experimental. See KalmanFilter. Only supported for non-binary measures.

fit(y: Tensor, **kwargs) → BinomialFilter

See StateSpaceModel.fit(). With do_post_hoc_correction='auto', this first chooses 'static' or 'num_obs' from the num_obs passed here ('num_obs' only if it varies), before creating the optimizer.