forked from jsyoon0823/TimeGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsine_generation_univariate.py
71 lines (54 loc) · 1.73 KB
/
sine_generation_univariate.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
## Necessary packages
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import numpy as np
import pandas as pd
import datetime
import time
import json
import warnings
warnings.filterwarnings("ignore")
# 1. TimeGAN model
from timegan import timegan
# 2. Data loading
from data_loading import real_data_loading, sine_data_generation, sine_data_loading
# get the start time
st = time.time()
## Newtork parameters
parameters = dict()
parameters['module'] = 'gru'
parameters['hidden_dim'] = 24
parameters['num_layer'] = 3
parameters['batch_size'] = 128
## Data loading
data_name = 'sine'
seq_len = 200
n_samples = 10000
n_iterations_list = [1000, 10000, 50000]
dim = 1
for n_iterations in n_iterations_list:
ori_data = sine_data_loading(n_samples, dim, seq_len)
print(data_name + ' dataset is ready.')
# Run TimeGAN
parameters['iterations'] = n_iterations
generated_data = timegan(ori_data, parameters, reproduce=False)
print('Finish Synthetic Data Generation')
# Save generated data to csv
x = datetime.datetime.now()
timestamp = x.strftime("%d%m%y_%Hh%M")
# generated_df = list_to_df(generated_data)
filepath = f'synthetic_sines/syn_sine_{n_iterations}_{dim}_{seq_len}_{timestamp}.json'
with open(filepath, 'w') as file:
json.dump(generated_data.tolist(), file)
# generated_df.to_csv(f'{filepath}.csv')
# generated_df.to_csv(f'{filepath}_indexless.csv', index=False)
# get the end time
et = time.time()
# get the execution time
elapsed_time = et - st
h = round(elapsed_time//(60*60), 0)
m = round((elapsed_time - h*(60*60))//60, 0)
s = round(elapsed_time - h*(60*60) - m*60,1)
print(f'Execution time: {h}h{m}m{s}s')