MeteoIODoc 2.11.0
ARIMAResampling.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2013 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef ARIMARESAMPLING_H
20#define ARIMARESAMPLING_H
21
25#include <vector>
26
27namespace mio {
28
29 using namespace ARIMAutils;
314 public:
315 ARIMAResampling(const std::string &i_algoname, const std::string &i_parname, const double &dflt_window_size,
316 const std::vector<std::pair<std::string, std::string>> &vecArgs);
317
318 // Performs ARIMA interpolation the first time it is called, as this is also the first time the data is available
319 void resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t &paramindex,
320 const std::vector<MeteoData> &vecM, MeteoData &md);
321 std::string toString() const;
322
323 private:
324 bool verbose;
325 // ARIMA related data
326 std::vector<ARIMA_GAP> gap_data;
327 std::vector<std::vector<double>> filled_data;
328 std::vector<std::vector<Date>> all_dates;
329
330 // Window parameters
331 double before_window, after_window;
332
333 // User defined Metadata
334 int max_p = 8, max_d = 3, max_q = 8;
335 int start_p = 2, start_q = 2;
336 int max_P = 2, max_D = 1, max_Q = 2;
337 int start_P = 1, start_Q = 1;
338 double period = 0;
339 ObjectiveFunction method = CSS_MLE;
340 OptimizationMethod opt_method = BFGS;
341 bool stepwise = true, approximation = true;
342 int num_models = 94;
343 bool seasonal = true, stationary = false;
344 Normalization::Mode normalize = Normalization::Mode::MinMax;
345
346 bool set_arima_manual = false;
347 bool fill_backward_manual = false;
348 int p = 0, d = 0, q = 0;
349 int P = 0, D = 0, Q = 0;
350
351 // Flags
352 bool is_zero_possible = false;
353 bool checked_vecM = false;
354 bool gave_warning_end = false;
355 bool gave_warning_start = false;
356 bool gave_warning_interpol = false;
357 std::vector<bool> is_valid_gap_data;
358 std::vector<bool> warned_about_gap;
359
360 ARIMA_GAP newest_gap;
361 // Private methods
362 void setMetaData(InterpolARIMA &arima);
363 std::vector<double> predictData(std::vector<double> &data, const std::string &direction, size_t startIdx_interpol,
364 size_t length_gap_interpol, int sr_period);
365
366 // Helper methods for resample
367 void checkZeroPossibility(const std::vector<MeteoData> &vecM, size_t paramindex);
368 bool processKnownGaps(const Date &resampling_date, const size_t paramindex,
369 const ResamplingAlgorithms::ResamplingPosition &position, const std::vector<MeteoData> &vecM, MeteoData &md);
370 void setEndGap(ARIMA_GAP &new_gap, Date &data_start_date, Date &data_end_date, const std::vector<MeteoData> &vecM,
371 const Date &resampling_date);
372 double interpolVecAt(const std::vector<MeteoData> &vecM, const size_t &idx, const Date &date, const size_t &paramindex);
373 double interpolVecAt(const std::vector<double> &data, const std::vector<Date> &dates, const size_t &pos, const Date &date);
374 void resampleInterpolationData(size_t &length_gap_interpol, size_t &endIdx_interpol, size_t &startIdx_interpol,
375 const ARIMA_GAP &new_gap, const Date &data_start_date, const Date &data_end_date,
376 const std::vector<MeteoData> &data_vec_before, const std::vector<MeteoData> &data_vec_after,
377 bool has_data_before, bool has_data_after, size_t paramindex, std::vector<double> &data,
378 std::vector<Date> &dates, size_t length);
379 std::vector<double> getInterpolatedData(std::vector<double> &data, size_t size_before, size_t size_after, size_t startIdx_interpol,
380 size_t length_gap_interpol, int period);
381 void cacheGap(const std::vector<double> &interpolated_data, const std::vector<Date> &interpolated_dates, const ARIMA_GAP &new_gap);
382
383 // info
384 void infoARIMA(InterpolARIMA arima);
385 };
386} // end namespace mio
387
388#endif
This class is designed to handle interpolation (resampling) of data using the ARIMA (AutoRegressive I...
Definition: ARIMAResampling.h:313
void resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t &paramindex, const std::vector< MeteoData > &vecM, MeteoData &md)
Definition: ARIMAResampling.cc:474
ARIMAResampling(const std::string &i_algoname, const std::string &i_parname, const double &dflt_window_size, const std::vector< std::pair< std::string, std::string > > &vecArgs)
Definition: ARIMAResampling.cc:27
std::string toString() const
Definition: ARIMAResampling.cc:143
Mode
Definition: ARIMAutils.h:54
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
This class is used for interpolating or predicting missing data in a time series using the Auto ARIMA...
Definition: InterpolARIMA.h:89
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:107
Interface class for the temporal resampling algorithms.
Definition: ResamplingAlgorithms.h:43
ResamplingPosition
Definition: ResamplingAlgorithms.h:46
OptimizationMethod
Definition: ARIMAutils.h:39
@ BFGS
Definition: ARIMAutils.h:45
ObjectiveFunction
Definition: ARIMAutils.h:34
@ CSS_MLE
Definition: ARIMAutils.h:35
Definition: Config.cc:31
Definition: ARIMAutils.h:147