object

intermittent_demand_forecasting

Croston, SBA, and TSB intermittent-demand forecasters with causal initialization, configurable missing observations, and immutable online updates.

Availability:
logtalk_load(intermittent_demand_forecasting(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-10-14
Compilation flags:
static, context_switching_calls
Imports:
Uses:
Remarks:
(none)

Public predicates

fitted_values/2

Returns aligned one-step fitted values for Dataset using default options.

Compilation flags:
static
Template:
fitted_values(Dataset,Values)
Mode and number of proofs:
fitted_values(+object_identifier,-list) - one_or_error
Exceptions:
An observation index or the declared series length is a variable:
instantiation_error
The declared series length is not an integer:
type_error(integer,DeclaredLength)
The declared series length is not positive:
domain_error(positive_integer,DeclaredLength)
The dataset contains no observations:
domain_error(non_empty_series,Dataset)
The indices are not a gap-free 1-based sequence:
domain_error(series_index_sequence,Dataset)
The declared and observed lengths differ:
consistency_error(series_length,DeclaredLength,ObservedLength)
An observation is neither a variable nor a number:
type_error(number,Observation)
An observation is negative:
domain_error(non_negative_number,Observation)
All observations are missing:
domain_error(insufficient_observations,Dataset)
Fitting, error-total, or replay arithmetic raises an evaluation error:
evaluation_error(Error)

fitted_values/3

Returns aligned one-step fitted values for Dataset using the specified Options.

Compilation flags:
static
Template:
fitted_values(Dataset,Values,Options)
Mode and number of proofs:
fitted_values(+object_identifier,-list,+list(compound)) - one_or_error
Exceptions:
An observation index or the declared series length is a variable:
instantiation_error
Options is a variable:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is a variable:
instantiation_error
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)
The declared series length is not an integer:
type_error(integer,DeclaredLength)
The declared series length is not positive:
domain_error(positive_integer,DeclaredLength)
The dataset contains no observations:
domain_error(non_empty_series,Dataset)
The indices are not a gap-free 1-based sequence:
domain_error(series_index_sequence,Dataset)
The declared and observed lengths differ:
consistency_error(series_length,DeclaredLength,ObservedLength)
An observation is neither a variable nor a number:
type_error(number,Observation)
An observation is negative:
domain_error(non_negative_number,Observation)
All observations are missing:
domain_error(insufficient_observations,Dataset)
Fitting, error-total, or replay arithmetic raises an evaluation error:
evaluation_error(Error)

update/3

Returns a new forecaster incorporating Observation without modifying Forecaster.

Compilation flags:
static
Template:
update(Forecaster,Observation,UpdatedForecaster)
Mode and number of proofs:
update(+compound,@term,-compound) - one_or_error
Exceptions:
Forecaster is a variable:
instantiation_error
Forecaster is not a valid intermittent-demand forecaster:
domain_error(forecaster,Forecaster)
Observation is neither a variable nor a number:
type_error(number,Observation)
Observation is negative:
domain_error(non_negative_number,Observation)
Update, error-total, or diagnostic validation arithmetic raises an evaluation error:
evaluation_error(Error)

Protected predicates

(no local declarations; see entity ancestors if any)

Private predicates

replay_series/5

Replays an already validated series using a concrete method, validated parameters, and valid starting state. Emits pre-observation predictions for numeric targets and fresh placeholders for missing targets, preserving order and all input variables.

Compilation flags:
static
Template:
replay_series(Series,Method,Parameters,State,Values)
Mode and number of proofs:
replay_series(@list,+atom,+compound,+compound,-list) - one_or_error
Exceptions:
Prediction or transition arithmetic raises an evaluation error:
evaluation_error(Error)

prepare_learning/4

Collects and validates once, fits all requested configurations using exact RMSE priority, and optionally returns aligned predictions without retaining history in the model.

Compilation flags:
static
Template:
prepare_learning(Dataset,Forecaster,Options,Output)
Mode and number of proofs:
prepare_learning(+object_identifier,-compound,+list(compound),+compound) - one_or_error
Exceptions:
An observation index or the declared series length is a variable:
instantiation_error
Options is a variable:
instantiation_error
Options is neither a variable nor a list:
type_error(list,Options)
An element Option of the list Options is a variable:
instantiation_error
An element Option of the list Options is neither a variable nor a compound term:
type_error(compound,Option)
An element Option of the list Options is a compound term but not a valid option:
domain_error(option,Option)
The declared series length is not an integer:
type_error(integer,DeclaredLength)
The declared series length is not positive:
domain_error(positive_integer,DeclaredLength)
The dataset contains no observations:
domain_error(non_empty_series,Dataset)
The indices are not a gap-free 1-based sequence:
domain_error(series_index_sequence,Dataset)
The declared and observed lengths differ:
consistency_error(series_length,DeclaredLength,ObservedLength)
An observation is neither a variable nor a number:
type_error(number,Observation)
An observation is negative:
domain_error(non_negative_number,Observation)
All observations are missing:
domain_error(insufficient_observations,Dataset)
Learning or error-total arithmetic raises an evaluation error:
evaluation_error(Error)

normalize_coefficient_grid/2

Normalizes a validated nonempty coefficient grid to ascending distinct floats without modifying the supplied list. Integer 1 and float 1.0 become one candidate. No comparison tolerance is used.

Compilation flags:
static
Template:
normalize_coefficient_grid(Grid,NormalizedGrid)
Mode and number of proofs:
normalize_coefficient_grid(+list(number),-list(float)) - one_or_error
Exceptions:
Coefficient conversion raises an evaluation error:
evaluation_error(Error)

select_methods/7

Evaluates every method while retaining only the best concrete fit.

Compilation flags:
static
Template:
select_methods(Methods,Alphas,Betas,Series,Policy,PreviousBest,Best)
Mode and number of proofs:
select_methods(+list,+list,+list,@list,+atom,+term,-compound) - one_or_error
Exceptions:
Candidate arithmetic raises an evaluation error:
evaluation_error(Error)

select_alphas/7

Evaluates each size coefficient for a concrete method.

Compilation flags:
static
Template:
select_alphas(Alphas,Method,Betas,Series,Policy,PreviousBest,Best)
Mode and number of proofs:
select_alphas(+list,+atom,+list,@list,+atom,+term,-compound) - one_or_error
Exceptions:
Candidate arithmetic raises an evaluation error:
evaluation_error(Error)

select_betas/7

Fits every occurrence coefficient without suppressing losing-candidate errors.

Compilation flags:
static
Template:
select_betas(Betas,Method,Alpha,Series,Policy,PreviousBest,Best)
Mode and number of proofs:
select_betas(+list,+atom,+number,@list,+atom,+term,-compound) - one_or_error
Exceptions:
Candidate arithmetic raises an evaluation error:
evaluation_error(Error)

fit_paired_series/4

Fits SBA and Croston with shared transitions and independent error totals and metrics.

Compilation flags:
static
Template:
fit_paired_series(Series,Parameters,SBA,Croston)
Mode and number of proofs:
fit_paired_series(@list,+compound,-compound,-compound) - one_or_error
Exceptions:
Transition or scoring arithmetic raises an evaluation error:
evaluation_error(Error)

learn_pair/4

Advances one shared Croston state and two causal error streams.

Compilation flags:
static
Template:
learn_pair(Series,Parameters,Accumulator,Result)
Mode and number of proofs:
learn_pair(@list,+compound,+compound,-compound) - one_or_error
Exceptions:
Transition or scoring arithmetic raises an evaluation error:
evaluation_error(Error)

paired_predictions/4

Computes both method predictions from one rate, retaining integer cold-start zeros.

Compilation flags:
static
Template:
paired_predictions(State,Parameters,SBA,Croston)
Mode and number of proofs:
paired_predictions(+compound,+compound,-number,-number) - one_or_error
Exceptions:
Prediction arithmetic raises an evaluation error:
evaluation_error(Error)

better_candidate/3

Chooses the lower rounded RMSE, breaking exact ties by method, alpha, and beta priority.

Compilation flags:
static
Template:
better_candidate(Candidate,PreviousBest,Best)
Mode and number of proofs:
better_candidate(+compound,+term,-compound) - one

candidate_key/2

Returns the exact RMSE and deterministic method/coefficient priority key.

Compilation flags:
static
Template:
candidate_key(Candidate,Key)
Mode and number of proofs:
candidate_key(+compound,-compound) - one

method_priority/2

Returns the priority of a validated concrete method.

Compilation flags:
static
Template:
method_priority(Method,Priority)
Mode and number of proofs:
method_priority(+atom,-integer) - one

fit_series/4

Fits a validated series, retaining terminal state and error metrics without constructing public diagnostics.

Compilation flags:
static
Template:
fit_series(Series,Method,Parameters,Fit)
Mode and number of proofs:
fit_series(@list,+atom,+compound,-compound) - one_or_error
Exceptions:
Fitting or metric arithmetic raises an evaluation error:
evaluation_error(Error)

fit_series_output/5

Fits and scores a validated series, optionally emitting pre-observation predictions in the same traversal.

Compilation flags:
static
Template:
fit_series_output(Series,Method,Parameters,Output,Fit)
Mode and number of proofs:
fit_series_output(@list,+atom,+compound,+term,-compound) - one_or_error
Exceptions:
Fitting or metric arithmetic raises an evaluation error:
evaluation_error(Error)

fitted_model/3

Builds canonical public diagnostics once from the winning fit and validated observation summary.

Compilation flags:
static
Template:
fitted_model(Summary,Fit,Forecaster)
Mode and number of proofs:
fitted_model(+compound,+compound,-compound) - one_or_error
Exceptions:
Counter arithmetic raises an evaluation error:
evaluation_error(Error)

learn_state/6

Advances causal state and error totals with optional aligned prediction output.

Compilation flags:
static
Template:
learn_state(Series,Method,Parameters,Accumulator,Result,Output)
Mode and number of proofs:
learn_state(@list,+atom,+compound,+compound,-compound,+term) - one_or_error
Exceptions:
Prediction, transition, or scoring arithmetic raises an evaluation error:
evaluation_error(Error)

score_observation/7

Scores a validated numeric target or preserves totals and a fresh prediction placeholder for a missing target.

Compilation flags:
static
Template:
score_observation(Method,State,Parameters,Observation,PreviousTotals,Totals,Prediction)
Mode and number of proofs:
score_observation(+atom,+compound,+compound,@term,+compound,-compound,-term) - one_or_error
Exceptions:
Prediction or scoring arithmetic raises an evaluation error:
evaluation_error(Error)

demand_summary/3

Validates demands and summarizes elapsed, observed, and positive counts without binding missing values.

Compilation flags:
static
Template:
demand_summary(Series,Accumulator,Summary)
Mode and number of proofs:
demand_summary(@list,+compound,-compound) - one_or_error
Exceptions:
An observation is not a number or variable:
type_error(number,Observation)
An observation is negative:
domain_error(non_negative_number,Observation)
Counter arithmetic raises an evaluation error:
evaluation_error(Error)

prepare_parameters/4

Prepares validated coefficients, their complements, and the SBA correction for a fitting pass or public operation.

Compilation flags:
static
Template:
prepare_parameters(Alpha,Beta,Policy,Parameters)
Mode and number of proofs:
prepare_parameters(+number,+number,+atom,-compound) - one_or_error
Exceptions:
Coefficient arithmetic raises an evaluation error:
evaluation_error(Error)

positive_smoothing/4

Smooths positive endpoints using their minimum plus a weighted difference, avoiding independent product underflow.

Compilation flags:
static
Template:
positive_smoothing(Weight,Observation,Previous,Smoothed)
Mode and number of proofs:
positive_smoothing(+compound,+number,+number,-number) - one_or_error
Exceptions:
Smoothing arithmetic raises an evaluation error:
evaluation_error(Error)

checked_forecaster/2

Validates a model and returns its extracted fields for reuse by public operations.

Compilation flags:
static
Template:
checked_forecaster(Forecaster,Data)
Mode and number of proofs:
checked_forecaster(@term,-compound) - one_or_error
Exceptions:
Forecaster is a variable:
instantiation_error
Forecaster is invalid:
domain_error(forecaster,Forecaster)
Validation arithmetic raises an evaluation error:
evaluation_error(Error)

valid_diagnostics/4

Extracts required fields once and validates options, counters, metrics, and state.

Compilation flags:
static
Template:
valid_diagnostics(Method,State,Diagnostics,Data)
Mode and number of proofs:
valid_diagnostics(+atom,+compound,+list,-compound) - zero_or_one_or_error
Exceptions:
Validation arithmetic raises an evaluation error:
evaluation_error(Error)

extract_diagnostics/2

Extracts ground diagnostic fields, rejecting malformed arities and duplicate error metrics.

Compilation flags:
static
Template:
extract_diagnostics(Diagnostics,Data)
Mode and number of proofs:
extract_diagnostics(+list,+compound) - zero_or_one

rewrite_diagnostics/4

Rebuilds diagnostic values in one traversal, preserving order, extra metadata, and later common-field occurrences.

Compilation flags:
static
Template:
rewrite_diagnostics(Diagnostics,Data,Seen,UpdatedDiagnostics)
Mode and number of proofs:
rewrite_diagnostics(+list,+compound,+non_negative_integer,-list) - one

diagnostic_position/2

Maps required diagnostic names to their compact field positions.

Compilation flags:
static
Template:
diagnostic_position(Name,Position)
Mode and number of proofs:
diagnostic_position(+atom,-positive_integer) - zero_or_one

valid_error_metrics/5

Checks numeric error totals and exact consistency of their derived metrics.

Compilation flags:
static
Template:
valid_error_metrics(Count,Absolute,Squared,MAE,RMSE)
Mode and number of proofs:
valid_error_metrics(+positive_integer,@term,@term,@term,@term) - zero_or_one_or_error
Exceptions:
Metric arithmetic raises an evaluation error:
evaluation_error(Error)

Operators

(none)