//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** @author John Miller, Hao Peng * @version 1.5 * @date Sat Dec 8 14:32:12 EST 2018 * @see LICENSE (MIT style license file). */ package scalation.analytics.forecaster import scala.collection.mutable.{LinkedHashMap, Map} import scala.math.{min, sqrt} import scalation.linalgebra.{VectoD, VectorD} import scalation.math.double_exp import scalation.plot.Plot //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** The `Forecaster` trait provides a common framework for several forecasters. * Note, the 'train' method must be called first followed by 'eval'. * @param t the time vector * @param y the input vector (time series data) * @param orders the orders for the model (e.g., ARIMA (,d,)) */ abstract class ForecasterVec (t: VectoD, y: VectoD, orders: Int*) extends Forecaster { protected val n = y.dim // size of the input vector protected val ml = min (n, 20) // maximum lag to consider protected val mu = y.mean // the sample mean protected var e = new VectorD (n) // residual/error vector [e_0, e_1, ... e_m-1] //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Given a time series 'y', train the prediction function 'y = f(y_)', where * 'f(y_)' is a function of the lagged values of 'y', by fitting its parameters. */ def train (): ForecasterVec //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Return the parameter vector. */ def parameters: VectoD //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Compute the error and useful diagnostics for the entire dataset. */ def eval () = { diagnose (y, e) } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: /** Plot a function, e.g., Auto-Correlation Function 'ACF', Partial Auto-Correlation * Function 'PACF'. * @param fVec the vector given function values * @param name the name of the function */ def plotFunc (fVec: VectoD, name: String) { val lag_axis = new VectorD (ml+1) for (i <- 0 until fVec.dim) lag_axis(i) = i val zero = new VectorD (ml+1) new Plot (lag_axis, fVec, zero, "Plot of " + name) } // plotFunc } // ForecasterVec abstract class