-
Notifications
You must be signed in to change notification settings - Fork 10
/
tests.py
93 lines (84 loc) · 2.67 KB
/
tests.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
89
90
91
92
93
import numpy as np
import train
def do_training():
data = np.load('euler.npy')
data = data.reshape(data.shape[0], -1)
data_mean = np.mean(data, axis=0)
data_std = np.std(data, axis=0)
idxs = np.where(data_std > 0)[0]
data_mean = data_mean[idxs]
data_std = data_std[idxs]
data = (data[:, idxs] - data_mean) / data_std
n_features = data.shape[-1]
batch_size = 100
sequence_length = 60
input_embed_size = None
n_neurons = 1024
n_layers = 3
n_gaussians = 20
use_attention = True
use_mdn = True
n_epochs = 5000
model_name = 'seq2seq-20-gaussians-3x1024'
restore_name = 'seq2seq-20-gaussians-3x1024-999'
train.train(
data=data,
data_mean=data_mean,
data_std=data_std,
batch_size=batch_size,
sequence_length=sequence_length,
n_features=n_features,
input_embed_size=input_embed_size,
n_neurons=n_neurons,
n_layers=n_layers,
n_gaussians=n_gaussians,
use_attention=use_attention,
use_mdn=use_mdn,
n_epochs=n_epochs,
model_name=model_name,
restore_name=restore_name)
def do_inference():
data = np.load('euler.npy')
data = data.reshape(data.shape[0], -1)
data_mean = np.mean(data, axis=0)
data_std = np.std(data, axis=0)
idxs = np.where(data_std > 0)[0]
data_mean = data_mean[idxs]
data_std = data_std[idxs]
data = (data[:, idxs] - data_mean) / data_std
n_features = data.shape[-1]
sequence_length = 60
input_embed_size = None
n_neurons = 1024
n_layers = 3
n_gaussians = 20
use_attention = True
use_mdn = True
restore_name = 'seq2seq_20-gaussians_3x1024_60-sequence-length_epoch-999'
batch_size = 1
offset = 0
source = data[offset:offset + sequence_length * batch_size, :].reshape(
batch_size, sequence_length, -1)
target = data[offset + sequence_length * batch_size:offset + sequence_length * batch_size * 2, :].reshape(
batch_size, sequence_length, -1)
res = train.infer(
source=source,
target=target,
data_mean=data_mean,
data_std=data_std,
batch_size=batch_size,
sequence_length=sequence_length,
n_features=n_features,
input_embed_size=input_embed_size,
n_neurons=n_neurons,
n_layers=n_layers,
n_gaussians=n_gaussians,
use_attention=use_attention,
use_mdn=use_mdn,
model_name=restore_name)
np.save('source.npy', res['source'])
np.save('target.npy', res['target'])
np.save('encoding.npy', res['encoding'])
np.save('prediction.npy', res['prediction'])
if __name__ == '__main__':
do_training()