WeightedMovingAverage

scalation.modeling.forecasting_old.WeightedMovingAverage
See theWeightedMovingAverage companion object

The WeightedMovingAverage class provides basic time series analysis capabilities. For a WeightedMovingAverage model with the time series data stored in vector y, the next value y_t+1 = y(t+1) may be predicted based on the weighted-average of the past q values of y:

y_t+1 = weight-average (y_t, ..., y_t-q') + e_t+1

where e_t+1 is the new residual/error term and q' = q-1. The hyper-parameter u selects between flat (u = 0), linear weights (u = 1) or comninations of both.

Value parameters

hparam

the hyper-parameters

tt

the time points, if needed

y

the response vector (time series data)

Attributes

Companion
object
Graph
Supertypes
trait Fit
trait FitM
trait Correlogram
trait Forecaster
trait Model
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def forecast(t: Int, yf: MatrixD, y_: VectorD, hh: Int): VectorD

Produce a vector of size h, of 1 through h-steps ahead forecasts for the model. forecast the following time points: t+1, ..., t-1+h. Note, must create the yf matrix before calling the forecast method. Intended to work with rolling validation (analog of predict method) FIX - not updated

Produce a vector of size h, of 1 through h-steps ahead forecasts for the model. forecast the following time points: t+1, ..., t-1+h. Note, must create the yf matrix before calling the forecast method. Intended to work with rolling validation (analog of predict method) FIX - not updated

Value parameters

hh

the max forecasting horizon, number of steps ahead to produce forecasts

t

the time point from which to make forecasts

y_

the actual values to use in making predictions

yf

the forecast matrix (time x horizons)

Attributes

def forecastAt(yf: MatrixD, y_: VectorD, h: Int): VectorD

Forecast values for all y_.dim time points at horizon h (h-steps ahead). Assign to FORECAST MATRIX and return h-step ahead forecast. Note, predictAll provides predictions for h = 1.

Forecast values for all y_.dim time points at horizon h (h-steps ahead). Assign to FORECAST MATRIX and return h-step ahead forecast. Note, predictAll provides predictions for h = 1.

Value parameters

h

the forecasting horizon, number of steps ahead to produce forecasts

y_

the actual values to use in making forecasts

yf

the forecast matrix (time x horizons)

Attributes

See also

forecastAll method in Forecaster trait.

override def parameter: VectorD

Return the parameter vector (there are none, so return an empty vector).

Return the parameter vector (there are none, so return an empty vector).

Attributes

Definition Classes
def predict(t: Int, y_: VectorD): Double

Predict a value for y_t+1 using the 1-step ahead forecast.

Predict a value for y_t+1 using the 1-step ahead forecast.

y_t+1 = [y_t-q+1, ... y_t] dot w

When t < q-1 is negative, use mean of partial sequence

Value parameters

t

the time point from which to make prediction

y_

the actual values to use in making predictions

Attributes

override def test(x_null: MatrixD, y_: VectorD): (VectorD, VectorD)

Test PREDICTIONS of a Weighted Moving Average forecasting model and return its predictions and QoF vector. Testing may be in-sample (on the training set) or out-of-sample (on the testing set) as determined by the parameters passed in. Note: must call train before test.

Test PREDICTIONS of a Weighted Moving Average forecasting model and return its predictions and QoF vector. Testing may be in-sample (on the training set) or out-of-sample (on the testing set) as determined by the parameters passed in. Note: must call train before test.

Value parameters

x_null

the data/input matrix (ignored, pass null)

y_

the actual testing/full response/output vector

Attributes

Definition Classes
def testF(h: Int, y_: VectorD): (VectorD, VectorD, VectorD)

Test FORECASTS of a Weighted Moving Average forecasting model and return its forecasts and QoF vector. Testing may be in-sample (on the training set) or out-of-sample (on the testing set) as determined by the parameters passed in. Note: must call train and forecastAll before testF.

Test FORECASTS of a Weighted Moving Average forecasting model and return its forecasts and QoF vector. Testing may be in-sample (on the training set) or out-of-sample (on the testing set) as determined by the parameters passed in. Note: must call train and forecastAll before testF.

Value parameters

h

the forecasting horizon, number of steps ahead to produce forecasts

y_

the training/testing/full response/output vector

Attributes

def train(x_null: MatrixD, y_: VectorD): Unit

Train/fit an WeightedMovingAverage model to the times series data in vector y_. Note: for WeightedMovingAverage there are no parameters to train.

Train/fit an WeightedMovingAverage model to the times series data in vector y_. Note: for WeightedMovingAverage there are no parameters to train.

Value parameters

x_null

the data/input matrix (ignored, pass null)

y_

the actual training/full response/output vector

Attributes

Inherited methods

inline def acF: VectorD

Return the autocorrelation vector (ACF).

Return the autocorrelation vector (ACF).

Attributes

Inherited from:
Correlogram
def cap: Int

Return the maximum lag used by the model (its capacity to look into the past). Models that use more than one past value to make predictions/forecasts must override this method, e.g., ARMA (2, 3) should set the cap to max(p, q) = 3.

Return the maximum lag used by the model (its capacity to look into the past). Models that use more than one past value to make predictions/forecasts must override this method, e.g., ARMA (2, 3) should set the cap to max(p, q) = 3.

Attributes

Inherited from:
Forecaster
def crossValidate(k: Int, rando: Boolean): Array[Statistic]

As seen from class WeightedMovingAverage, the missing signatures are as follows. For convenience, these are usable as stub implementations.

As seen from class WeightedMovingAverage, the missing signatures are as follows. For convenience, these are usable as stub implementations.

Attributes

Inherited from:
Forecaster
override def diagnose(y_: VectorD, yp_: VectorD, w: VectorD): VectorD

Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted.

Diagnose the health of the model by computing the Quality of Fit (QoF) measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted.

Value parameters

w

the weights on the instances (defaults to null)

y_

the actual response/output vector to use (test/full)

yp_

the predicted response/output vector (test/full)

Attributes

See also

Regression_WLS

Definition Classes
Fit -> FitM
Inherited from:
Fit
def diagnose_(y: VectorD, yp: VectorD, low: VectorD, up: VectorD, alpha: Double, w: VectorD): VectorD

Diagnose the health of the model by computing the Quality of Fit (QoF) metrics/measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted. Include interval measures. Note: wis should be computed separately.

Diagnose the health of the model by computing the Quality of Fit (QoF) metrics/measures, from the error/residual vector and the predicted & actual responses. For some models the instances may be weighted. Include interval measures. Note: wis should be computed separately.

Value parameters

alpha

the nominal level of uncertainty (alpha) (defaults to 0.9, 90%)

low

the predicted lower bound

up

the predicted upper bound

w

the weights on the instances (defaults to null)

y

the actual response/output vector to use (test/full)

yp

the point prediction mean/median

Attributes

See also

Regression_WLS

Inherited from:
Fit
def diagnose_wis(y: VectorD, yp: VectorD, low: MatrixD, up: MatrixD, alphas: Array[Double]): Double

Diagnose the health of the model by computing the Quality of Fit (QoF) measures,

Diagnose the health of the model by computing the Quality of Fit (QoF) measures,

Value parameters

alphas

the array of prediction levels

low

the lower bounds for various alpha levels

up

the upper bounds for various alpha levels

y

the given time-series (must be aligned with the interval forecast)

yp

the point prediction mean/median

Attributes

Inherited from:
Fit
def durbinLevinson(g: VectorD, ml: Int): MatrixD

Apply the Durbin-Levinson Algorithm to iteratively compute the psi matrix. The last/p-th row of the matrix gives AR coefficients. Note, also known as Levinson-Durbin.

Apply the Durbin-Levinson Algorithm to iteratively compute the psi matrix. The last/p-th row of the matrix gives AR coefficients. Note, also known as Levinson-Durbin.

Value parameters

g

the auto-covariance vector (gamma)

ml

the maximum number of lags

Attributes

See also
Inherited from:
Correlogram
override def fit: VectorD

Return the Quality of Fit (QoF) measures corresponding to the labels given. Note, if sse > sst, the model introduces errors and the rSq may be negative, otherwise, R^2 (rSq) ranges from 0 (weak) to 1 (strong). Override to add more quality of fit measures.

Return the Quality of Fit (QoF) measures corresponding to the labels given. Note, if sse > sst, the model introduces errors and the rSq may be negative, otherwise, R^2 (rSq) ranges from 0 (weak) to 1 (strong). Override to add more quality of fit measures.

Attributes

Definition Classes
Fit -> FitM
Inherited from:
Fit
def forecastAll(y_: VectorD, h: Int): MatrixD

Forecast values for all y_.dim time points and all horizons (1 through h-steps ahead). Record these in the FORECAST MATRIX yf, where yf(t, k) = k-steps ahead forecast for y_t Note, column 0, yf(?, 0), is set to y (the actual time series values). last column, yf(?, h+1), is set to t (the time values, for reference). Forecast recursively down diagonals in the yf forecast matrix. The top right and bottom left triangles in yf matrix are not forecastable. FIX - merge the forecast matrices used by predictAll and forecastAll.

Forecast values for all y_.dim time points and all horizons (1 through h-steps ahead). Record these in the FORECAST MATRIX yf, where yf(t, k) = k-steps ahead forecast for y_t Note, column 0, yf(?, 0), is set to y (the actual time series values). last column, yf(?, h+1), is set to t (the time values, for reference). Forecast recursively down diagonals in the yf forecast matrix. The top right and bottom left triangles in yf matrix are not forecastable. FIX - merge the forecast matrices used by predictAll and forecastAll.

Value parameters

h

the maximum forecasting horizon, number of steps ahead to produce forecasts

y_

the actual values to use in making forecasts

Attributes

Inherited from:
Forecaster
def forecastAtI(y_: VectorD, yfh: VectorD, h: Int, p: Double): (VectorD, VectorD)

Forecast intervals for all y_.dim time points at horizon h (h-steps ahead). Create prediction intervals (two vectors) for the given time points at level p. Caveat: assumes errors follow a Normal distribution. Override this method to handle other cases.

Forecast intervals for all y_.dim time points at horizon h (h-steps ahead). Create prediction intervals (two vectors) for the given time points at level p. Caveat: assumes errors follow a Normal distribution. Override this method to handle other cases.

Value parameters

h

the forecasting horizon, number of steps ahead to produce forecasts

p

the level (1 - alpha) for the prediction interval

y_

the aligned actual values to use in making forecasts

yfh

the forecast vector at horizon h

Attributes

Inherited from:
Forecaster
def forwardSel(cols: Set[Int], idx_q: Int): (Int, Forecaster)

Perform forward selection to find the most predictive variable to add the existing model, returning the variable to add and the new model. May be called repeatedly. Note, all lags up and including 'p|q' define the model.

Perform forward selection to find the most predictive variable to add the existing model, returning the variable to add and the new model. May be called repeatedly. Note, all lags up and including 'p|q' define the model.

Value parameters

cols

the lags/columns currently included in the existing model (currently ignored)

idx_q

index of Quality of Fit (QoF) to use for comparing quality

Attributes

See also

Fit for index of QoF measures.

Inherited from:
Forecaster
def forwardSelAll(idx_q: Int, cross: Boolean): (Set[Int], MatrixD)

Perform forward selection to find the most predictive lags/variables to have in the model, returning the variables added and the new Quality of Fit (QoF) measures for all steps.

Perform forward selection to find the most predictive lags/variables to have in the model, returning the variables added and the new Quality of Fit (QoF) measures for all steps.

Value parameters

cross

whether to include the cross-validation QoF measure (currently ignored)

idx_q

index of Quality of Fit (QoF) to use for comparing quality

Attributes

See also

Fit for index of QoF measures.

Inherited from:
Forecaster
def getFname: Array[String]

Return the feature/variable names. Override for models like SARIMAX.

Return the feature/variable names. Override for models like SARIMAX.

Attributes

Inherited from:
Forecaster
def getX: MatrixD

Return the used data matrix x. Mainly for derived classes where x is expanded from the given columns in x_, e.g., SymbolicRegression.quadratic adds squared columns.

Return the used data matrix x. Mainly for derived classes where x is expanded from the given columns in x_, e.g., SymbolicRegression.quadratic adds squared columns.

Attributes

Inherited from:
Forecaster
def getY: VectorD

Return the used response vector y. Used by derived classes where y may be transformed, e.g., ARX.

Return the used response vector y. Used by derived classes where y may be transformed, e.g., ARX.

Attributes

Inherited from:
Forecaster

Return the the y-transformation.

Return the the y-transformation.

Attributes

Inherited from:
Fit
def getYY: MatrixD

Return the used response matrix y, if needed.

Return the used response matrix y, if needed.

Attributes

See also

neuralnet.PredictorMV

Inherited from:
Model
def getYf: MatrixD

Return the FORECAST MATRIX yf (initially allocated in predictAll method).

Return the FORECAST MATRIX yf (initially allocated in predictAll method).

Attributes

Inherited from:
Forecaster
def getYp: VectorD

Return the prediction vector yp.

Return the prediction vector yp.

Attributes

Inherited from:
Forecaster
override def help: String

Return the help string that describes the Quality of Fit (QoF) measures provided by the Fit trait. Override to correspond to fitLabel.

Return the help string that describes the Quality of Fit (QoF) measures provided by the Fit trait. Override to correspond to fitLabel.

Attributes

Definition Classes
Fit -> FitM
Inherited from:
Fit

Return the hyper-parameters.

Return the hyper-parameters.

Attributes

Inherited from:
Forecaster
def ll(ms: Double, s2: Double, m2: Int): Double

The log-likelihood function times -2. Override as needed.

The log-likelihood function times -2. Override as needed.

Value parameters

ms

raw Mean Squared Error

s2

MLE estimate of the population variance of the residuals

Attributes

See also
Inherited from:
Fit
def makeCorrelogram(y_: VectorD): Unit

Make a Correlogram, i.e., compute stats, psi and pacf.

Make a Correlogram, i.e., compute stats, psi and pacf.

Value parameters

y_

the current (e.g., training) times-series to use (defaults to full y)

Attributes

Inherited from:
Correlogram
def makeForecastMatrix(y_: VectorD, yp_: VectorD, h: Int): MatrixD

Make the full FORECAST MATRIX from the prediction forecast matrix (built by prodictAll). Has has more columns and a few more rows and copies all contents from the prediction forecast matrix.

Make the full FORECAST MATRIX from the prediction forecast matrix (built by prodictAll). Has has more columns and a few more rows and copies all contents from the prediction forecast matrix.

Value parameters

h

the maximum forecasting horizon, number of steps ahead to produce forecasts

y_

the actual values to use in making forecasts

yp_

the predicted values (h=1) to use in making forecasts

Attributes

Inherited from:
Forecaster
def mse_: Double

Return the mean of the squares for error (sse / df). Must call diagnose first.

Return the mean of the squares for error (sse / df). Must call diagnose first.

Attributes

Inherited from:
Fit
def nparams: Int

Attributes

Inherited from:
Forecaster
inline def pacF: VectorD

Return the partial autocorrelation vector (PACF).

Return the partial autocorrelation vector (PACF).

Attributes

Inherited from:
Correlogram
def plotCorrelogram(show: Boolean): Unit

Plot both the Auto-Correlation Function (ACF) and the Partial Auto-Correlation Function (PACF) with confidence bound.

Plot both the Auto-Correlation Function (ACF) and the Partial Auto-Correlation Function (PACF) with confidence bound.

Value parameters

show

whether to show the ACF, PACF values

Attributes

Inherited from:
Correlogram
def plotFunc(fVec: VectorD, name: String, show: Boolean): Unit

Plot a function, e.g., Auto-Correlation Function (ACF), Partial Auto-Correlation Function (PACF) with confidence bound.

Plot a function, e.g., Auto-Correlation Function (ACF), Partial Auto-Correlation Function (PACF) with confidence bound.

Value parameters

fVec

the vector given function values

name

the name of the function

show

whether to show the fVec values

Attributes

Inherited from:
Correlogram
def predict(z: VectorD): Double

The standard signature for prediction does not apply to time series.

The standard signature for prediction does not apply to time series.

Attributes

Inherited from:
Forecaster

Predict all values corresponding to the given time series vector y_. Create FORECAST MATRIX yf and return PREDICTION VECTOR yp as second (1) column of yf with last value removed.

Predict all values corresponding to the given time series vector y_. Create FORECAST MATRIX yf and return PREDICTION VECTOR yp as second (1) column of yf with last value removed.

Value parameters

h

the forecasting horizon, number of steps ahead to produce forecasts

y_

the actual time series values to use in making predictions

Attributes

See also

forecastAll to forecast beyond horizon h = 1.

Inherited from:
Forecaster
inline def psiM: MatrixD

Return the psi matrix.

Return the psi matrix.

Attributes

Inherited from:
Correlogram
def rSq0_: Double

Attributes

Inherited from:
FitM
def rSq_: Double

Return the coefficient of determination (R^2). Must call diagnose first.

Return the coefficient of determination (R^2). Must call diagnose first.

Attributes

Inherited from:
FitM
def report(ftMat: MatrixD): String

Return a basic report on a trained and tested multi-variate model.

Return a basic report on a trained and tested multi-variate model.

Value parameters

ftMat

the matrix of qof values produced by the Fit trait

Attributes

Inherited from:
Model
def report(ftVec: VectorD): String

Return a basic report on a trained and tested model.

Return a basic report on a trained and tested model.

Value parameters

ftVec

the vector of qof values produced by the Fit trait

Attributes

Inherited from:
Model
def resetDF(df_update: (Double, Double)): Unit

Reset the degrees of freedom to the new updated values. For some models, the degrees of freedom is not known until after the model is built.

Reset the degrees of freedom to the new updated values. For some models, the degrees of freedom is not known until after the model is built.

Value parameters

df_update

the updated degrees of freedom (model, error)

Attributes

Inherited from:
Fit

Return the vector of residuals/errors.

Return the vector of residuals/errors.

Attributes

Inherited from:
Forecaster
def show_interval_forecasts(yy: VectorD, yfh: VectorD, low: VectorD, up: VectorD, qof_all: VectorD, h: Int): Unit

Show the prediction interval forecasts and relevant QoF metrics/measures.

Show the prediction interval forecasts and relevant QoF metrics/measures.

Value parameters

h

the forecasting horizon

low

the predicted lower bound

qof_all

all the QoF metrics (for point and interval forecasts)

up

the predicted upper bound

yfh

the forecasts for horizon h

yy

the aligned actual response/output vector to use (test/full)

Attributes

Inherited from:
Fit
inline def smapeF(y: VectorD, yp: VectorD, e_: VectorD): Double

Return the symmetric Mean Absolute Percentage Error (sMAPE) score. Caveat: y_i = yp_i = 0 => no error => no percentage error

Return the symmetric Mean Absolute Percentage Error (sMAPE) score. Caveat: y_i = yp_i = 0 => no error => no percentage error

Value parameters

e_

the error/residual vector (if null, recompute)

y

the given time-series (must be aligned with the forecast)

yp

the forecasted time-series

Attributes

Inherited from:
FitM
def sse_: Double

Return the sum of the squares for error (sse). Must call diagnose first.

Return the sum of the squares for error (sse). Must call diagnose first.

Attributes

Inherited from:
FitM
inline def statsF: Stats4TS

Return basic statistics on time-series y or y_.

Return basic statistics on time-series y or y_.

Attributes

Inherited from:
Correlogram
override def summary(x_: MatrixD, fname: Array[String], b: VectorD, vifs: VectorD): String

Produce a QoF summary for a model with diagnostics for each predictor x_j and the overall Quality of Fit (QoF). Note: `Fac_Cholesky is used to compute the inverse of xtx.

Produce a QoF summary for a model with diagnostics for each predictor x_j and the overall Quality of Fit (QoF). Note: `Fac_Cholesky is used to compute the inverse of xtx.

Value parameters

b

the parameters/coefficients for the model

fname

the array of feature/variable names

vifs

the Variance Inflation Factors (VIFs)

x_

the testing/full data/input matrix

Attributes

Definition Classes
Fit -> FitM
Inherited from:
Fit

Train and test the forecasting model y_ = f(y-past) + e and report its QoF and plot its predictions. Return the predictions and QoF.

Train and test the forecasting model y_ = f(y-past) + e and report its QoF and plot its predictions. Return the predictions and QoF.

Value parameters

y_

the training/full response/output vector (defaults to full y)

yy

the testing/full response/output vector (defaults to full y)

Attributes

Inherited from:
Forecaster

Concrete fields

val w: VectorD

Inherited fields

var modelConcept: URI

The optional reference to an ontological concept

The optional reference to an ontological concept

Attributes

Inherited from:
Model
var modelName: String

The name for the model (or modeling technique).

The name for the model (or modeling technique).

Attributes

Inherited from:
Model