-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
656 lines (458 loc) · 20.2 KB
/
models.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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
import numpy as np
import os
from hill_functions import *
#from hill_functions import *
"""
###
RELEVANT CODE FOR NPMP
###
"""
# MASTER-SLAVE D FLIP-FLOP MODEL
def ff_ode_model(Y, T, params):
a, not_a, q, not_q, d, clk = Y
if isinstance(params, dict):
alpha1 = params["alpha1"]
alpha2 = params["alpha2"]
alpha3 = params["alpha3"]
alpha4 = params["alpha4"]
delta1 = params["delta1"]
delta2 = params["delta2"]
Kd = params["Kd"]
n = params["n"]
else:
alpha1, alpha2, alpha3, alpha4, delta1, delta2, Kd, n = params
da_dt = alpha1*(pow(d/Kd, n)/(1 + pow(d/Kd, n) + pow(clk/Kd, n) + pow(d/Kd, n)*pow(clk/Kd, n))) + alpha2*(1/(1 + pow(not_a/Kd, n))) - delta1 *a
dnot_a_dt = alpha1*(1/(1 + pow(d/Kd, n) + pow(clk/Kd, n) + pow(d/Kd, n)*pow(clk/Kd, n))) + alpha2*(1/(1 + pow(a/Kd, n))) - delta1*not_a
dq_dt = alpha3*((pow(a/Kd, n)*pow(clk/Kd, n))/(1 + pow(a/Kd, n) + pow(clk/Kd, n) + pow(a/Kd, n)*pow(clk/Kd, n))) + alpha4*(1/(1 + pow(not_q/Kd, n))) - delta2*q
dnot_q_dt = alpha3*((pow(not_a/Kd, n)*pow(clk/Kd, n))/(1 + pow(not_a/Kd, n) + pow(clk/Kd, n) + pow(not_a/Kd, n)*pow(clk/Kd, n))) + alpha4*(1/(1 + pow(q/Kd, n))) - delta2*not_q
# Check if theres nan values
#brez tega, temporary clock disable ni delu
if np.isnan(da_dt):
da_dt = 0
if np.isnan(dnot_a_dt):
dnot_a_dt = 0
if np.isnan(dq_dt):
dq_dt = 0
if np.isnan(dnot_q_dt):
dnot_q_dt = 0
return np.array([da_dt, dnot_a_dt, dq_dt, dnot_q_dt])
"""
JOHSON COUNTER MODELS
"""
# TOP MODEL (JOHNSON): ONE BIT MODEL WITH EXTERNAL CLOCK
def one_bit_model(Y, T, params):
a, not_a, q, not_q= Y
clk = get_clock(T)
d = not_q
Y_FF1 = [a, not_a, q, not_q, d, clk]
dY = ff_ode_model(Y_FF1, T, params)
return dY
# TOP MODEL (JOHNSON): TWO BIT MODEL WITH EXTERNAL CLOCK
def two_bit_model(Y, T, params):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2 = Y
clk = get_clock(T)
d1 = not_q2
d2 = q1
Y_FF1 = [a1, not_a1, q1, not_q1, d1, clk]
Y_FF2 = [a2, not_a2, q2, not_q2, d2, clk]
dY1 = ff_ode_model(Y_FF1, T, params)
dY2 = ff_ode_model(Y_FF2, T, params)
dY = np.append(dY1, dY2)
return dY
# TOP MODEL (JOHNSON): THREE BIT MODEL WITH EXTERNAL CLOCK
def three_bit_model(Y, T, params):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3 = Y
clk = get_clock(T)
d1 = not_q3
d2 = q1
d3 = q2
Y_FF1 = [a1, not_a1, q1, not_q1, d1, clk]
Y_FF2 = [a2, not_a2, q2, not_q2, d2, clk]
Y_FF3 = [a3, not_a3, q3, not_q3, d3, clk]
dY1 = ff_ode_model(Y_FF1, T, params)
dY2 = ff_ode_model(Y_FF2, T, params)
dY3 = ff_ode_model(Y_FF3, T, params)
dY = np.append(np.append(dY1, dY2), dY3)
return dY
def xor(in1, in2, Kd, n):
return hybrid(in1,in2, Kd, n, Kd, n) + hybrid(in2,in1, Kd, n, Kd, n)
def xnor(A1, A2, Kd, n):
# Implementing XNOR as (A AND B) OR (NOT A AND NOT B)
and_gate = activate_2(A1, A2, Kd, n)
nor_gate = repress_2(A1, A2, Kd, n)
return and_gate + nor_gate - and_gate * nor_gate
def counter_model_2(Y, T, params_ff, inhibitor_value=0, set_number = 0):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2 = Y
alpha1, alpha2, alpha3, alpha4, delta1, delta2, Kd, n = params_ff
clk = modulated_clock(T, inhibitor_value, Kd, n)
if set_number != 0 and T < 10 :
bin_rep = format(set_number, '02b')
for i in range(2):
func = induction if bin_rep[i] == '1' else inhibition
vars()[f'd{i+1}'] = alpha1 * func(vars()[f'q{i+1}'], 200, Kd, n)
else:
d1 = not_q1
d2 = alpha1 * xor(q1, q2, Kd, n)
Y1 = ff_ode_model([a1, not_a1, q1, not_q1, d1, clk], T, params_ff)
Y2 = ff_ode_model([a2, not_a2, q2, not_q2, d2, clk], T, params_ff)
return np.concatenate([Y1, Y2])
def counter_model_3(Y, T, params_ff, inhibitor_value=0, set_number = 0):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3 = Y
if isinstance(params_ff, dict):
alpha1 = params_ff["alpha1"]
alpha2 = params_ff["alpha2"]
alpha3 = params_ff["alpha3"]
alpha4 = params_ff["alpha4"]
delta1 = params_ff["delta1"]
delta2 = params_ff["delta2"]
Kd = params_ff["Kd"]
n = params_ff["n"]
else:
alpha1, alpha2, alpha3, alpha4, delta1, delta2, Kd, n = params_ff
clk = modulated_clock(T, inhibitor_value, Kd, n)
if set_number != 0 and T < 12 :
bin_rep = format(set_number, '03b')
ds = []
for i in range(3):
q = [q1, q2, q3][i]
alpha = alpha1 # Assuming alpha1 is used for both conditions
function = induction if bin_rep[i] == '1' else inhibition
ds.append(alpha * function(q, 200, Kd, n))
d1, d2, d3 = ds
else:
d1 = not_q1
d2 = alpha1 * xor(q1, q2, Kd, n)
d3 = alpha1 * xor(alpha1 * activate_2(q1, q2, Kd, n), q3, Kd, n)
Y1 = ff_ode_model([a1, not_a1, q1, not_q1, d1, clk], T, params_ff)
Y2 = ff_ode_model([a2, not_a2, q2, not_q2, d2, clk], T, params_ff)
Y3 = ff_ode_model([a3, not_a3, q3, not_q3, d3, clk], T, params_ff)
return np.concatenate([Y1, Y2, Y3])
# TOP MODEL (JOHNSON): FOUR BIT MODEL WITH EXTERNAL CLOCK
def four_bit_model(Y, T, params):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, a4, not_a4, q4, not_q4 = Y
clk = get_clock(T)
d1 = not_q4
d2 = q1
d3 = q2
d4 = q3
Y_FF1 = [a1, not_a1, q1, not_q1, d1, clk]
Y_FF2 = [a2, not_a2, q2, not_q2, d2, clk]
Y_FF3 = [a3, not_a3, q3, not_q3, d3, clk]
Y_FF4 = [a4, not_a4, q4, not_q4, d4, clk]
dY1 = ff_ode_model(Y_FF1, T, params)
dY2 = ff_ode_model(Y_FF2, T, params)
dY3 = ff_ode_model(Y_FF3, T, params)
dY4 = ff_ode_model(Y_FF4, T, params)
dY = np.append(np.append(np.append(dY1, dY2), dY3), dY4)
return dY
"""
###
END OF RELEVANT CODE FOR NPMP
###
"""
"""
JOHSON COUNTER MODELS THAT USE FLIP-FLOPS WITH ASYNCRHONOUS SET/RESET
dodano 23. 1. 2020
"""
# TOP MODEL (JOHNSON): ONE BIT MODEL WITH EXTERNAL CLOCK AND FLIP-FLOPS WITH ASYNCRHONOUS SET/RESET
def one_bit_model_RS(Y, T, params):
a, not_a, q, not_q, R, S = Y
clk = get_clock(T)
d = not_q
Y_FF1 = [a, not_a, q, not_q, d, clk, R, S]
dY = ff_ode_model_RS(Y_FF1, T, params)
return dY
# TOP MODEL (JOHNSON): TWO BIT MODEL WITH EXTERNAL CLOCK AND FLIP-FLOPS WITH ASYNCRHONOUS SET/RESET
def two_bit_model_RS(Y, T, params):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, R1, S1, R2, S2 = Y
clk = get_clock(T)
d1 = not_q2
d2 = q1
Y_FF1 = [a1, not_a1, q1, not_q1, d1, clk, R1, S1]
Y_FF2 = [a2, not_a2, q2, not_q2, d2, clk, R2, S2]
dY1 = ff_ode_model_RS(Y_FF1, T, params)
dY2 = ff_ode_model_RS(Y_FF2, T, params)
dY = np.append(dY1, dY2)
return dY
# TOP MODEL (JOHNSON): THREE BIT MODEL WITH EXTERNAL CLOCK AND FLIP-FLOPS WITH ASYNCRHONOUS SET/RESET
def three_bit_model_RS(Y, T, params):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, R1, S1, R2, S2, R3, S3 = Y
clk = get_clock(T)
d1 = not_q3
d2 = q1
d3 = q2
Y_FF1 = [a1, not_a1, q1, not_q1, d1, clk, R1, S1]
Y_FF2 = [a2, not_a2, q2, not_q2, d2, clk, R2, S2]
Y_FF3 = [a3, not_a3, q3, not_q3, d3, clk, R3, S3]
dY1 = ff_ode_model_RS(Y_FF1, T, params)
dY2 = ff_ode_model_RS(Y_FF2, T, params)
dY3 = ff_ode_model_RS(Y_FF3, T, params)
dY = np.append(np.append(dY1, dY2), dY3)
return dY
"""
###
OTHER CODE
###
"""
"""
FLIP-FLOP MODELS
"""
# MASTER-SLAVE D FLIP-FLOP QSSA MODEL
def ff_stochastic_model(Y, T, params, omega):
p = np.zeros(12)
a, not_a, q, not_q, d, clk = Y
alpha1, alpha2, alpha3, alpha4, delta1, delta2, Kd, n = params
p[0] = alpha1*(pow(d/(Kd*omega), n)/(1 + pow(d/(Kd*omega), n) + pow(clk/(Kd*omega), n) + pow(d/(Kd*omega), n)*pow(clk/(Kd*omega), n)))*omega
p[1] = alpha2*(1/(1 + pow(not_a/(Kd*omega), n)))*omega
p[2] = delta1*a
p[3] = alpha1*(1/(1 + pow(d/(Kd*omega), n) + pow(clk/(Kd*omega), n) + pow(d/(Kd*omega), n)*pow(clk/(Kd*omega), n)))*omega
p[4] = alpha2*(1/(1 + pow(a/(Kd*omega), n)))*omega
p[5] = delta1*not_a
p[6] = alpha3*((pow(a/(Kd*omega), n)*pow(clk/(Kd*omega), n))/(1 + pow(a/(Kd*omega), n) + pow(clk/(Kd*omega), n) + pow(a/(Kd*omega), n)*pow(clk/(Kd*omega), n)))*omega
p[7] = alpha4*(1/(1 + pow(not_q/(Kd*omega), n)))*omega
p[8] = delta2*q
p[9] = alpha3*((pow(not_a/(Kd*omega), n)*pow(clk/(Kd*omega), n))/(1 + pow(not_a/(Kd*omega), n) + pow(clk/(Kd*omega), n) + pow(not_a/(Kd*omega), n)*pow(clk/(Kd*omega), n)))*omega
p[10] = alpha4*(1/(1 + pow(q/(Kd*omega), n)))*omega
p[11] = delta2*not_q
#propensities
return p
# FF MODEL WITH ASYNCHRONOUS RESET AND SET
# dodana parametra deltaE, KM
# dodani vhodni spremenljivki RESET in SET
# dodano 23. 1. 2020
def ff_ode_model_RS(Y, T, params):
a, not_a, q, not_q, d, clk, RESET, SET = Y
repress_both = True
if repress_both:
sum_one = a + q
sum_zero = not_a + not_q
alpha1, alpha2, alpha3, alpha4, delta1, delta2, Kd, n, deltaE, KM = params
da_dt = alpha1*(pow(d/Kd, n)/(1 + pow(d/Kd, n) + pow(clk/Kd, n) + pow(d/Kd, n)*pow(clk/Kd, n))) + alpha2*(1/(1 + pow(not_a/Kd, n))) - delta1 *a
#deltaE = delta1
if repress_both:
da_dt += -a*(deltaE*RESET/(KM+sum_one))
else:
da_dt += -a*(deltaE*RESET/(KM+a))
dnot_a_dt = alpha1*(1/(1 + pow(d/Kd, n) + pow(clk/Kd, n) + pow(d/Kd, n)*pow(clk/Kd, n))) + alpha2*(1/(1 + pow(a/Kd, n))) - delta1*not_a
if repress_both:
dnot_a_dt += -not_a*(deltaE*SET/(KM+sum_zero))
else:
dnot_a_dt += -not_a*(deltaE*SET/(KM+not_a))
#deltaE = delta2
dq_dt = alpha3*((pow(a/Kd, n)*pow(clk/Kd, n))/(1 + pow(a/Kd, n) + pow(clk/Kd, n) + pow(a/Kd, n)*pow(clk/Kd, n))) + alpha4*(1/(1 + pow(not_q/Kd, n))) - delta2*q
if repress_both:
dq_dt += -q*(deltaE*RESET/(KM+sum_one))
dnot_q_dt = alpha3*((pow(not_a/Kd, n)*pow(clk/Kd, n))/(1 + pow(not_a/Kd, n) + pow(clk/Kd, n) + pow(not_a/Kd, n)*pow(clk/Kd, n))) + alpha4*(1/(1 + pow(q/Kd, n))) - delta2*not_q
if repress_both:
dnot_q_dt += -not_q*(deltaE*SET/(KM+sum_zero))
return np.array([da_dt, dnot_a_dt, dq_dt, dnot_q_dt])
"""
ADRESSING MODELS
"""
# ADDRESSING 1-BIT QSSA MODEL
def addressing_stochastic_one_bit_model(Y, T, params, omega):
alpha, delta, Kd, n = params
_,_, q1, not_q1, i1, i2 = Y
p = np.zeros(4)
p[0] = alpha*activate_1(not_q1, Kd*omega, n)*omega
p[1] = delta*i1
p[2] = alpha*activate_1(q1, Kd*omega, n)*omega
p[3] = delta*i2
#propensities
return p
# ADDRESSING 2-BIT QSSA MODEL
def addressing_stochastic_two_bit_model(Y, T, params, omega):
alpha, delta, Kd, n = params
_, _, q1, not_q1, _, _, q2, not_q2, i1, i2, i3, i4 = Y
p = np.zeros(8)
p[0] = alpha * activate_2(not_q1, not_q2, Kd*omega, n)*omega
p[1] = delta * i1
p[2] = alpha * activate_2(q1, not_q2, Kd*omega, n)*omega
p[3] = delta * i2
p[4] = alpha * activate_2(q1, q2, Kd*omega, n)*omega
p[5] = delta * i3
p[6] = alpha * activate_2(not_q1, q2, Kd*omega, n)*omega
p[7] = delta * i4
#propensities
return p
# ADDRESSING 3-BIT QSSA MODEL
def addressing_stochastic_three_bit_model(Y, T, params, omega):
alpha, delta, Kd, n = params
_, _, q1, not_q1, _, _, q2, not_q2, _, _, q3, not_q3, i1, i2, i3, i4, i5, i6 = Y
p = np.zeros(12)
p[0] = alpha * activate_2(not_q1, not_q3, Kd*omega, n)*omega
p[1] = delta * i1
p[2] = alpha * activate_2(q1, not_q2, Kd*omega, n)*omega
p[3] = delta * i2
p[4] = alpha * activate_2(q2, not_q3, Kd*omega, n)*omega
p[5] = delta * i3
p[6] = alpha * activate_2(q1, q3, Kd*omega, n)*omega
p[7] = delta * i4
p[8] = alpha * activate_2(not_q1, q2, Kd*omega, n)*omega
p[9] = delta * i5
p[10] = alpha * activate_2(not_q2, q3, Kd*omega, n)*omega
p[11] = delta * i6
#propensities
return p
# ONE BIT ADDRESSING MODEL SIMPLE
def one_bit_simple_addressing_ode_model(Y, T, params):
alpha, delta, Kd, n = params
q1, not_q1, i1, i2 = Y
di1_dt = alpha * activate_1(not_q1, Kd, n) - delta * i1
di2_dt = alpha * activate_1(q1, Kd, n) - delta * i2
return np.array([di1_dt, di2_dt])
# TWO BIT ADDRESSING MODEL SIMPLE
def two_bit_simple_addressing_ode_model(Y, T, params):
alpha, delta, Kd, n = params
q1, not_q1, q2, not_q2, i1, i2, i3, i4 = Y
di1_dt = alpha * activate_2(not_q1, not_q2, Kd, n) - delta * i1
di2_dt = alpha * activate_2(q1, not_q2, Kd, n) - delta * i2
di3_dt = alpha * activate_2(q1, q2, Kd, n) - delta * i3
di4_dt = alpha * activate_2(not_q1, q2, Kd, n) - delta * i4
return np.array([di1_dt, di2_dt, di3_dt, di4_dt])
# THREE BIT ADDRESSING MODEL SIMPLE
def three_bit_simple_addressing_ode_model(Y, T, params):
alpha, delta, Kd, n = params
q1, not_q1, q2, not_q2, q3, not_q3, i1, i2, i3, i4, i5, i6 = Y
di1_dt = alpha * activate_2(not_q1, not_q3, Kd, n) - delta * i1
di2_dt = alpha * activate_2(q1, not_q2, Kd, n) - delta * i2
di3_dt = alpha * activate_2(q2, not_q3, Kd, n) - delta * i3
di4_dt = alpha * activate_2(q1, q3, Kd, n) - delta * i4
di5_dt = alpha * activate_2(not_q1, q2, Kd, n) - delta * i5
di6_dt = alpha * activate_2(not_q2, q3, Kd, n) - delta * i6
return np.array([di1_dt, di2_dt, di3_dt, di4_dt, di5_dt, di6_dt])
# FOUR BIT ADDRESSING MODEL SIMPLE
def four_bit_simple_addressing_ode_model(Y, T, params):
alpha, delta, Kd, n = params
q1, not_q1, q2, not_q2, q3, not_q3, q4, not_q4, i1, i2, i3, i4, i5, i6, i7, i8 = Y
di1_dt = alpha * activate_2(not_q1, not_q4, Kd, n) - delta * i1
di2_dt = alpha * activate_2(q1, not_q2, Kd, n) - delta * i2
di3_dt = alpha * activate_2(q2, not_q3, Kd, n) - delta * i3
di4_dt = alpha * activate_2(q3, not_q4, Kd, n) - delta * i4
di5_dt = alpha * activate_2(q1, q4, Kd, n) - delta * i5
di6_dt = alpha * activate_2(not_q1, q2, Kd, n) - delta * i6
di7_dt = alpha * activate_2(not_q2, q3, Kd, n) - delta * i7
di8_dt = alpha * activate_2(not_q3, q4, Kd, n) - delta * i8
return np.array([di1_dt, di2_dt, di3_dt, di4_dt, di5_dt, di6_dt, di7_dt, di8_dt])
"""
PROCESSOR MODEL
!!!OPTIMIZACIJA NAD TEMI MODELI!!!
"""
# TOP MODEL OF PROCESSOR WITH ONE BIT ADDRESSING
def one_bit_processor_ext(Y, T, params_johnson, params_addr):
a1, not_a1, q1, not_q1, i1, i2 = Y
Y_johnson = [a1, not_a1, q1, not_q1]
Y_address = [q1, not_q1, i1, i2]
dY_johnson = one_bit_model(Y_johnson, T, params_johnson)
dY_addr = one_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
# TOP MODEL OF PROCESSOR WITH TWO BIT ADDRESSING
def two_bit_processor_ext(Y, T, params_johnson, params_addr):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, i1, i2, i3, i4 = Y
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2]
Y_address = [q1, not_q1, q2, not_q2, i1, i2, i3, i4]
dY_johnson = two_bit_model(Y_johnson, T, params_johnson)
dY_addr = two_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
# TOP MODEL OF PROCESSOR WITH THREE BIT ADDRESSING
def three_bit_processor_ext(Y, T, params_johnson, params_addr):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, i1, i2, i3, i4, i5, i6 = Y
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3]
Y_address = [q1, not_q1, q2, not_q2, q3, not_q3, i1, i2, i3, i4, i5, i6]
dY_johnson = three_bit_model(Y_johnson, T, params_johnson)
dY_addr = three_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
# TOP MODEL OF PROCESSOR WITH FOUR BIT ADDRESSING
def four_bit_processor_ext(Y, T, params_johnson, params_addr):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, a4, not_a4, q4, not_q4, i1, i2, i3, i4, i5, i6, i7, i8 = Y
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, a4, not_a4, q4, not_q4]
Y_address = [q1, not_q1, q2, not_q2, q3, not_q3, q4, not_q4, i1, i2, i3, i4, i5, i6, i7, i8]
dY_johnson = four_bit_model(Y_johnson, T, params_johnson)
dY_addr = four_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
"""
PROCESSOR MODEL WITH EXTERNAL CLOCK AND RS inputs
external clock is required, more robust
jumps allowed
dodano 23. 1. 2020
"""
# TOP MODEL OF PROCESSOR WITH ONE BIT ADDRESSING AND FLIP-FLOP WITH RS ASYNCHRONOUS INPUTS
def one_bit_processor_ext_RS(Y, T, params_johnson_RS, params_addr):
a1, not_a1, q1, not_q1, i1, i2 = Y
R1 = 0
S1 = 0
Y_johnson = [a1, not_a1, q1, not_q1, R1, S1]
Y_address = [q1, not_q1, i1, i2]
dY_johnson = one_bit_model_RS(Y_johnson, T, params_johnson_RS)
dY_addr = one_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
# TOP MODEL OF PROCESSOR WITH TWO BIT ADDRESSING AND FLIP-FLOPS WITH RS ASYNCHRONOUS INPUTS
def two_bit_processor_ext_RS(Y, T, params_johnson_RS, params_addr):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, i1, i2, i3, i4 = Y
R1 = 0
S1 = 0
R2 = 0
S2 = 0
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, R1, S1, R2, S2]
Y_address = [q1, not_q1, q2, not_q2, i1, i2, i3, i4]
dY_johnson = two_bit_model_RS(Y_johnson, T, params_johnson_RS)
dY_addr = two_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
# TOP MODEL OF PROCESSOR WITH THREE BIT ADDRESSING AND FLIP-FLOPS WITH RS ASYNCHRONOUS INPUTS
def three_bit_processor_ext_RS(Y, T, params_johnson_RS, params_addr, jump_src, jump_dst, i_src, i_dst):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, i1, i2, i3, i4, i5, i6 = Y
i_src = eval(i_src)
R = [0,0,0]
S = [0,0,0]
for i in range(len(jump_src)):
if jump_src[i] > jump_dst[i]:
R[i] = i_src
elif jump_src[i] < jump_dst[i]:
S[i] = i_src
R1, R2, R3 = R if T > 1 else [100,100,100]
S1, S2, S3 = S
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, R1, S1, R2, S2, R3, S3]
Y_address = [q1, not_q1, q2, not_q2, q3, not_q3, i1, i2, i3, i4, i5, i6]
dY_johnson = three_bit_model_RS(Y_johnson, T, params_johnson_RS)
dY_addr = three_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY
"""
PROCESSOR MODEL WITH EXTERNAL CLOCK AND RS inputs AND JUMP CONDITIONS
dodano 24. 1. 2020
"""
def get_condition(x0, delta, t):
return x0 * np.e**(-delta*t)
# TOP MODEL OF PROCESSOR WITH THREE BIT ADDRESSING AND CONDITIONAL JUMPS
def three_bit_processor_ext_RS_cond(Y, T, params_johnson_RS, params_addr, jump_src, jump_dst, i_src, i_dst, condition):
a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, i1, i2, i3, i4, i5, i6 = Y
x0_cond, delta_cond, KD_cond, condition_type = condition
cond = get_condition(x0_cond, delta_cond, T)
i_src = eval(i_src)
R = np.array([0,0,0])
S = np.array([0,0,0])
for i in range(len(jump_src)):
if jump_src[i] > jump_dst[i]:
R[i] = i_src
elif jump_src[i] < jump_dst[i]:
S[i] = i_src
if condition_type == "induction":
R = induction(R, cond, KD_cond)
S = induction(S, cond, KD_cond)
else:
R = inhibition(R, cond, KD_cond)
S = inhibition(S, cond, KD_cond)
R1, R2, R3 = R
S1, S2, S3 = S
Y_johnson = [a1, not_a1, q1, not_q1, a2, not_a2, q2, not_q2, a3, not_a3, q3, not_q3, R1, S1, R2, S2, R3, S3]
Y_address = [q1, not_q1, q2, not_q2, q3, not_q3, i1, i2, i3, i4, i5, i6]
dY_johnson = three_bit_model_RS(Y_johnson, T, params_johnson_RS)
dY_addr = three_bit_simple_addressing_ode_model(Y_address, T, params_addr)
dY = np.append(dY_johnson, dY_addr)
return dY