MeteoIODoc 20241221.207bde49
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;
321 public:
322 ARIMAResampling(const std::string &i_algoname, const std::string &i_parname, const double &dflt_max_gap_size,
323 const std::vector<std::pair<std::string, std::string>> &vecArgs);
324
325 // Performs ARIMA interpolation the first time it is called, as this is also the first time the data is available
326 void resample(const std::string &stationHash, const size_t &index, const ResamplingPosition &position, const size_t &paramindex,
327 const std::vector<MeteoData> &vecM, MeteoData &md);
328 std::string toString() const;
329
330 private:
331 bool verbose;
332 // ARIMA related data
333 std::vector<ARIMA_GAP> gap_data;
334 std::vector<std::vector<double>> filled_data;
335 std::vector<std::vector<Date>> all_dates;
336
337 // Window parameters
338 double before_window, after_window;
339
340 // User defined Metadata
341 int max_p = 8, max_d = 3, max_q = 8;
342 int start_p = 2, start_q = 2;
343 int max_P = 2, max_D = 1, max_Q = 2;
344 int start_P = 1, start_Q = 1;
345 double period = 0;
346 ObjectiveFunction method = CSS_MLE;
347 OptimizationMethod opt_method = BFGS;
348 bool stepwise = true, approximation = true;
349 int num_models = 94;
350 bool seasonal = true, stationary = false;
351 Normalization::Mode normalize = Normalization::Mode::Nothing;
352
353 bool set_arima_manual = false;
354 bool fill_backward_manual = false;
355 int p = 0, d = 0, q = 0;
356 int P = 0, D = 0, Q = 0;
357
358 // Flags
359 bool is_zero_possible = false;
360 bool checked_vecM = false;
361 bool gave_warning_end = false;
362 bool gave_warning_start = false;
363 bool gave_warning_interpol = false;
364 std::vector<bool> is_valid_gap_data;
365 std::vector<bool> warned_about_gap;
366
367 ARIMA_GAP newest_gap;
368 // Private methods
369 void setMetaData(InterpolARIMA &arima);
370 std::vector<double> predictData(std::vector<double> &data, const std::string &direction, size_t startIdx_interpol,
371 size_t length_gap_interpol, int sr_period);
372
373 // Helper methods for resample
374 void checkZeroPossibility(const std::vector<MeteoData> &vecM, size_t paramindex);
375 bool processKnownGaps(const Date &resampling_date, const size_t paramindex,
376 const ResamplingAlgorithms::ResamplingPosition &position, const std::vector<MeteoData> &vecM, MeteoData &md);
377 double interpolVecAt(const std::vector<MeteoData> &vecM, const size_t &idx, const Date &date, const size_t &paramindex);
378 double interpolVecAt(const std::vector<double> &data, const std::vector<Date> &dates, const size_t &pos, const Date &date);
379 double interpolVecAt(std::vector<MeteoData> &vecMet, const Date &date, const size_t &paramindex);
380 void resampleInterpolationData(size_t &length_gap_interpol, size_t &endIdx_interpol, size_t &startIdx_interpol,
381 const ARIMA_GAP &new_gap, const Date &data_start_date, const Date &data_end_date,
382 std::vector<MeteoData> &data_vec_before, std::vector<MeteoData> &data_vec_after,
383 bool has_data_before, bool has_data_after, size_t paramindex, std::vector<double> &data,
384 std::vector<Date> &dates, size_t length);
385 std::vector<double> getInterpolatedData(std::vector<double> &data, size_t size_before, size_t size_after, size_t startIdx_interpol,
386 size_t length_gap_interpol, int period);
387 void cacheGap(const std::vector<double> &interpolated_data, const std::vector<Date> &interpolated_dates, const ARIMA_GAP &new_gap);
388
389 // info
390 void infoARIMA(InterpolARIMA arima);
391 };
392} // end namespace mio
393
394#endif
This class is designed to handle interpolation (resampling) of data using the ARIMA (AutoRegressive I...
Definition: ARIMAResampling.h:320
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:470
std::string toString() const
Definition: ARIMAResampling.cc:138
ARIMAResampling(const std::string &i_algoname, const std::string &i_parname, const double &dflt_max_gap_size, const std::vector< std::pair< std::string, std::string > > &vecArgs)
Definition: ARIMAResampling.cc:27
Mode
Definition: ARIMAutils.h:57
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:104
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:108
Interface class for the temporal resampling algorithms.
Definition: ResamplingAlgorithms.h:43
ResamplingPosition
Definition: ResamplingAlgorithms.h:46
OptimizationMethod
Definition: ARIMAutils.h:41
@ BFGS
Definition: ARIMAutils.h:47
ObjectiveFunction
Definition: ARIMAutils.h:34
@ CSS_MLE
Definition: ARIMAutils.h:35
Definition: Config.cc:31
Definition: ARIMAutils.h:150