MeteoIODoc 2.11.0
mio::InterpolARIMA Class Reference

Detailed Description

This class is used for interpolating or predicting missing data in a time series using the Auto ARIMA algorithm.

Depending on the constructor that is used, the data and auto ARIMA models are set up for either interpolation or prediction. The interpolation is interpolate(). The prediction methods is predict().

Interpolate will fill a gap in the data, whose start is specified by gap_loc and whose length is specified by N_gap. Data is assumed to be of equal time steps, and is split into two parts, data_before and data_after. So in the end data should be of size data_before + data_after + N_gap. The interpolation is done by fitting one ARIMA model to data_before and one to data_after. The ARIMA models are fitted using the auto.arima algorithm from the ctsa (BSD-3 Clause, see below). The ARIMA models are then used to predict the missing data forward and backward in time. The final prediction is a weighted average of the two, where the weighting is done so more information comes from the closer data.

Predict will predict the next n_steps values in the time series. It can either be forward in time (direction = "forward") or backward in time (direction = "backward"). For forward prediction data[0:gap_loc] is used to fit the ARIMA model, and for backward prediction data[gap_loc + N_gap:] is used.

For more Information concerning ARIMA see, Wikipedia, and Forecast documentation, and the final interpolation algorithm: Time weighted average

Note
Interpolate is meant to only be used, when there is actually backward data available. If there is no backward data, then predict should be used instead. Where predict is meant to be used in conjunction with the according constructor. Currently prediction forward or backward, when providing both is not implemented, but can be easily added on demand.
Author
Patrick Leibersperger
Date
2024-01-25

Copyright (c) 2014, Rafat Hussain All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <InterpolARIMA.h>

Public Member Functions

 InterpolARIMA ()
 
 InterpolARIMA (std::vector< double > data_in, size_t gap_loc, size_t N_gap, int s=0)
 Main Constructor for an InterpolARIMA object. Used to fill 1 gap in the data. More...
 
 InterpolARIMA (std::vector< double > data_in, size_t gap_loc, size_t N_gap, std::vector< double > xreg_vec, int s=0)
 This constructor is used to initialize an InterpolARIMA object for filling a gap in the data with exogenous variables. More...
 
 InterpolARIMA (std::vector< double > data_in, size_t gap_loc, size_t n_predictions, std::string direction="forward", int s=0)
 This constructor is used to initialize an InterpolARIMA object for making predictions ahead or backward in time. More...
 
void setAutoArimaMetaData (int max_p_param=8, int max_d_param=3, int max_q=8, int start_p=2, int start_q=2, int max_P=2, int max_D=1, int max_Q=2, int start_P=1, int start_Q=1, bool seasonal=true, bool stationary=false)
 
void setOptMetaData (ObjectiveFunction method=CSS_MLE, OptimizationMethod opt_method=BFGS, bool stepwise=true, bool approximation=false, int num_models=94)
 
void setVerbose (bool verbose=false)
 
void setNormalizationMode (Normalization::Mode mode)
 
void setManualARIMA (int p, int d, int q, int P, int D, int Q, bool fill_backward)
 
std::vector< double > simulate (int n_steps, int seed=0)
 
void fillGap ()
 
void fillGapManual ()
 
void interpolate ()
 
std::vector< double > predict (size_t n_steps=0)
 
std::vector< double > ARIMApredict (size_t n_steps)
 
std::vector< double > getData ()
 
std::vector< double > getForwardData ()
 
std::vector< double > getBackwardData ()
 
std::vector< double > getInterpolatedData ()
 
 InterpolARIMA (const InterpolARIMA &other)
 
InterpolARIMAoperator= (const InterpolARIMA &other)
 
 ~InterpolARIMA ()
 
std::string toString ()
 
std::string autoArimaInfo (auto_arima_object obj)
 

Public Attributes

auto_arima_object auto_arima_forward
 
auto_arima_object auto_arima_backward
 
sarima_object sarima_forward
 

Constructor & Destructor Documentation

◆ InterpolARIMA() [1/5]

mio::InterpolARIMA::InterpolARIMA ( )

◆ InterpolARIMA() [2/5]

mio::InterpolARIMA::InterpolARIMA ( std::vector< double >  data_in,
size_t  gap_location,
size_t  gap_length,
int  period = 0 
)

Main Constructor for an InterpolARIMA object. Used to fill 1 gap in the data.

Parameters
data_inA vector of double values representing the input data.
gap_locationThe location of the gap in the data.
gap_lengthThe length of the gap in the data.
period(Optional) The period of the ARIMA model. Defaults to 0. Only needed when the period is known.

◆ InterpolARIMA() [3/5]

mio::InterpolARIMA::InterpolARIMA ( std::vector< double >  data_in,
size_t  gap_location,
size_t  gap_length,
std::vector< double >  xreg_vec_in,
int  period = 0 
)

This constructor is used to initialize an InterpolARIMA object for filling a gap in the data with exogenous variables.

Parameters
data_inThe input data for making predictions.
gap_locationThe starting location of the data gap.
gap_lengthThe length of the data gap.
xreg_vec_inThe exogenous inputs for the ARIMA model.
periodThe period for the ARIMA model.
Note
This constructor is part of the InterpolARIMA class.

◆ InterpolARIMA() [4/5]

mio::InterpolARIMA::InterpolARIMA ( std::vector< double >  data_in,
size_t  data_end,
size_t  n_predictions,
std::string  direction = "forward",
int  period = 0 
)

This constructor is used to initialize an InterpolARIMA object for making predictions ahead or backward in time.

Parameters
data_inThe input data for making predictions.
data_endThe end location of the data gap.
n_predictionsThe number of predictions to be made.
directionThe direction of the prediction. Can be either "forward" or "past".
periodThe period for the ARIMA model.

It also decides the direction of the data based on the direction parameter and the gap_loc:

  • If the direction is "forward", the prediction is made based on the data from the beginning of the data set up to gap_loc.
  • If the direction is "past", the prediction is made based on the data from gap_loc to the end of the data set.
Note
This constructor is part of the InterpolARIMA class in InterpolARIMA.cc.

◆ InterpolARIMA() [5/5]

mio::InterpolARIMA::InterpolARIMA ( const InterpolARIMA other)
inline

◆ ~InterpolARIMA()

mio::InterpolARIMA::~InterpolARIMA ( )
inline

Member Function Documentation

◆ ARIMApredict()

std::vector< double > mio::InterpolARIMA::ARIMApredict ( size_t  n_steps)

◆ autoArimaInfo()

std::string mio::InterpolARIMA::autoArimaInfo ( auto_arima_object  obj)

◆ fillGap()

void mio::InterpolARIMA::fillGap ( )

◆ fillGapManual()

void mio::InterpolARIMA::fillGapManual ( )

◆ getBackwardData()

std::vector< double > mio::InterpolARIMA::getBackwardData ( )
inline

◆ getData()

std::vector< double > mio::InterpolARIMA::getData ( )
inline

◆ getForwardData()

std::vector< double > mio::InterpolARIMA::getForwardData ( )
inline

◆ getInterpolatedData()

std::vector< double > mio::InterpolARIMA::getInterpolatedData ( )

◆ interpolate()

void mio::InterpolARIMA::interpolate ( )

◆ operator=()

InterpolARIMA & mio::InterpolARIMA::operator= ( const InterpolARIMA other)
inline

◆ predict()

std::vector< double > mio::InterpolARIMA::predict ( size_t  n_steps = 0)

◆ setAutoArimaMetaData()

void mio::InterpolARIMA::setAutoArimaMetaData ( int  max_p_param = 8,
int  max_d_param = 3,
int  max_q = 8,
int  start_p = 2,
int  start_q = 2,
int  max_P = 2,
int  max_D = 1,
int  max_Q = 2,
int  start_P = 1,
int  start_Q = 1,
bool  seasonal = true,
bool  stationary = false 
)

◆ setManualARIMA()

void mio::InterpolARIMA::setManualARIMA ( int  p,
int  d,
int  q,
int  P,
int  D,
int  Q,
bool  fill_backward 
)

◆ setNormalizationMode()

void mio::InterpolARIMA::setNormalizationMode ( Normalization::Mode  mode)

◆ setOptMetaData()

void mio::InterpolARIMA::setOptMetaData ( ObjectiveFunction  method = CSS_MLE,
OptimizationMethod  opt_method = BFGS,
bool  stepwise = true,
bool  approximation = false,
int  num_models = 94 
)

◆ setVerbose()

void mio::InterpolARIMA::setVerbose ( bool  verbose = false)

◆ simulate()

std::vector< double > mio::InterpolARIMA::simulate ( int  n_steps,
int  seed = 0 
)

◆ toString()

std::string mio::InterpolARIMA::toString ( )

Member Data Documentation

◆ auto_arima_backward

auto_arima_object mio::InterpolARIMA::auto_arima_backward

◆ auto_arima_forward

auto_arima_object mio::InterpolARIMA::auto_arima_forward

◆ sarima_forward

sarima_object mio::InterpolARIMA::sarima_forward

The documentation for this class was generated from the following files: