32 namespace ARIMAutils {
65 std::vector<double>
normalize(
const std::vector<double>& data);
66 std::vector<double>
denormalize(
const std::vector<double>& data);
77 std::vector<double>
slice(
const std::vector<double> &vec,
size_t start,
size_t N);
80 std::vector<double>
slice(
const std::vector<double> &vec,
size_t start);
83 std::vector<double>
arange(
size_t start,
size_t N);
85 template <
typename T> T
findMinMax(
const std::vector<T> &vec,
bool findMin) {
88 T extremeValue = vec[0];
89 for (
const auto &value : vec) {
90 if (findMin ? value < extremeValue : value > extremeValue) {
101 double stdDev(
const std::vector<double> &vec);
106 throw std::invalid_argument(
"Cannot reverse an empty vector");
109 int end = int(vec.size()) - 1;
111 while (start < end) {
112 std::swap(vec[start], vec[end]);
121 throw std::invalid_argument(
"Cannot reverse an empty vector");
123 std::vector<T> reversed_vec = vec;
125 int end = int(reversed_vec.size()) - 1;
127 while (start < end) {
128 std::swap(reversed_vec[start], reversed_vec[end]);
137 std::vector<double>
toVector(
const std::vector<MeteoData> &vecM,
const std::string ¶mname);
140 std::vector<double>
toVector(
const std::vector<MeteoData> &vecM,
const size_t ¶mindex);
143 std::vector<double>
decideDirection(
const std::vector<double> &data,
const std::string &direction,
bool forward,
size_t gap_loc,
149 void extend(
const size_t &idx,
const std::vector<MeteoData> &vecM) {
155 void setStart(
const size_t &idx,
const std::vector<MeteoData> &vecM) {
156 if (idx >= vecM.size())
161 void setEnd(
const size_t &idx,
const std::vector<MeteoData> &vecM) {
162 if (idx >= vecM.size())
180 std::ostringstream os;
181 os <<
"ARIMA_GAP: {\n"
191 size_t searchBackward(
ARIMA_GAP &last_gap,
const size_t &pos,
const size_t ¶mindex,
const std::vector<MeteoData> &vecM,
192 const Date &resampling_date,
const double &i_window_size);
195 size_t searchForward(
ARIMA_GAP &last_gap,
const size_t &pos,
const size_t ¶mindex,
const std::vector<MeteoData> &vecM,
196 const Date &resampling_date,
const double &i_window_size,
const size_t &indexP1);
198 void computeARIMAGap(
ARIMA_GAP &last_gap,
const size_t &pos,
const size_t ¶mindex,
const std::vector<MeteoData> &vecM,
199 const Date &resampling_date,
size_t &indexP1,
size_t &indexP2,
double &before_window,
double &after_window,
200 double &window_size,
Date &data_start_date,
Date &data_end_date);
212 Date &data_end_date);
214 const Date &data_end_date);
217 std::ostringstream oss;
219 for (
const auto &vec : vecs) {
220 maxSize = std::max(maxSize, vec.size());
224 for (
size_t i = 0; i < vecs.size(); i++) {
225 oss << std::left << std::setw(10) <<
"Vector" + std::to_string(i + 1);
228 oss << std::string(vecs.size() * 10,
'-') << std::endl;
230 for (
size_t i = 0; i < maxSize; i++) {
231 for (
const auto &vec : vecs) {
233 if (i < vec.size()) {
234 oss << std::left << std::setw(10) << vec[i];
236 oss << std::left << std::setw(10) <<
"NaN";
244 template <
typename T>
void printVectors(
const std::vector<std::vector<T>> &vecs) {
246 for (
const auto &vec : vecs) {
247 maxSize = std::max(maxSize, vec.size());
251 for (
size_t i = 0; i < vecs.size(); i++) {
252 std::cout << std::left << std::setw(10) <<
"Vector" + std::to_string(i + 1);
254 std::cout << std::endl;
255 std::cout << std::string(vecs.size() * 10,
'-') << std::endl;
257 for (
size_t i = 0; i < maxSize; i++) {
258 for (
const auto &vec : vecs) {
260 if (i < vec.size()) {
261 std::cout << std::left << std::setw(10) << vec[i];
263 std::cout << std::left << std::setw(10) <<
"NaN";
266 std::cout << std::endl;
270 template <
typename T>
void printVectors(
const std::vector<Date> &vec1,
const std::vector<T> &vec2) {
271 size_t maxSize = std::max(vec1.size(), vec2.size());
274 std::cout << std::left << std::setw(30) <<
"Date1"
275 <<
"| Date2" << std::endl;
276 std::cout <<
"--------------------------------------------------" << std::endl;
278 for (
size_t i = 0; i < maxSize; i++) {
280 if (i < vec1.size()) {
281 std::cout << std::left << std::setw(30) << vec1[i].toString(
Date::ISO) <<
"| ";
283 std::cout << std::left << std::setw(30) <<
"NaN"
288 if (i < vec2.size()) {
289 std::cout << vec2[i] << std::endl;
291 std::cout <<
"NaN" << std::endl;
static const int MAX_ARIMA_EXTRAPOLATION
Definition: ARIMAutils.h:28
static const int MIN_ARIMA_DATA_POINTS
Definition: ARIMAutils.h:27
static const double DATE_TOLERANCE
Definition: ARIMAutils.h:26
Definition: ARIMAutils.h:52
Mode getMode()
Definition: ARIMAutils.h:64
Normalization()
Definition: ARIMAutils.cc:30
std::vector< double > normalize(const std::vector< double > &data)
Definition: ARIMAutils.cc:36
std::vector< double > denormalize(const std::vector< double > &data)
Definition: ARIMAutils.cc:50
Mode
Definition: ARIMAutils.h:54
@ ZScore
Definition: ARIMAutils.h:56
@ MinMax
Definition: ARIMAutils.h:55
@ Nothing
Definition: ARIMAutils.h:57
void setMode(Mode new_mode)
Definition: ARIMAutils.h:63
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
const std::string toString(const FORMATS &type, const bool &gmt=false) const
Return a nicely formated string.
Definition: Date.cc:1120
@ ISO
ISO 8601 extended format combined date: YYYY-MM-DDTHH:mm:SS.sss (fields might be dropped,...
Definition: Date.h:91
size_t searchForward(ARIMA_GAP &last_gap, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_window_size, const size_t &indexP1)
Definition: ARIMAutils.cc:191
double stdDev(const std::vector< double > &vec)
Definition: ARIMAutils.cc:96
void computeARIMAGap(ARIMA_GAP &last_gap, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, size_t &indexP1, size_t &indexP2, double &before_window, double &after_window, double &window_size, Date &data_start_date, Date &data_end_date)
Definition: ARIMAutils.cc:277
std::vector< double > decideDirection(const std::vector< double > &data, const std::string &direction, bool forward, size_t gap_loc, size_t length)
Definition: ARIMAutils.cc:125
static Date findFirstDateWithSamplingRate(const std::vector< MeteoData > &vecM, const double sampling_rate, const Date &data_start_date, const Date &data_end_date)
Definition: ARIMAutils.cc:332
double calcVecMean(const std::vector< double > &vec)
Definition: ARIMAutils.cc:91
std::vector< double > slice(const std::vector< double > &vec, size_t start, size_t N)
Definition: ARIMAutils.cc:66
size_t searchBackward(ARIMA_GAP &last_gap, const size_t &pos, const size_t ¶mindex, const std::vector< MeteoData > &vecM, const Date &resampling_date, const double &i_window_size)
Definition: ARIMAutils.cc:143
std::vector< double > toVector(const std::vector< MeteoData > &vecM, const std::string ¶mname)
Definition: ARIMAutils.cc:106
std::vector< double > arange(size_t start, size_t N)
Definition: ARIMAutils.cc:82
std::string convertVectorsToString(const std::vector< std::vector< T > > &vecs)
Definition: ARIMAutils.h:216
Date adjustStartDate(const std::vector< MeteoData > &vecM, const ARIMA_GAP &last_gap, Date data_start_date, const Date &data_end_date)
Definition: ARIMAutils.cc:349
OptimizationMethod
Definition: ARIMAutils.h:39
@ Conjugate_Gradient
Definition: ARIMAutils.h:44
@ LBFGS
Definition: ARIMAutils.h:46
@ Newton_Trust_Region_Hook_Step
Definition: ARIMAutils.h:42
@ Newton_Trust_Region_Double_Dog_Leg
Definition: ARIMAutils.h:43
@ BFGS_MTM
Definition: ARIMAutils.h:47
@ Nelder_Mead
Definition: ARIMAutils.h:40
@ Newton_Line_Search
Definition: ARIMAutils.h:41
@ BFGS
Definition: ARIMAutils.h:45
ObjectiveFunction
Definition: ARIMAutils.h:34
@ MLE
Definition: ARIMAutils.h:36
@ CSS_MLE
Definition: ARIMAutils.h:35
@ CSS
Definition: ARIMAutils.h:37
std::vector< T > reverseVectorReturn(const std::vector< T > &vec)
Definition: ARIMAutils.h:119
void reverseVector(std::vector< T > &vec)
Definition: ARIMAutils.h:104
double computeSamplingRate(Date data_start_date, Date data_end_date, std::vector< MeteoData > vecM)
Definition: ARIMAutils.cc:316
T findMinMax(const std::vector< T > &vec, bool findMin)
Definition: ARIMAutils.h:85
void printVectors(const std::vector< std::vector< T > > &vecs)
Definition: ARIMAutils.h:244
double mostLikelyValue(const std::vector< double > &vec)
Definition: ARIMAutils.cc:301
bool requal(const Date &date1, const Date &date2)
Definition: ARIMAutils.cc:248
static const double e
Definition: Meteoconst.h:68
const size_t npos
npos is the out-of-range value
Definition: IOUtils.h:80
static double forward(double x, const std::vector< double > ¶ms, EditingRegFill::RegressionType regtype)
Definition: DataEditingAlgorithms.cc:1007
Definition: ARIMAutils.h:147
ARIMA_GAP()
Definition: ARIMAutils.h:148
void setEnd(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ARIMAutils.h:161
Date endDate
Definition: ARIMAutils.h:174
bool isGap()
Definition: ARIMAutils.h:176
void extend(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ARIMAutils.h:149
std::string toString() const
Definition: ARIMAutils.h:179
void setStart(const size_t &idx, const std::vector< MeteoData > &vecM)
Definition: ARIMAutils.h:155
size_t end
Definition: ARIMAutils.h:173
Date startDate
Definition: ARIMAutils.h:174
void reset()
Definition: ARIMAutils.h:167
double sampling_rate
Definition: ARIMAutils.h:175
size_t start
Definition: ARIMAutils.h:173