Package weka.classifiers.timeseries
Class BaselineAdjustedForecaster
- java.lang.Object
-
- weka.classifiers.timeseries.AbstractForecaster
-
- weka.classifiers.timeseries.BaselineAdjustedForecaster
-
- All Implemented Interfaces:
Serializable,weka.classifiers.timeseries.TSForecaster,weka.core.CommandlineRunnable,weka.core.OptionHandler
public class BaselineAdjustedForecaster extends weka.classifiers.timeseries.AbstractForecaster implements Serializable, weka.core.OptionHandler
Uses two base-forecasters for making predictions. The first one is trained on the baseline of the timeseries (= overall trend), the second is trained on the baseline-corrected data (= periodicity). At forecast time, the two predictions are super-imposed to generate the original signal again.
Valid options are:
-correction <classname+options> The baseline correction scheme. (default: adams.data.baseline.LOWESSBased)
-baseline <classname+options> The baseline forecaster. (default: weka.classifiers.timeseries.WekaForecaster)
-periodicity <classname+options> The periodicity forecaster. (default: weka.classifiers.timeseries.WekaForecaster)
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected weka.classifiers.timeseries.AbstractForecasterm_Baselinethe forecaster for the baseline.protected AbstractBaselineCorrectionm_Correctionthe baseline correction scheme to use.protected booleanm_ModelBuiltwhether a model was built.protected weka.classifiers.timeseries.AbstractForecasterm_Periodicitythe forecaster for the periodicity (= baseline-correct signal).
-
Constructor Summary
Constructors Constructor Description BaselineAdjustedForecaster()Initializes the forecaster.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbaselineTipText()Returns the tip text for this property.booleanbaseModelHasSerializer()Check whether the base learner requires special serializationvoidbuildForecaster(weka.core.Instances insts, PrintStream... progress)Builds a new forecasting model using the supplied training data.voidclearPreviousState()Reset model state.StringcorrectionTipText()Returns the tip text for this property.protected TimeseriesextractBaseline(Timeseries raw, Timeseries corrected)Subtracts the corrected signal from the original one to obtain the baseline.List<List<weka.classifiers.evaluation.NumericPrediction>>forecast(int numSteps, PrintStream... progress)Produce a forecast for the target field(s).StringgetAlgorithmName()Provides a short name that describes the underlying algorithm in some way.weka.classifiers.timeseries.AbstractForecastergetBaseline()Returns the forecaster in use for the baselineAbstractBaselineCorrectiongetCorrection()Returns the baseline correction scheme in use.String[]getOptions()Gets the current option settings for the OptionHandler.weka.classifiers.timeseries.AbstractForecastergetPeriodicity()Returns the forecaster in use for the periodicityList<Object>getPreviousState()Get the last set state of the model.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.protected TimeseriesinstancesToTimeseries(weka.core.Instances insts)Turns Weka Instances into aTimeseries.EnumerationlistOptions()Returns an enumeration of all the available options..voidloadBaseModel(String filepath)Load serialized classifiervoidloadSerializedState(String filepath)Load serialized model stateStringperiodicityTipText()Returns the tip text for this property.voidpostExecution()Perform any teardown stuff that might need to happen after execution.voidpreExecution()Perform any setup stuff that might need to happen before execution.voidprimeForecaster(weka.core.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.voidreset()Reset this forecaster so that it is ready to construct a new model.voidsaveBaseModel(String filepath)Save underlying classifiervoidserializeState(String filepath)Serialize model statevoidsetBaseline(weka.classifiers.timeseries.AbstractForecaster value)Sets the forecaster to use for the baseline.voidsetCorrection(AbstractBaselineCorrection value)Sets the baseline correction scheme to use.voidsetOptions(String[] options)Sets the OptionHandler's options using the given list.voidsetPeriodicity(weka.classifiers.timeseries.AbstractForecaster value)Sets the forecaster to use for the periodicity.voidsetPreviousState(List<Object> previousState)Load state into model.protected weka.core.InstancestimeseriesToInstances(Timeseries series)Turns a timeseries back into Weka Instances.StringtoString()Outputs a short description of the model.booleanusesState()Check whether the base learner requires operations regarding state
-
-
-
Field Detail
-
m_Correction
protected AbstractBaselineCorrection m_Correction
the baseline correction scheme to use.
-
m_Baseline
protected weka.classifiers.timeseries.AbstractForecaster m_Baseline
the forecaster for the baseline.
-
m_Periodicity
protected weka.classifiers.timeseries.AbstractForecaster m_Periodicity
the forecaster for the periodicity (= baseline-correct signal).
-
m_ModelBuilt
protected boolean m_ModelBuilt
whether a model was built.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Returns:
- a description suitable for displaying in the gui
-
getAlgorithmName
public String getAlgorithmName()
Provides a short name that describes the underlying algorithm in some way.- Specified by:
getAlgorithmNamein interfaceweka.classifiers.timeseries.TSForecaster- Returns:
- a short description of this forecaster.
-
initialize
protected void initialize()
Initializes the members.
-
reset
public void reset()
Reset this forecaster so that it is ready to construct a new model.- Specified by:
resetin interfaceweka.classifiers.timeseries.TSForecaster
-
listOptions
public Enumeration listOptions()
Returns an enumeration of all the available options..- Specified by:
listOptionsin interfaceweka.core.OptionHandler- Returns:
- an enumeration of all available options.
-
setOptions
public void setOptions(String[] options) throws Exception
Sets the OptionHandler's options using the given list. All options will be set (or reset) during this call (i.e. incremental setting of options is not possible).- Specified by:
setOptionsin interfaceweka.core.OptionHandler- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
getOptions
public String[] getOptions()
Gets the current option settings for the OptionHandler.- Specified by:
getOptionsin interfaceweka.core.OptionHandler- Returns:
- the list of current option settings as an array of strings
-
setCorrection
public void setCorrection(AbstractBaselineCorrection value)
Sets the baseline correction scheme to use.- Parameters:
value- the scheme
-
getCorrection
public AbstractBaselineCorrection getCorrection()
Returns the baseline correction scheme in use.- Returns:
- the scheme
-
correctionTipText
public String correctionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setBaseline
public void setBaseline(weka.classifiers.timeseries.AbstractForecaster value)
Sets the forecaster to use for the baseline.- Parameters:
value- the forecaster
-
getBaseline
public weka.classifiers.timeseries.AbstractForecaster getBaseline()
Returns the forecaster in use for the baseline- Returns:
- the forecaster
-
baselineTipText
public String baselineTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setPeriodicity
public void setPeriodicity(weka.classifiers.timeseries.AbstractForecaster value)
Sets the forecaster to use for the periodicity.- Parameters:
value- the forecaster
-
getPeriodicity
public weka.classifiers.timeseries.AbstractForecaster getPeriodicity()
Returns the forecaster in use for the periodicity- Returns:
- the forecaster
-
periodicityTipText
public String periodicityTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
instancesToTimeseries
protected Timeseries instancesToTimeseries(weka.core.Instances insts) throws Exception
Turns Weka Instances into aTimeseries.- Parameters:
insts- the instances to convert- Returns:
- the timeseries
- Throws:
Exception- if conversion fails
-
timeseriesToInstances
protected weka.core.Instances timeseriesToInstances(Timeseries series) throws Exception
Turns a timeseries back into Weka Instances.- Parameters:
series- the timeseries to convert- Returns:
- the Instances
- Throws:
Exception- if conversion fails
-
extractBaseline
protected Timeseries extractBaseline(Timeseries raw, Timeseries corrected)
Subtracts the corrected signal from the original one to obtain the baseline.- Parameters:
raw- the original signalcorrected- the baseline-corrected signal- Returns:
- the baseline adjustment
-
buildForecaster
public void buildForecaster(weka.core.Instances insts, PrintStream... progress) throws ExceptionBuilds 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:
buildForecasterin interfaceweka.classifiers.timeseries.TSForecaster- Specified by:
buildForecasterin classweka.classifiers.timeseries.AbstractForecaster- Parameters:
insts- the training instances.progress- an optional varargs parameter supplying progress objects to report to- Throws:
Exception- if the model can't be constructed for some reason.
-
primeForecaster
public void primeForecaster(weka.core.Instances insts) throws ExceptionSupply 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:
primeForecasterin interfaceweka.classifiers.timeseries.TSForecaster- Specified by:
primeForecasterin classweka.classifiers.timeseries.AbstractForecaster- Parameters:
insts- the instances to prime the model with- Throws:
Exception- if the model can't be primed for some reason.
-
forecast
public List<List<weka.classifiers.evaluation.NumericPrediction>> forecast(int numSteps, PrintStream... progress) throws 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:
forecastin interfaceweka.classifiers.timeseries.TSForecaster- Specified by:
forecastin classweka.classifiers.timeseries.AbstractForecaster- 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:
Exception- if the forecast can't be produced for some reason.
-
toString
public String toString()
Outputs a short description of the model.
-
preExecution
public void preExecution() throws ExceptionPerform any setup stuff that might need to happen before execution.- Specified by:
preExecutionin interfaceweka.core.CommandlineRunnable- Overrides:
preExecutionin classweka.classifiers.timeseries.AbstractForecaster- Throws:
Exception- if a problem occurs during setup
-
postExecution
public void postExecution() throws ExceptionPerform any teardown stuff that might need to happen after execution.- Specified by:
postExecutionin interfaceweka.core.CommandlineRunnable- Overrides:
postExecutionin classweka.classifiers.timeseries.AbstractForecaster- Throws:
Exception- if a problem occurs during teardown
-
baseModelHasSerializer
public boolean baseModelHasSerializer()
Check whether the base learner requires special serialization- Specified by:
baseModelHasSerializerin interfaceweka.classifiers.timeseries.TSForecaster- Returns:
- true if base learner requires special serialization, false otherwise
-
saveBaseModel
public void saveBaseModel(String filepath) throws Exception
Save underlying classifier- Specified by:
saveBaseModelin interfaceweka.classifiers.timeseries.TSForecaster- Parameters:
filepath- the path of the file to save the base model to- Throws:
Exception
-
loadBaseModel
public void loadBaseModel(String filepath) throws Exception
Load serialized classifier- Specified by:
loadBaseModelin interfaceweka.classifiers.timeseries.TSForecaster- Parameters:
filepath- the path of the file to load the base model from- Throws:
Exception
-
serializeState
public void serializeState(String filepath) throws Exception
Serialize model state- Specified by:
serializeStatein interfaceweka.classifiers.timeseries.TSForecaster- Parameters:
filepath- the path of the file to save the model state to- Throws:
Exception
-
loadSerializedState
public void loadSerializedState(String filepath) throws Exception
Load serialized model state- Specified by:
loadSerializedStatein interfaceweka.classifiers.timeseries.TSForecaster- Parameters:
filepath- the path of the file to save the model state from- Throws:
Exception
-
usesState
public boolean usesState()
Check whether the base learner requires operations regarding state- Specified by:
usesStatein interfaceweka.classifiers.timeseries.TSForecaster- Returns:
- true if base learner uses state-based predictions, false otherwise
-
clearPreviousState
public void clearPreviousState()
Reset model state.- Specified by:
clearPreviousStatein interfaceweka.classifiers.timeseries.TSForecaster
-
setPreviousState
public void setPreviousState(List<Object> previousState)
Load state into model.- Specified by:
setPreviousStatein interfaceweka.classifiers.timeseries.TSForecaster
-
-