-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Fuest
committed
Oct 3, 2024
1 parent
f747c70
commit 1630e7e
Showing
10 changed files
with
154 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import torch | ||
from torch.utils.data import Dataset | ||
|
||
|
||
class TimeSeriesDataset(Dataset): | ||
def __init__(self, dataframe, time_series_column_name, conditioning_vars=None): | ||
""" | ||
Initializes the TimeSeriesDataset. | ||
Args: | ||
dataframe (pd.DataFrame): The input DataFrame containing the time series data and optional conditioning variables. | ||
time_series_column_name (str): The name of the column containing the time series data. | ||
conditioning_vars (list of str, optional): List of column names to be used as conditioning variables. | ||
""" | ||
self.data = dataframe.reset_index(drop=True) | ||
self.conditioning_vars = conditioning_vars or [] | ||
self.time_series_column_name = time_series_column_name | ||
|
||
if self.time_series_column_name not in self.data.columns: | ||
raise ValueError( | ||
f"Time series column '{self.time_series_column_name}' not found in DataFrame." | ||
) | ||
|
||
for var in self.conditioning_vars: | ||
if var not in self.data.columns: | ||
raise ValueError( | ||
f"Conditioning variable '{var}' not found in DataFrame." | ||
) | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
def __getitem__(self, idx): | ||
time_series = self.data.iloc[idx][self.time_series_column] | ||
time_series = torch.tensor(time_series, dtype=torch.float32) | ||
|
||
conditioning_vars_dict = {} | ||
for var in self.conditioning_vars: | ||
value = self.data.iloc[idx][var] | ||
conditioning_vars_dict[var] = torch.tensor(value, dtype=torch.long) | ||
|
||
return time_series, conditioning_vars_dict |
Oops, something went wrong.