-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_dyn.py
350 lines (345 loc) · 11 KB
/
run_dyn.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import pandas as pd
import numpy as np
import os
import re
import time
import keras
from sklearn.utils import shuffle
from sklearn.model_selection import train_test_split
from numpy import array
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Flatten
from keras.layers import Activation
from keras.layers.convolutional import Conv1D
from keras.layers.convolutional import MaxPooling1D
from hyperopt import Trials, STATUS_OK, tpe
from hyperas import optim
from hyperas.distributions import choice, uniform
# load the trained model
model = keras.models.load_model('../model-404-tloss-2.623e-07-vloss-2.321e-07.hdf5')
#Show the model architecture
model.summary()
# path to the directory where the training trajectories are stored
gamma = np.load('gamma.npy')
lamb = np.load('lambda.npy')
temp = np.load('temperature.npy')
initial = np.load('initial_site.npy')
gamma, lamb, temp, initial = shuffle(gamma, lamb, temp, initial)
num_trajs = len(gamma)
gamma_1 = np.zeros((num_trajs), dtype=float)
lamb_1 = np.zeros((num_trajs), dtype=float)
temp_1 = np.zeros((num_trajs), dtype=float)
init_1 = np.zeros((num_trajs), dtype=int)
gamma_1[:] = gamma[:]
lamb_1[:] = lamb[:]
temp_1[:] = temp[:]
init_1[:] = initial[:]
# Normalize values range of gamma, lambda and temperature ...
# by dividing each value by the maximum value in that range
#
tt_M = 200001 #t_M[f]
j=0
for i in lamb:
lamb[j] = i/310
j=j+1
j=0
for i in gamma:
gamma[j] = i/300
j=j+1
j=0
for i in temp:
temp[j] = i/310
j=j+1
# Define logistic function
#
def logistic(x,c):
a=1
b=15
d=1
f= a/(1 + b * np.exp(-(x-c)/d))
return f
# We have seven sites and as a label we use ...
# values between 0 and 1
#
states = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
#
red_times = 100
t = np.arange(0,200001)*0.005 # 500ps
tt = np.zeros((len(t), red_times), dtype=float)
u = 0
for i in t:
c = -1.0
for j in range(0, red_times):
tt[u,j]=logistic(i,c)
c = c + 5
u=u + 1
# normalizing the time feature using logistic function
#
time_steps = np.arange(0,tt.shape[0]) * 5.0
m = 0
for f in range(0, num_trajs):
#print(files[f], t_M[f]) # print trajectory and the corresponding time-length for it
if f ==0:
if tt_M <= 201:
for i in range(0,tt_M):
m = m + 1
if tt_M > 201 and tt_M <= 301:
for i in range(0,201):
m = m + 1
for i in range(202,tt_M, 2):
m = m + 1
if tt_M > 301 and tt_M <= 501:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,tt_M, 5):
m = m + 1
if tt_M > 501 and tt_M <= 1001:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,501, 5):
m = m + 1
for i in range(510,tt_M, 10):
m = m + 1
if tt_M > 1001 and tt_M <= 5001:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,501, 5):
m = m + 1
for i in range(510,1001, 10):
m = m + 1
for i in range(1020,tt_M, 20):
m = m + 1
if tt_M > 5001 and tt_M <= 10001:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,501, 5):
m = m + 1
for i in range(510,1001, 10):
m = m + 1
for i in range(1020,5001, 20):
m = m + 1
for i in range(5040,tt_M, 40):
m = m + 1
if tt_M > 10001 and tt_M <= 50001:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,501, 5):
m = m + 1
for i in range(510,1001, 10):
m = m + 1
for i in range(1020,5001, 20):
m = m + 1
for i in range(5040,10001, 40):
m = m + 1
for i in range(10100,tt_M, 100):
m = m + 1
if tt_M > 50001:
for i in range(0,201):
m = m + 1
for i in range(202,301, 2):
m = m + 1
for i in range(305,501, 5):
m = m + 1
for i in range(510,1001, 10):
m = m + 1
for i in range(1020,5001, 20):
m = m + 1
for i in range(5040,10001, 40):
m = m + 1
for i in range(10100,50001, 100):
m = m + 1
for i in range(50200,tt_M, 200):
m = m + 1
x = np.zeros((m, 5+red_times), dtype=float)
y = np.zeros((m,7*13), dtype=float)
tf = np.zeros((m,1), dtype = float)
#m = m + 1 # include the t -> infinity
# m is the total number of training points
m = 0
if initial[f] == 1:
init_index = 0 # use 0 as a label for initial excitation on site-1
else:
init_index = 1 # use 1 as a label for initial excitation on site-6
x[:,0] = init_index
x[:,2] = gamma[f]
x[:,3] = lamb[f]
x[:,4] = temp[f]
if tt_M <= 201:
for i in range(0,tt_M):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 201 and tt_M <= 301:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,tt_M, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 301 and tt_M <= 501:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,tt_M, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 501 and tt_M <= 1001:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,501, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(510,tt_M, 10):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 1001 and tt_M <= 5001:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,501, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(510,1001, 10):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(1020,tt_M, 20):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 5001 and tt_M <= 10001:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,501, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(510,1001, 10):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(1020,5001, 20):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(5040,tt_M, 40): # 200fs
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 10001 and tt_M <= 50001:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,501, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(510,1001, 10):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(1020,5001, 20):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(5040,10001, 40): # 200fs
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(10100,tt_M, 100): #500fs
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
if tt_M > 50001:
for i in range(0,201):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(202,301, 2):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(305,501, 5):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(510,1001, 10):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(1020,5001, 20):
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(5040,10001, 40): # 200fs
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(10100,50001, 100): #500fs
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
for i in range(50200,tt_M, 200): # 1ps
x[m,5:x.shape[1]] = tt[i,:]
tf[m,0] = time_steps[i]
m = m + 1
sn1 = 0
sn2 = 13
start_time = time.time()
for s in states:
x[:,1] = s
for i in range(0, x.shape[0]):
x_pred = x[i,:]
x_pred = x_pred.reshape(1, x.shape[1],1) # reshape the input
yhat = model.predict(x_pred, verbose=0)
y[i,sn1:sn2] = yhat
sn1 = sn1 + 13
sn2 = sn2 + 13
print("--- %s seconds ---" % (time.time() - start_time))
print("trejectory ",f," predicted")
filename = "pred_initial-" + str(init_1[f]) + "_wc-" + str(int(gamma_1[f])) + "_lambda-" + str(int(lamb_1[f])) + "_temp-" + str(int(temp_1[f])) + ".dat"
np.savetxt(filename, np.r_['-1',tf, y])