-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.py
63 lines (54 loc) · 2.11 KB
/
main.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
import model
import utils
import numpy as np
if __name__ == "__main__":
# ------------------------------ DATA -----------------------------------
dataset = input("Enter dataset (FD001, FD002, FD003, FD004): ")
# sensors to work with: T30, T50, P30, PS30, phi
sensors = ['s_3', 's_4', 's_7', 's_11', 's_12']
# windows length
sequence_length = 30
# smoothing intensity
alpha = 0.1
# max RUL
threshold = 125
x_train, y_train, x_val, y_val, x_test, y_test = utils.get_data(dataset, sensors,
sequence_length, alpha, threshold)
# -----------------------------------------------------------------------
# ----------------------------- MODEL -----------------------------------
timesteps = x_train.shape[1]
input_dim = x_train.shape[2]
intermediate_dim = 300
batch_size = 128
latent_dim = 2
epochs = 10000
optimizer = 'adam'
RVE = model.create_model(timesteps,
input_dim,
intermediate_dim,
batch_size,
latent_dim,
epochs,
optimizer,
)
# Callbacks for training
model_callbacks = utils.get_callbacks(RVE, x_train, y_train)
# -----------------------------------------------------------------------
# --------------------------- TRAINING ---------------------------------
results = RVE.fit(x_train, y_train,
shuffle=True,
epochs=epochs,
batch_size=batch_size,
validation_data= (x_val, y_val),
callbacks=model_callbacks, verbose=2)
# -----------------------------------------------------------------------
# -------------------------- EVALUATION ---------------------------------
RVE.load_weights('./checkpoints/checkpoint')
train_mu = utils.viz_latent_space(RVE.encoder, np.concatenate((x_train, x_val)), np.concatenate((y_train, y_val)))
test_mu = utils.viz_latent_space(RVE.encoder, x_test, y_test.clip(upper=threshold))
# Evaluate
y_hat_train = RVE.regressor.predict(train_mu)
y_hat_test = RVE.regressor.predict(test_mu)
utils.evaluate(np.concatenate((y_train, y_val)), y_hat_train, 'train')
utils.evaluate(y_test, y_hat_test, 'test')
# -----------------------------------------------------------------------