time_series_protocols
Use this library when implementing a time series forecaster or providing
a dataset for one. It defines the protocols that let datasets and
forecasting algorithms work together. Datasets are represented as
objects implementing the time_series_dataset_protocol protocol.
Forecasters are represented as objects importing the
forecaster_common category. This library also provides a category
defining common predicates for dataset validation, differencing and
reconstruction, lag construction, forecast error metrics, naive
baselines, diagnostics metadata, export, and pretty-printing support.
Learned forecasters expose diagnostics using the shared
diagnostics/2, diagnostic/2, and forecaster_options/2
predicates. Concrete forecaster implementations store effective training
options in the diagnostics metadata under an options(Options) term.
Dataset observation indices must form a complete, gap-free, 1-based
sequence. The dataset’s series_length/1 predicate must report a
positive length matching the number of enumerated observations. When
provided, its frequency/1 predicate must report a positive integer;
this is dataset metadata, not a learning option.
Observation indices must be instantiated integers. Variable indices raise an instantiation error; other invalid index sequences raise a domain error. Collection sorts observations and validates their indices without instantiating them or removing duplicates.
Forecast horizons are non-negative integers. A zero horizon produces an empty forecast list. Forecast error metrics require non-empty numeric actual and predicted series of equal length.
This library also provides time series test datasets under the
test_datasets directory.
API documentation
Open the ../../apis/library_index.html#time-series-protocols link in a web browser.
Loading
To load this library, load its loader.lgt file:
| ?- logtalk_load(time_series_protocols(loader)).
Testing
To test this library, load its tester.lgt file:
| ?- logtalk_load(time_series_protocols(tester)).
Test datasets
The test_datasets directory includes the following compact time
series datasets and validation fixtures:
gap_index.lgt: invalid dataset fixture containing a gap in the observation index sequence (index 3 is missing).inconsistent_series_length.lgt: invalid dataset fixture whose declared series length differs from its number of observations.linear_trend.lgt: simple non-seasonal series following the linevalue = 2*index + 8(values 10, 12, 14, 16, 18, 20).malformed_series_lengths.lgt: invalid dataset fixtures declaring zero and non-integer series lengths.malformed_series_indices.lgt: fixed malformed-index and variable-length cases, plus valid singleton and out-of-order controls with missing observations.non_numeric_value.lgt: invalid dataset fixture containing a non-numeric observation value.seasonal_series.lgt: two repetitions of a length-4 seasonal cycle (10, 20, 15, 5) with a declaredfrequency/1of 4.short_series.lgt: two-observation series, too short for most forecaster minimum-length checks.
Seasonal preprocessing
Seasonal predicates accept numbers and anonymous variables representing
missing observations. The autocorrelation test uses the mean-centered
available-pair biased autocorrelations up to the supplied seasonal lag
and the standard Theta cutoff 1.6448536269514722. Constant data,
frequency one, series with at most two elapsed cycles or 2*Frequency
known values, and any tested lag with fewer than two known pairs are
nonseasonal. The mean and variance use known values, covariance sums
skip unavailable pairs at original lags, and the test statistic uses the
known count. This missing-data extension is a conservative heuristic,
not a calibrated significance guarantee for arbitrary gaps. Its direct
lag calculation costs O(N*Frequency).
Classical seasonal adjustment requires frequency at least two and at
least two elapsed cycles. It uses only full centered moving-average
windows with no missing observations, including the two-by-frequency
filter for even periods, followed by phase means of interior differences
or ratios. Factors are normalized to zero mean for additive adjustment
or unit mean for multiplicative adjustment. For each seasonal phase, at
least one known observation must have a trend estimate calculated from
such a window; otherwise the lowest unestimable phase raises
domain_error(insufficient_seasonal_phase_observations, Phase).
Windows containing missing observations are discarded, not renormalized
or interpolated. Known values, including endpoints, are adjusted and
missing values remain unbound. Multiplicative known observations, valid
trends and factors must be positive. Rolling window sums and cycle-wise
phase totals cost O(N+Frequency).
Restoration uses an explicit 1-based start phase and cycles factors in input order, advancing phase through missing positions without binding them. It validates the phase and factors even when the values list is empty. These predicates do not interpolate missing values, mutate input data or silently replace failed seasonal decompositions.
Limitations
This library supplies interfaces and reusable auxiliary predicates, not
a standalone forecasting algorithm. A concrete forecaster must implement
learning and forecast construction. The forecaster_protocol protocol
does not declare online updates, fitted-value extraction, or prediction
intervals; check the chosen implementation for those capabilities and
their options.
The dataset interface describes one series of numeric observations at
complete, gap-free, 1-based positions. It has no timestamp,
multivariate, or exogenous-variable interface, and does not resample
irregular data. Represent an unknown observation by an unbound value at
its original position, not by omitting that position. The
dataset_series/2 predicate collects and sorts the entire dataset in
memory; it is not a streaming dataset reader.
Missing-value support depends on the predicate. The check_series/2
predicate, the difference_series/2 predicate, and the numeric
error-metric predicates require known numeric values. Missing-aware
predicates preserve gaps but do not impute them. A concrete forecaster
remains responsible for its missing policy, minimum usable sample,
numerical checks, and model-specific diagnostic consistency.
Seasonal predicates use a single supplied integer period; they do not estimate frequency or model multiple seasonal cycles. Sparse gaps can leave too few lag pairs or complete centered windows to detect or estimate seasonality. The missing-data autocorrelation test is a heuristic, not a calibrated significance test for arbitrary gaps. Multiplicative adjustment requires positive known values, trends, and factors; failed decompositions are not silently replaced with a nonseasonal fit.