Operator LPC
The Linear Predictive Coding (LPC) operator uses an autoregressive (AR) model to predict values in a time series. The LPC operator is a univariate operator and can ingest a univariate time series.
The AR model uses a linear predictive coding approach to forecast future time series values. The linear predictive coding approach is primarily used in audio and speech processing applications to encode and decode speech signals. This approach is also used in spectral estimation, smoothing, predicting stock values, and in gene sequence modeling.
The LPC operator supports a control port to which you can send control signals to control the behavior of the model. For example, you can make the model adaptive so that the predicted values reflect the trend of the data accurately. Using the control signals, the LPC operator can train the model to use a new input time series to predict values.
Behavior in a consistent region
- The LPC 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.
Exceptions
The LPC operator does not throw any exceptions.
Examples
The following example shows how to forecast the next four values in a time series by using the LPC operator:
composite Main {
graph
stream<int64 stampTime, list<float64> KPIs> KPIStream = FileSource()
{
param
file : "KPIStream.csv";
format:csv;
}
stream <timestamp predTimestamps, list<float64>
predTimeSeries> predStream = LPC(KPIStream)
{
param
inputTimeSeries: KPIStream.KPIs;
initSamples: 144u;
order: 8u;
stepAhead: 4u;
output predStream:
predTimeSeries =forecastedTimeSeriesStep(),
predTimes-tamps=forecastedTimestamps();
}
() as writer1 = File-Sink(predStream)
{
param
file : "predstream.csv";
}
}
Summary
- Ports
- This operator has 2 input ports and 2 output ports.
- Windowing
- This operator does not accept any windowing configurations.
- Parameters
- This operator supports 10 parameters.
Required: initSamples, inputTimeSeries
Optional: controlSignal, diagout, inputCoefficient, inputTimestamp, order, partitionBy, retrainingConfig, stepAhead
- Metrics
- This operator does not report any metrics.
Properties
- Implementation
- C++
- Threading
- Always - Operator always provides a single threaded execution context.
- Ports (0)
-
This port consumes data for training and scoring against the model. The inputTimeSeries parameter specifies the name of the attribute on this port that contains the time series data. The accepted data types are float64 and list<float64>.
- Properties
-
- Optional: false
- ControlPort: false
- TupleMutationAllowed: false
- WindowingMode: NonWindowed
- WindowPunctuationInputMode: Oblivious
- Ports (1)
-
This port accepts control signals to control the behaviour of the operator. The controlSignal parameter specifies the name of the attribute on this port that contains the control signal type. The inputCoefficient parameter specifies the attribute name on this port that contains the new input coefficents. The retrainingConfig parameter specifies the attribute name on this port that contains the configuration values used for retraining the model.
- Properties
-
- Optional: true
- ControlPort: true
- 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
-
- LPC_COF
-
- list<list<float64> > forecastedAllTimeSeriesSteps()
-
Returns a two-dimensional list of forecasted values where for each index in the input time series a list of forecasted values are returned (values from step 1 to n).
- list<float64> forecastedTimeSeriesStep()
-
Returns the forecasted values at step n. The data at step n is a future time series value where n is the same as the stepAhead parameter value. If the input is a univariate time series, the output list contains a single forecasted value at step n.
- <any T> list<T> forecastedTimestamps()
-
Returns a timestamp object that holds the value of forecasted timestamp values. If the input timestamp is irregular, the function returns a zero timestamp value and the operators logs a warning message in the log file. The supported types are uint64 and timestamp.
- <any T> T AsIs (T v)
-
The default function for output attributes. By default, this function assigns the output attribute to the value of the input attribute with the same name.
- Getcoeff
-
- map<uint32,map<uint32,float64> > coefficients()
-
Returns the current coefficients of the LPC model.
- <any T> T AsIs(T v)
-
The default function for output attributes. By default, this function assigns the output attribute to the value of the input attribute with the same name.
- Ports (0)
-
This port submits a tuple that contains the next predicted value as determined by the LPC algorithm. This port submits a tuple each time a prediction is made. Custom output functions are used to specify the value of the output tuple attributes. The output tuple attributes whose assignments are not specified are assigned from input attributes.
- Properties
-
- Optional: false
- TupleMutationAllowed: false
- WindowPunctuationOutputMode: Preserving
- Ports (1)
-
This port submits a tuple that contains information about the state of the LPC model. This port submits a tuple each time a Monitor signal is consumed on the input control port. The coefficients() output function is used to assign the value of the coefficients to an attribute. The expected type of the attribute is map<uint32,map<uint32,float64> >.
- Properties
-
- Optional: true
- TupleMutationAllowed: false
- WindowPunctuationOutputMode: Preserving
Required: initSamples, inputTimeSeries
Optional: controlSignal, diagout, inputCoefficient, inputTimestamp, order, partitionBy, retrainingConfig, stepAhead
- controlSignal
-
Specifies the name of the attribute in the control port, which holds the control signal. The supported control signals are: TSSignal.Retrain, TSSignal.Monitor, TSSignal.Load, TSSignal.Suspend and TSSignal.Resume.
- Properties
-
- Type: enum{Monitor,Load,Retrain,RetrainAll,Suspend,Resume,UpdateParamsAll}
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- PortScope: 1
- diagout
-
Get diagnostics to stdout
- Properties
-
- Type: boolean
- Cardinality: 1
- Optional: true
- ExpressionMode: Constant
- initSamples
-
Specifies the number of input time series values to be used to initialize the model.
- Properties
-
- Type: uint32
- Cardinality: 1
- Optional: false
- ExpressionMode: Expression
- inputCoefficient
-
Specifies the name of the attribute in the control port, which ingests the coefficients that are used for loading the model. If this parameter is not specified, by default, the inputCoefficient attribute is used. If the default attribute or the inputCoefficient parameter is not provided, the operator throws an exception. If the attribute or the parameter value does not contain valid coefficients, the load operation fails and the operator logs a warning message for each failed operation. The operator continues to predict values by using the older coefficients.
- Properties
-
- Type: map<uint32,map<uint32,float64>>
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- PortScope: 1
- inputTimeSeries
-
Specifies the name of the attribute that contains the time series data in the input tuple. The supported types are float64 and list<float64>.
- Properties
-
- Type
- Cardinality: 1
- Optional: false
- ExpressionMode: Expression
- inputTimestamp
-
Specifies the name of the attribute in the input stream that contains the timestamp values. The supported data types are uint64 and timestamp. If the data type is uint64, the parameter value represents the number of nanoseconds since Unix epoch.
- Properties
-
- Type
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- PortScope: 0
- order
-
Specifies the order of the autoregressive model that the LPC operator uses for prediction. The default value is 24u.
- Properties
-
- Type: uint32
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- partitionBy
-
Specifies the name of the attribute that contains the key values that are associated with the time series values in the input tuple. An input time series with the same partitionBy key is processed as a continuum. If the control port is specified, you must provide the key parameter for both the input ports. Otherwise, an exception is thrown.
- Properties
-
- Type: rstring
- Optional: true
- ExpressionMode: Expression
- PortScope: 0, 1
- retrainingConfig
-
Specifies the name of the attribute in the control port, which ingests the configurations that are used for retraining the model. If this parameter is not specified, by default, the retrainingConfig attribute is used. If the default attribute or the retrainingConfig parameter is not provided, the operator throws an exception. If the attribute or the parameter does not contain valid configurations, the retrain operation fails and the operator logs a warning message for each failed operation. The operator continues to predict values by using the older configuration.
- Properties
-
- Type: map<rstring,uint32>
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- PortScope: 1
- stepAhead
-
Specifies the forecast horizon in the sample. The LPC operator produces a single-point forecast at the specified step. The default value is 1u.
- Properties
-
- Type: uint32
- Cardinality: 1
- Optional: true
- ExpressionMode: Expression
- LPC
-
stream<${schema}> ${outputStream} = LPC(${inputStream}) { param inputTimeSeries: ${timeSeriesExpression}; initSamples: ${initSamplesExpression}; output ${outputStream}: ${outputExpression}; }
- LPC library module