weka.classifiers.timeseries
Class AbstractForecaster

java.lang.Object
  extended by weka.classifiers.timeseries.AbstractForecaster
All Implemented Interfaces:
java.io.Serializable, TSForecaster, CommandlineRunnable
Direct Known Subclasses:
WekaForecaster

public abstract class AbstractForecaster
extends java.lang.Object
implements TSForecaster, CommandlineRunnable, java.io.Serializable

Abstract base class implementing TSForecaster that concrete subclasses can extend.

Version:
$Revision: $
Author:
Mark Hall (mhall{[at]}pentaho{[dot]}com)
See Also:
Serialized Form

Constructor Summary
AbstractForecaster()
           
 
Method Summary
abstract  void buildForecaster(Instances insts, java.io.PrintStream... progress)
          Builds a new forecasting model using the supplied training data.
abstract  java.util.List<java.util.List<NumericPrediction>> forecast(int numSteps, java.io.PrintStream... progress)
          Produce a forecast for the target field(s).
 java.lang.String getFieldsToForecast()
          Get the fields to forecast.
static TSForecaster makeCopy(TSForecaster model)
          Creates a deep copy of the given forecaster using serialization.
abstract  void primeForecaster(Instances insts)
          Supply the (potentially) trained model with enough historical data, up to and including the current time point, in order to produce a forecast.
 void run(java.lang.Object toRun, java.lang.String[] options)
          Run the supplied object using the supplied options on the command line.
 void runForecaster(TSForecaster forecaster, java.lang.String[] options)
          Run the supplied forecaster with the supplied options on the command line.
 void setFieldsToForecast(java.lang.String targets)
          Set the names of the fields/attributes in the data to forecast.
static java.util.List<java.lang.String> stringToList(java.lang.String list)
          A utility method for converting a List of Strings to a single comma separated String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface weka.classifiers.timeseries.TSForecaster
getAlgorithmName, primeForecasterIncremental, reset
 

Constructor Detail

AbstractForecaster

public AbstractForecaster()
Method Detail

stringToList

public static java.util.List<java.lang.String> stringToList(java.lang.String list)
A utility method for converting a List of Strings to a single comma separated String.

Parameters:
list - the List object to process
Returns:
a single String containing a comma separated list of elements from the original list.

setFieldsToForecast

public void setFieldsToForecast(java.lang.String targets)
                         throws java.lang.Exception
Set the names of the fields/attributes in the data to forecast.

Specified by:
setFieldsToForecast in interface TSForecaster
Parameters:
targets - a list of names of fields to forecast
Throws:
java.lang.Exception - if a field(s) can't be found, or if multiple fields are specified and this forecaster can't predict multiple fields.

getFieldsToForecast

public java.lang.String getFieldsToForecast()
Get the fields to forecast.

Specified by:
getFieldsToForecast in interface TSForecaster
Returns:
the fields to forecast

buildForecaster

public abstract void buildForecaster(Instances insts,
                                     java.io.PrintStream... progress)
                              throws java.lang.Exception
Builds a new forecasting model using the supplied training data. The instances in the data are assumed to be sorted in ascending order of time and equally spaced in time. Some methods may not need to implement this method and may instead do their work in the primeForecaster method.

Specified by:
buildForecaster in interface TSForecaster
Parameters:
insts - the training instances.
progress - an optional varargs parameter supplying progress objects to report to
Throws:
java.lang.Exception - if the model can't be constructed for some reason.

primeForecaster

public abstract void primeForecaster(Instances insts)
                              throws java.lang.Exception
Supply the (potentially) trained model with enough historical data, up to and including the current time point, in order to produce a forecast. Instances are assumed to be sorted in ascending order of time and equally spaced in time.

Specified by:
primeForecaster in interface TSForecaster
Parameters:
insts - the instances to prime the model with
Throws:
java.lang.Exception - if the model can't be primed for some reason.

forecast

public abstract java.util.List<java.util.List<NumericPrediction>> forecast(int numSteps,
                                                                           java.io.PrintStream... progress)
                                                                    throws java.lang.Exception
Produce a forecast for the target field(s). Assumes that the model has been built and/or primed so that a forecast can be generated.

Specified by:
forecast in interface TSForecaster
Parameters:
numSteps - number of forecasted values to produce for each target. E.g. a value of 5 would produce a prediction for t+1, t+2, ..., t+5.
progress - an optional varargs parameter supplying progress objects to report to
Returns:
a List of Lists (one for each step) of forecasted values for each target
Throws:
java.lang.Exception - if the forecast can't be produced for some reason.

run

public void run(java.lang.Object toRun,
                java.lang.String[] options)
         throws java.lang.IllegalArgumentException
Run the supplied object using the supplied options on the command line.

Specified by:
run in interface CommandlineRunnable
Parameters:
toRun - the object to run.
options - the command line options to pass to the object.
Throws:
java.lang.Exception - if the supplied object is not an instance of TSForecaster.
java.lang.IllegalArgumentException

makeCopy

public static TSForecaster makeCopy(TSForecaster model)
                             throws java.lang.Exception
Creates a deep copy of the given forecaster using serialization.

Parameters:
model - the forecaster to copy
Returns:
a deep copy of the forecaster
Throws:
java.lang.Exception - if an error occurs

runForecaster

public void runForecaster(TSForecaster forecaster,
                          java.lang.String[] options)
Run the supplied forecaster with the supplied options on the command line.

Specified by:
runForecaster in interface TSForecaster
Parameters:
forecaster - the forecaster to run
options - the options to pass to the forecaster