Commit a94525a5 authored by Bentriou Mahmoud's avatar Bentriou Mahmoud
Browse files

Now pictures are saved in svg. All tests passed.

parent 2fd6f15d
import Plots: plot, plot!, scatter!, hline!, Shape, text
import Plots: current, palette, display, png, close
import Plots: current, palette, display, png, close, savefig
"""
`plot(σ, var...; plot_transitions=false)`
......@@ -27,14 +27,14 @@ function plot(σ::AbstractTrajectory, vars::VariableModel...; plot_transitions::
@assert var in get_obs_var(σ) "Variable $var is not observed."
plot!(p, times(σ), σ[var],
xlabel = "Time", ylabel = "Number of species",
label = var,
label = "$var",
linetype=:steppost)
end
if plot_transitions
for (i, var) in enumerate(to_plot)
for tr in l_tr
idx_tr = findall(x->x==tr, transitions(σ))
label = (tr == nothing || i > 1) ? "" : tr
label = (tr == nothing || i > 1) ? "" : "$tr"
alpha = (tr == nothing) ? 0.0 : 0.5
scatter!(p, times(σ)[idx_tr], σ[var][idx_tr], label=label,
markershape=:cross, markeralpha=alpha,
......@@ -49,7 +49,7 @@ function plot(σ::AbstractTrajectory, vars::VariableModel...; plot_transitions::
if filename == ""
display(p)
else
png(p, filename)
savefig(p, filename)
end
end
......@@ -124,7 +124,7 @@ function plot_periodic_trajectory(A::LHA, σ::SynchronizedTrajectory, sym_obs::S
if filename == ""
display(p)
else
png(p, filename)
savefig(p, filename)
end
end
......
......@@ -10,7 +10,7 @@ sync_doping = doping_3way_oscillator * A_per
set_time_bound!(sync_doping, 0.1)
set_x0!(doping_3way_oscillator, [:A, :B, :C, :DA, :DB, :DC], [333, 333, 333, 10, 10, 10])
σ = simulate(sync_doping)
plot(σ; A = A_per, filename = "traj_full.png")
plot(σ, :A; A = A_per, filename = "traj_A.png")
plot_periodic_trajectory(A_per, σ, :A, filename = "traj_automaton.png")
plot(σ; A = A_per, filename = "traj_full.svg")
plot(σ, :A; A = A_per, filename = "traj_A.svg")
plot_periodic_trajectory(A_per, σ, :A, filename = "traj_automaton.svg")
......@@ -45,7 +45,7 @@ samples_weights = r.weights
# Histogram
histogram(samples_abc_post, weights = r.weights, normalize = :density)
png(path_results * "histogram.png")
savefig(path_results * "histogram.svg")
## Satisfaction function
......@@ -92,5 +92,5 @@ y_MC = readdlm("/home/moud/plot_R1-3/estim_MC/$(exp)/satisfaction_func.csv", ','
inf_x, sup_x = 0.0, 100.0
x_MC = inf_x:((sup_x-inf_x)/(length(y_MC)-1)):sup_x
plot!(x_MC, y_MC, label = "MC spf")
png(path_results * "satisfaction_prob_function.png")
savefig(path_results * "satisfaction_prob_function.svg")
......@@ -47,7 +47,7 @@ samples_weights = r.weights
# Histogram
histogram2d(samples_abc_post[1,:], samples_abc_post[2,:], weights = samples_weights, normalize = :density)
png(path_results * "histogram.png")
savefig(path_results * "histogram.svg")
=#
## Satisfaction function
......@@ -88,11 +88,11 @@ xaxis = 0:0.1:1.5
yaxis = 0:1.0:100.0
p = plot(title = "Multivariate KDE", dpi = 480, background_color_legend = :transparent)
plot!(p, xaxis, yaxis, prob_func, st = :surface, c = :coolwarm, camera = (30, 45))
png(path_results * "estim_abc_satisfaction_prob_function.png")
savefig(path_results * "estim_abc_satisfaction_prob_function.svg")
x_MC = readdlm("/home/moud/results_last_automata/estim_satisfaction_func_MC/$(exp)/grid_X.csv", ',')
y_MC = readdlm("/home/moud/results_last_automata/estim_satisfaction_func_MC/$(exp)/grid_Y.csv", ',')
z_MC = readdlm("/home/moud/results_last_automata/estim_satisfaction_func_MC/$(exp)/satisfaction_func.csv", ',')
p = plot(title = "ABC MC", dpi = 480, background_color_legend = :transparent)
plot!(p, [x_MC...], [y_MC...], [z_MC...], st = :surface, c = :coolwarm, camera = (30, 45), label = "MC spf")
png(path_results * "estim_MC_satisfaction_prob_function.png")
savefig(path_results * "estim_MC_satisfaction_prob_function.svg")
......@@ -20,5 +20,5 @@ return test
#using Plots
#histogram(r.mat_p_end', weights = r.weights, normalize = :density)
#png("R1_hist.png")
#savefig("R1_hist.svg")
......@@ -13,5 +13,5 @@ pm_sync_ER = ParametricModel(sync_ER, (:k3, Uniform(0.0, 100.0)))
@show r.nbr_sim
histogram(r.mat_p_end', bins = :sqrt, weights = r.weights, normalize = :density, xlims = (0.0, 100.0))
png("R2_hist.png")
savefig("R2_hist.svg")
......@@ -11,5 +11,5 @@ pm_sync_ER = ParametricModel(sync_ER, (:k3, Uniform(0.0, 100.0)))
r = automaton_abc(pm_sync_ER; nbr_particles = 1000)
histogram(r.mat_p_end', weights = r.weights, normalize = :density, xlims = (0.0, 100.0))
png("R3_hist.png")
savefig("R3_hist.svg")
using MarkovProcesses
load_model("ER")
observe_all!(ER)
load_automaton("automaton_G_and_F")
A_G_F_R6 = create_automaton_G_and_F(ER, 50.0, 100.0, 0.0, 0.8, :E, 30.0, 100.0, 0.8, 0.9, :P)
sync_ER = A_G_F_R6 * ER
pm_sync_ER = ParametricModel(sync_ER, (:k1, Uniform(0.0,100.0)), (:k2, Uniform(0.0,100.0)))
r = automaton_abc(pm_sync_ER; alpha=0.2)
using Plots
histogram2d(r.mat_p_end[1,:], r.mat_p_end[2,:], bins=50)
savefig("R6_hist.svg")
......@@ -34,5 +34,5 @@ test = size(r.mat_p_end)[1] == pm_sync_ER.df &&
return test
#histogram(r.mat_p_end', weights = r.weights, normalize = :density)
#png("R1_hist.png")
#savefig("R1_hist.svg")
......@@ -9,7 +9,7 @@ ER_row_buffer.time_bound = 10.0
σ = _simulate_row_buffer(ER_row_buffer)
plt.figure()
plt.step(times(σ), _get_values_row(σ,:P), "ro--", marker="x", where="post", linewidth=1.0)
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_er_row_buffer_bounded.png")
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_er_row_buffer_bounded.svg")
plt.close()
return true
......
......@@ -9,7 +9,7 @@ pm_ER = ParametricModel(ER, (:k1, Uniform(0.0,100.0)), (:k2, Uniform(0.0,100.0))
prior_p = [0.2, 40.0]
σ = simulate(pm_ER, prior_p)
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_pm_er_long.png")
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_pm_er_long.svg")
return true
......@@ -11,7 +11,7 @@ pm_sync_ER = ParametricModel(ER*A_F, (:k1, Uniform(0.0,100.0)), (:k2, Uniform(0.
prior_p = [0.2, 40.0]
σ = simulate(pm_sync_ER, prior_p)
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_pm_sync_er_long.png")
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_pm_sync_er_long.svg")
return true
......@@ -4,7 +4,7 @@ load_plots()
load_model("poisson")
σ = simulate(poisson)
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_poisson.png")
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_poisson.svg")
return true
......@@ -7,7 +7,7 @@ load_model("SIR")
σ = simulate(SIR)
plt.figure()
plt.step(times(σ), σ[:I], "ro--", marker="x", where="post", linewidth=1.0)
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir.png")
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir.svg")
plt.close()
return true
......
......@@ -8,7 +8,7 @@ SIR.time_bound = 100.0
σ = simulate(SIR)
plt.figure()
plt.step(times(σ), σ[:I], "ro--", marker="x", where="post", linewidth=1.0)
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_bounded.png")
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_bounded.svg")
plt.close()
return true
......
......@@ -9,7 +9,7 @@ SIR_col_buffer.time_bound = 100.0
σ = _simulate_col_buffer(SIR_col_buffer)
plt.figure()
plt.step(times(σ), _get_values_col(σ,:I), "ro--", marker="x", where="post", linewidth=1.0)
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_col_buffer_bounded.png")
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_col_buffer_bounded.svg")
plt.close()
return true
......
......@@ -9,7 +9,7 @@ SIR_row_buffer.time_bound = 100.0
σ = _simulate_row_buffer(SIR_row_buffer)
plt.figure()
plt.step(times(σ), _get_values_row(σ,:I), "ro--", marker="x", where="post", linewidth=1.0)
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_row_buffer_bounded.png")
plt.savefig(get_module_path() * "/tests/simulation/res_pics/sim_sir_row_buffer_bounded.svg")
plt.close()
return true
......
......@@ -4,7 +4,7 @@ load_plots()
load_model("SIR_tauleap")
σ = simulate(SIR_tauleap)
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_sir_tauleap.png")
MarkovProcesses.plot(σ; filename = get_module_path() * "/tests/simulation/res_pics/sim_sir_tauleap.svg")
return true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment