access_var_values.jl 1.53 KB
Newer Older
Bentriou Mahmoud's avatar
Bentriou Mahmoud committed
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

using BenchmarkTools
using pygmalion
using MarkovProcesses

println("Pygmalion:")

str_m = "enzymatic_reaction"
str_d = "abc_er"
pygmalion.load_model(str_m)
str_oml = "P,R,time"
ll_om = split(str_oml, ",")
x0 = State(95.0, 95.0, 0.0, 0.0, 0.0, 0.0)
p_true = Parameters(1.0, 1.0, 1.0)
u = Control(10.0)
tml = 1:400
g_all = create_observation_function([ObserverModel(str_oml, tml)]) 
so = pygmalion.simulate(f, g_all, x0, u, p_true; on = nothing, full_timeline = true)
function read_trajectory_v1(so::SystemObservation)
    vals = to_vec(so, "P")
    n_states = length(vals)
    res = 0.0
    for i = 1:n_states
        res += vals[i]
    end
    return res
end
function read_trajectory_v2(so::SystemObservation)
    idx_P = om_findfirst("P", so.oml)
    n_states = length(so.otll[idx_P]) 
    res = 0.0
    for i = 1:n_states
        res += so.otll[idx_P][i][2][1]
    end
    return res
end
# Bench
@timev read_trajectory_v1(so)
b1_pyg = @benchmark read_trajectory_v1($so) 
@show minimum(b1_pyg), mean(b1_pyg), maximum(b1_pyg)
@timev read_trajectory_v2(so)
b2_pyg = @benchmark read_trajectory_v2($so) 
@show minimum(b2_pyg), mean(b2_pyg), maximum(b2_pyg)

println("MarkovProcesses:")

MarkovProcesses.load_model("ER")
ER.time_bound = 10.0
σ = MarkovProcesses.simulate(ER)
function read_trajectory(σ::AbstractTrajectory)
    n_states = get_states_number(σ)
    res = 0
    for i = 1:n_states
        res += (σ["P"])[i]
    end
    return res
end
# Bench
@timev read_trajectory(σ) 
b1 = @benchmark read_trajectory($σ)
@show minimum(b1), mean(b1), maximum(b1)