Class 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 Detail

      • 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.
    • Constructor Detail

      • BaselineAdjustedForecaster

        public BaselineAdjustedForecaster()
        Initializes the forecaster.
    • 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 interface weka.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 interface weka.classifiers.timeseries.TSForecaster
      • listOptions

        public Enumeration listOptions()
        Returns an enumeration of all the available options..
        Specified by:
        listOptions in interface weka.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 interface weka.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 interface weka.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 a Timeseries.
        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 signal
        corrected - 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 interface weka.classifiers.timeseries.TSForecaster
        Specified by:
        buildForecaster in class weka.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 interface weka.classifiers.timeseries.TSForecaster
        Specified by:
        primeForecaster in class weka.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 interface weka.classifiers.timeseries.TSForecaster
        Specified by:
        forecast in class weka.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.
        Overrides:
        toString in class Object
        Returns:
        the description
      • preExecution

        public void preExecution()
                          throws Exception
        Perform any setup stuff that might need to happen before execution.
        Specified by:
        preExecution in interface weka.core.CommandlineRunnable
        Overrides:
        preExecution in class weka.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 interface weka.core.CommandlineRunnable
        Overrides:
        postExecution in class weka.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 interface weka.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 interface weka.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 interface weka.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 interface weka.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 interface weka.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 interface weka.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 interface weka.classifiers.timeseries.TSForecaster
      • setPreviousState

        public void setPreviousState​(List<Object> previousState)
        Load state into model.
        Specified by:
        setPreviousState in interface weka.classifiers.timeseries.TSForecaster
      • getPreviousState

        public List<Object> getPreviousState()
        Get the last set state of the model.
        Specified by:
        getPreviousState in interface weka.classifiers.timeseries.TSForecaster
        Returns:
        the state of the model to be used in next prediction