Operator RLSFilter
The Recursive Least Squares (RLS) is linear regression estimation algorithm that learns to predict a target time series, given inputs.
A linear regression model is estimated from a sequence of provided inputs(covariates) and targets (dependent variables). The fitting is done adaptively by using the recursive least squares (RLS) method. The fitted model can be used to estimate the target (dependent variable), given new unseen inputs (covariates).
The RLSFilter operator takes input in the form of a list of values and produces output in the form of single value or list of values.
Behavior in a consistent region
- The RLSFilter operator is not supported in a consistent region. A warning occurs when you compile your streams processing application.
- The operator cannot be the start of a consistent region. An error occurs when you compile your streams processing application.
Example
use com.teracloud.streams.timeseries.modeling::RLSFilter;
composite RLSMain {
graph
// Read covariates from csv file
// where covariates are two-dimensional independent standard normal random vectors
stream<float64 y,list<float64> x> Covariate = FileSource() {
param
file: "housingstarts.csv";
format: csv;
initDelay: 1f;
}
// Insert a punctuation every 100 tuples:
// this will trigger the output of the current regression coefficient estimates
stream<Covariate> CovariateAndDependentVariablePunct = Punctor(Covariate) {
logic state:
mutable uint32 n = 0;
onTuple Covariate:
n++;
param
punctuate: (n%100u)==0u || n > 9900u ;
position: after;
}
// Apply the RecursiveLeastSquare operator to update the model and filter the dependent variable (if a tuple
// arrives at port 0), to output the current estimate of the regression coefficients (if a punctuation arrives
// at port 0), or to predict the dependent variable (if a tuple arrives at port1):
(stream<Covariate, tuple<float64 y_hat>> UpdateModelAndFilterDependentVariable;
stream<list<float64> coefficients> RegressionCoefficients;
stream<Covariate, tuple<float64 y_hat>> PredictDependentVariable)
= RLSFilter(CovariateAndDependentVariablePunct; Covariate) {
param
inputCovariates: Covariate.x, CovariateAndDependentVariablePunct.x;
dependentVariable: CovariateAndDependentVariablePunct.y;
forgettingFactor: 1f;
output
UpdateModelAndFilterDependentVariable: y_hat = estimatedValue();
RegressionCoefficients: coefficients = coefficients();
PredictDependentVariable: y_hat = estimatedValue();
}
}
Summary
- Ports
- This operator has 2 input ports and 3 output ports.
- Windowing
- This operator does not accept any windowing configurations.
- Parameters
- This operator supports arbitrary parameters in addition to 3 specific parameters.
Required: dependentVariable, forgettingFactor, inputCovariates
- Metrics
- This operator does not report any metrics.
Properties
- Implementation
- C++
- Threading
- Never - Operator never provides a single threaded execution context.
- Ports (0)
-
This port ingests tuples to update the model.
- Properties
-
- Optional: false
- ControlPort: false
- TupleMutationAllowed: false
- WindowingMode: NonWindowed
- WindowPunctuationInputMode: Oblivious
- Ports (1)
-
This port ingests tuples to be scored.
- Properties
-
- Optional: false
- ControlPort: false
- TupleMutationAllowed: false
- WindowingMode: NonWindowed
- WindowPunctuationInputMode: Oblivious
- Assignments
- This operator allows any SPL expression of the correct type to be assigned to output attributes.
- Output Functions
-
- RLSDep
-
- <any T> T AsIs(T v)
- <any T> T estimatedValue()
- RLSCoef
-
- <any T> T AsIs(T v)
- <any T> list<T> coefficients()
- Ports (0)
-
- Properties
-
- Optional: false
- TupleMutationAllowed: false
- WindowPunctuationOutputMode: Preserving
- Ports (1)
-
- Properties
-
- Optional: false
- TupleMutationAllowed: false
- WindowPunctuationOutputMode: Preserving
- Ports (2)
-
- Properties
-
- Optional: false
- TupleMutationAllowed: false
- WindowPunctuationOutputMode: Generating
Required: dependentVariable, forgettingFactor, inputCovariates
- dependentVariable
-
Specifies the input attribute that contains the dependent variable from the update input port.
- Properties
-
- Cardinality: 1
- Optional: false
- ExpressionMode: Expression
- forgettingFactor
-
Specifies that the forgettingFactor range is between 0 and 1.
- Properties
-
- Type: float64
- Cardinality: 1
- Optional: false
- ExpressionMode: Expression
- inputCovariates
-
Specifies the input attribute that contains the co-variates to be operated upon from both the update port and scoring port.
- Properties
-
- Type: list<float64>
- Cardinality: 2
- Optional: false
- ExpressionMode: Expression
- RLSFilter
-
(stream<${schema1}> ${outputStream1}; stream<${schema2}> ${outputStream2}; stream<${schema3}> ${outputStream3}) = com.teracloud.streams.timeseries.modeling::RLSFilter(${inputStreamForUpdate}; ${inputStreamForScoring}) { param inputCovariates: ${inputCovariatesExpression}; dependentVariable: ${dependentVariableExpression}; forgettingFactor: ${forgettingFactorConstant}; output ${outputStream[n]}: ${output[n]AttributeAssignment}; }
- RecursiveLeastSquares