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.AbstractForecaster
m_Baseline
the forecaster for the baseline.protected AbstractBaselineCorrection
m_Correction
the baseline correction scheme to use.protected boolean
m_ModelBuilt
whether a model was built.protected weka.classifiers.timeseries.AbstractForecaster
m_Periodicity
the 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 String
baselineTipText()
Returns the tip text for this property.boolean
baseModelHasSerializer()
Check whether the base learner requires special serializationvoid
buildForecaster(weka.core.Instances insts, PrintStream... progress)
Builds a new forecasting model using the supplied training data.void
clearPreviousState()
Reset model state.String
correctionTipText()
Returns the tip text for this property.protected Timeseries
extractBaseline(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).String
getAlgorithmName()
Provides a short name that describes the underlying algorithm in some way.weka.classifiers.timeseries.AbstractForecaster
getBaseline()
Returns the forecaster in use for the baselineAbstractBaselineCorrection
getCorrection()
Returns the baseline correction scheme in use.String[]
getOptions()
Gets the current option settings for the OptionHandler.weka.classifiers.timeseries.AbstractForecaster
getPeriodicity()
Returns the forecaster in use for the periodicityList<Object>
getPreviousState()
Get the last set state of the model.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.protected Timeseries
instancesToTimeseries(weka.core.Instances insts)
Turns Weka Instances into aTimeseries
.Enumeration
listOptions()
Returns an enumeration of all the available options..void
loadBaseModel(String filepath)
Load serialized classifiervoid
loadSerializedState(String filepath)
Load serialized model stateString
periodicityTipText()
Returns the tip text for this property.void
postExecution()
Perform any teardown stuff that might need to happen after execution.void
preExecution()
Perform any setup stuff that might need to happen before execution.void
primeForecaster(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.void
reset()
Reset this forecaster so that it is ready to construct a new model.void
saveBaseModel(String filepath)
Save underlying classifiervoid
serializeState(String filepath)
Serialize model statevoid
setBaseline(weka.classifiers.timeseries.AbstractForecaster value)
Sets the forecaster to use for the baseline.void
setCorrection(AbstractBaselineCorrection value)
Sets the baseline correction scheme to use.void
setOptions(String[] options)
Sets the OptionHandler's options using the given list.void
setPeriodicity(weka.classifiers.timeseries.AbstractForecaster value)
Sets the forecaster to use for the periodicity.void
setPreviousState(List<Object> previousState)
Load state into model.protected weka.core.Instances
timeseriesToInstances(Timeseries series)
Turns a timeseries back into Weka Instances.String
toString()
Outputs a short description of the model.boolean
usesState()
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:
getAlgorithmName
in 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:
reset
in interfaceweka.classifiers.timeseries.TSForecaster
-
listOptions
public Enumeration listOptions()
Returns an enumeration of all the available options..- Specified by:
listOptions
in 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:
setOptions
in 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:
getOptions
in 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 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 interfaceweka.classifiers.timeseries.TSForecaster
- Specified by:
buildForecaster
in 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 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 interfaceweka.classifiers.timeseries.TSForecaster
- Specified by:
primeForecaster
in 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:
forecast
in interfaceweka.classifiers.timeseries.TSForecaster
- Specified by:
forecast
in 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 Exception
Perform any setup stuff that might need to happen before execution.- Specified by:
preExecution
in interfaceweka.core.CommandlineRunnable
- Overrides:
preExecution
in classweka.classifiers.timeseries.AbstractForecaster
- Throws:
Exception
- if a problem occurs during setup
-
postExecution
public void postExecution() throws Exception
Perform any teardown stuff that might need to happen after execution.- Specified by:
postExecution
in interfaceweka.core.CommandlineRunnable
- Overrides:
postExecution
in 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:
baseModelHasSerializer
in 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:
saveBaseModel
in 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:
loadBaseModel
in 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:
serializeState
in 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:
loadSerializedState
in 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:
usesState
in interfaceweka.classifiers.timeseries.TSForecaster
- Returns:
- true if base learner uses state-based predictions, false otherwise
-
clearPreviousState
public void clearPreviousState()
Reset model state.- Specified by:
clearPreviousState
in interfaceweka.classifiers.timeseries.TSForecaster
-
setPreviousState
public void setPreviousState(List<Object> previousState)
Load state into model.- Specified by:
setPreviousState
in interfaceweka.classifiers.timeseries.TSForecaster
-
-