-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce.py
88 lines (73 loc) · 2.89 KB
/
reduce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
"""
Writters:
Aristi Papstavrou
Vissarion Moutafis
Time Series Forecasting using tensorflow lstm models.
usage:
~$ python reduce.py [-h] [-d DATASET_PATH] [-q QUERY_PATH] [-od OUTPUT_DATASET_PATH] [-q QUERY_PATH]
"""
import pandas as pd
from scipy.sparse import data
from src.ArgParser import *
from src.TimeSeriesCNNAutoEncoderFramework import *
from config.reduce_config import *
def main():
# create the needed parser
cmd_args = create_hyperparameter_parser(3)
train_mode = cmd_args.train
MODEL_PATH = cmd_args.model_path+'reduce' # set model path
n_samples = N_TRAINING_SAMPLES
input_dataset_path = cmd_args.dataset_path
query_dataset_path = cmd_args.query_set
output_query = cmd_args.output_query_path
output_input = cmd_args.output_path
# get the timeseries sample in a pandas dataframe
timeseries_input_df = (
pd.read_csv(input_dataset_path, sep="\t", index_col=0, header=None)
.astype(np.float32)
)
timeseries_query_df = (
pd.read_csv(query_dataset_path, sep="\t", index_col=0, header=None)
.astype(np.float32)
)
# get the indices in a list
train_timeseries_dataset = timeseries_input_df.sample(n_samples)
TIME_SERIES_TRAIN_ID = train_timeseries_dataset.index.tolist()
TIME_SERIES_INPUT_ID = timeseries_input_df.index.tolist()
TIME_SERIES_QUERY_ID = timeseries_query_df.index.tolist()
if train_mode:
# create the timeseries prediction model
autoencoder = TimeSeriesComplexityReducerModel(
LOOKBACK,
CNN_LAYER_SETTINGS,
latent_dim=LATENT_DIM,
pool_size=POOL_SIZE,
dropout_rate=DROPOUT_RATE,
_loss=LOSS,
verbose=True)
# create the problem statement
problem=TimeSeriesComplexityReducer(autoencoder, train_timeseries_dataset.to_numpy(), TIME_SERIES_TRAIN_ID)
# solve the problem
problem.solve(epochs=EPOCHS, batch_size=BATCH_SIZE)
# save model for later use
autoencoder.save_solver(MODEL_PATH)
else:
# create the timeseries prediction model
autoencoder = TimeSeriesComplexityReducerModel(
LOOKBACK,
CNN_LAYER_SETTINGS,
latent_dim=LATENT_DIM,
pool_size=POOL_SIZE,
dropout_rate=DROPOUT_RATE,
_loss=LOSS,
trained_model_path=MODEL_PATH)
# create the problem statement
problem = TimeSeriesComplexityReducer(
autoencoder, train_timeseries_dataset.to_numpy(), TIME_SERIES_TRAIN_ID)
#create compressed input data
problem.create_compressed_file(timeseries_input_df.to_numpy(),TIME_SERIES_INPUT_ID, output_input)
#create compressed query file
problem.create_compressed_file(timeseries_query_df.to_numpy(), TIME_SERIES_QUERY_ID, output_query)
if __name__ == "__main__":
main()