check_trajectory_consistency.jl 2.56 KB
Newer Older
1
2

using MarkovProcesses
3

4
5
6
7
8
9
load_model("SIR")
load_model("ER")

test_all = true
nb_sim = 1000

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function show_traj(io::IO, σ::AbstractTrajectory, m::Model)
    println(io, "length(σ.values), length(σ.times), length(σ.transitions)")
    println(io, "$(length(σ.values)), $(length(σ.times)), $(length(σ.transitions))")
    println(io, "isbounded(m), isbounded(σ)")
    println(io, "$(isbounded(m)), $(isbounded(σ))")
    println(io, σ.values)
    println(io, "$(σ.values)")
    println(io, σ.times)
    println(io, "$(σ.times)")
    println(io, "σ.transitions")
    println(io, "$(σ.transitions)")
end

σ_dump = simulate(SIR)
σ2_dump = simulate(ER)

26
27
28
29
for i = 1:nb_sim
    σ = simulate(SIR)
    σ2 = simulate(ER)
    try
30
31
        global test_all = test_all && check_consistency(σ) && check_consistency(σ2) &&
                          !isbounded(σ) && !isbounded(σ2)
32
    catch err
33
34
35
36
        show_traj(stdout,σ, SIR)
        show_traj(stdout,σ2, ER)
        global σ_dump = σ
        global σ2_dump = σ2
37
38
        throw(err)
    end
39
40
41
42
43
44
45
    if !test_all
        show_traj(stdout,σ, SIR)
        show_traj(stdout,σ2, ER)
        global σ_dump = σ
        global σ2_dump = σ2
        error("Ouch")
    end
46
end
47
48
49

SIR.time_bound = 1.0
ER.time_bound = 0.01
50
51
52
53
for i = 1:nb_sim
    σ = simulate(SIR)
    σ2 = simulate(ER)
    try
54
55
        global test_all = test_all && check_consistency(σ) && check_consistency(σ2) &&
                          isbounded(σ) && isbounded(σ2)
56
    catch err
57
58
59
60
        show_traj(stdout, σ, SIR)
        show_traj(stdout, σ2, ER)
        global σ_dump = σ
        global σ2_dump = σ2
61
62
        throw(err)
    end
63
64
65
66
67
68
69
    if !test_all
        show_traj(stdout, σ, SIR)
        show_traj(stdout, σ2, ER)
        global σ_dump = σ
        global σ2_dump = σ2
        error("Ouch")
    end
70
71
end

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
SIR.time_bound = Inf
ER.time_bound = Inf
new_x0_SIR = view(reshape([95, 0, 5], 1, :), 1, :)
new_x0_ER = view(reshape([0, 0, 0, 100], 1, :), 1, :)
SIR.x0 = new_x0_SIR
ER.x0 = new_x0_ER
σ = simulate(SIR)
σ2 = simulate(ER)
test_all = test_all && SIR.isabsorbing(SIR.p,new_x0_SIR) && ER.isabsorbing(ER.p,new_x0_ER) &&
                    length_states(σ) == 1 && length_states(σ2) == 1 &&
                    check_consistency(σ) && check_consistency(σ2)

SIR.time_bound = 1.0
ER.time_bound = 0.01
σ = simulate(SIR)
σ2 = simulate(ER)
test_all = test_all && SIR.isabsorbing(SIR.p,new_x0_SIR) && ER.isabsorbing(ER.p,new_x0_ER) &&
                    length_states(σ) == 2 && length_states(σ2) == 2 &&
                    check_consistency(σ) && check_consistency(σ2)

92
93
return test_all