OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
time_series_dataset.h
Go to the documentation of this file.
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// T I M E S E R I E S D A T A S E T C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
14
15#pragma once
16
17#include "dataset.h"
18
19namespace opennn
20{
21
32class TimeSeriesDataset final : public Dataset
33{
34
35public:
36
43 TimeSeriesDataset(const Index samples_number = 0,
44 const Shape& input_shape = {},
45 const Shape& target_shape = {});
46
55 TimeSeriesDataset(const filesystem::path& path,
56 const string& separator,
57 bool has_header = true,
58 bool has_sample_index = false,
60
65 void fill_gaps();
66
68 Index get_past_time_steps() const;
70 Index get_future_time_steps() const;
74 bool get_multi_target() const;
75
82 Tensor3 get_data(const string& sample_role, const string& feature_role) const;
83
89 void set_past_time_steps(const Index);
95 void set_future_time_steps(const Index);
101 void set_time_variable_index(const Index);
107 void set_multi_target(const bool);
108
114 MatrixR calculate_autocorrelations(const Index maximum_lag = 10) const;
120 Tensor3 calculate_cross_correlations(const Index maximum_lag = 10) const;
126 Tensor3 calculate_cross_correlations_spearman(const Index maximum_lag = 10) const;
127
131 void to_JSON(JsonWriter&) const override;
135 void from_JSON(const JsonDocument&) override;
136
138 void read_csv() override;
139
144
152 void fill_inputs(const vector<Index>&,
153 const vector<Index>&,
154 float*,
155 bool = true,
156 int contiguous = -1) const override;
157
165 void fill_targets(const vector<Index>&,
166 const vector<Index>&,
167 float*,
168 bool = true,
169 int contiguous = -1) const override;
170
171private:
172
174 Index past_time_steps = 2;
175
177 Index future_time_steps = 1;
178
180 bool multi_target = false;
181
183 Index time_variable_index = 0;
184};
185
186}
187
188// OpenNN: Open Neural Networks Library.
189// Copyright(C) 2005-2026 Artificial Intelligence Techniques, SL.
190// Licensed under the GNU Lesser General Public License v2.1 or later.
Codification codification
Source-file character encoding.
Definition dataset.h:1354
bool has_header
Whether the source file's first row contains column names.
Definition dataset.h:1348
Shape target_shape
Shape of the target portion.
Definition dataset.h:1317
Codification
Source-file character encoding.
Definition dataset.h:116
@ UTF8
Definition dataset.h:116
Separator separator
Field separator used in the source file.
Definition dataset.h:1340
Dataset(const Index samples_number=0, const Shape &input_shape={0}, const Shape &target_shape={0})
Constructs an empty dataset of given dimensions.
Shape input_shape
Shape of the input portion (rank may exceed 1 for image/sequence data).
Definition dataset.h:1315
Definition json.h:71
Definition json.h:84
MatrixR calculate_autocorrelations(const Index maximum_lag=10) const
Computes the autocorrelation function of every variable.
TimeSeriesDataset(const filesystem::path &path, const string &separator, bool has_header=true, bool has_sample_index=false, const Codification &codification=Codification::UTF8)
Constructs a TimeSeriesDataset by loading from a CSV file.
Tensor3 calculate_cross_correlations(const Index maximum_lag=10) const
Computes the Pearson cross-correlation between every variable pair.
void set_future_time_steps(const Index)
Sets the forecast horizon.
void fill_inputs(const vector< Index > &, const vector< Index > &, float *, bool=true, int contiguous=-1) const override
Fills the input batch buffer with past-window data.
void impute_missing_values_interpolate() override
Imputes missing values via temporal interpolation.
Index get_time_variable_index() const
Column index of the time variable.
void set_multi_target(const bool)
Sets whether the dataset has more than one target variable.
void to_JSON(JsonWriter &) const override
Writes dataset metadata (windows, time variable) to JSON.
void from_JSON(const JsonDocument &) override
Loads dataset metadata (windows, time variable) from JSON.
void set_past_time_steps(const Index)
Sets the input window length.
Index get_future_time_steps() const
Number of future time steps used as targets.
void read_csv() override
Reads time-series rows from the configured CSV file.
void set_time_variable_index(const Index)
Sets the column index of the time variable.
void impute_missing_values_unuse() override
Marks rows with missing values as None (excluded from training).
Tensor3 calculate_cross_correlations_spearman(const Index maximum_lag=10) const
Computes the Spearman cross-correlation between every variable pair.
void fill_gaps()
Fills missing time steps with imputed rows so the time variable becomes evenly spaced.
TimeSeriesDataset(const Index samples_number=0, const Shape &input_shape={}, const Shape &target_shape={})
Constructs an empty TimeSeriesDataset of given dimensions.
bool get_multi_target() const
Whether the dataset has more than one target variable.
Index get_past_time_steps() const
Number of past time steps used as inputs.
void fill_targets(const vector< Index > &, const vector< Index > &, float *, bool=true, int contiguous=-1) const override
Fills the target batch buffer with future-window data.
Tensor3 get_data(const string &sample_role, const string &feature_role) const
Returns the data tensor for the given sample / feature roles.
Declares the Dataset class and the SampleRole enum.
Definition adaptive_moment_estimation.h:19
Matrix< float, Dynamic, Dynamic, Layout > MatrixR
Definition neural_network.h:152
Tensor< float, 3, Layout|AlignedMax > Tensor3
Definition neural_network.h:165
Definition tensor_utilities.h:46