-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added convergence plots of main poisson to main.tex
- Loading branch information
Showing
9 changed files
with
226 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
latex/main paper/plots_julia_code/main_poisson_convergence.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Plots | ||
using Random | ||
using LinearAlgebra | ||
using Plots.PlotMeasures | ||
|
||
function Y(t, sig, A::Function, f::Function, y0) | ||
(s = -log(rand()) / sig; sol = y0) | ||
while s < t | ||
sol += (A(s) * sol .+ f(s)) ./ sig | ||
s -= log(rand()) / sig | ||
end | ||
sol | ||
end | ||
|
||
a = 1 | ||
A(s) = [a 0; 1 a] | ||
q = [1, 0] | ||
f(s) = zero(q) | ||
sol(s) = [exp(a * s), s * exp(a * s)] | ||
sig = 1.0 | ||
t = 1.0 | ||
|
||
|
||
Random.seed!(2234) | ||
xticks = 10.0 .^ range(1, 4, step=1) | ||
yticks = 10.0 .^ range(-4, 0, step=1) | ||
sigs = exp10.(range(1, 4, length=1000)) | ||
errors = [norm(Y(t, sig, A, f, q) - sol(t)) for sig in sigs] | ||
p1 = plot(sigs, errors, st=:scatter, xscale=:log10, yscale=:log10, label="error", alpha=0.5) | ||
plot!(p1, sigs, 5 * sigs .^ -0.5, label="\$O(sig^{-0.5})\$", linewidth=4) | ||
plot!(p1, sigs, 5 * sigs .^ -1, label="\$O(sig^{-1})\$", linewidth=4) | ||
xticks!(p1, xticks) # Set xticks | ||
yticks!(p1, yticks) # Set yticks | ||
title!(p1, "error vs sig") | ||
xlabel!(p1, "sig") | ||
ylabel!(p1, "error") | ||
|
||
nsims = exp10.(range(1, 4, length=1000)) | ||
errors = [norm(sum(Y(t, sig, A, f, q) for _ in 1:nsim) / nsim - sol(t, sig)) for nsim in nsims] | ||
p2 = plot(nsims, errors, st=:scatter, xscale=:log10, yscale=:log10, label="error", alpha=0.5) | ||
plot!(p2, nsims, 5 * nsims .^ -0.5, label="\$O(nsim^{-0.5})\$", linewidth=4) | ||
plot!(p2, nsims, 5 * nsims .^ -1, label="\$O(nsim^{-1})\$", linewidth=4) | ||
xticks!(p2, xticks) # Set xticks | ||
yticks!(p2, yticks) # Set yticks | ||
title!(p2, "error vs nsim") | ||
xlabel!(p2, "nsim") | ||
ylabel!(p2, "error") | ||
|
||
p = plot(p1, p2, layout=(1, 2), size=(1000, 400), bottom_margin=5mm, left_margin=5mm) # Combine both plots | ||
display(p) | ||
savefig(p, "latex/main paper/julia_plots/main_poisson_convergence.pdf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Plots | ||
using Random | ||
using GLM, DataFrames | ||
using Plots.PlotMeasures | ||
|
||
function Yplot(t, sig, A::Function, f::Function, y0) | ||
(s = -log(rand()) / sig; sol = y0) | ||
path = [] | ||
while s < t | ||
push!(path, (s, sol)) | ||
sol += (A(s) * sol .+ f(s)) ./ sig | ||
s -= log(rand()) / sig | ||
end | ||
if length(path) > 0 | ||
push!(paths, path) | ||
end | ||
sol | ||
end | ||
|
||
a = 1 | ||
A(s) = [a 0; 1 a] | ||
q = [1, 0] | ||
f(s) = zero(q) | ||
sol(s) = [exp(a * s), s * exp(a * s)] | ||
|
||
Random.seed!(2234) | ||
paths = [] | ||
t = 1.0 | ||
sigs = [10.0, 1000.0] | ||
nsim1 = 5 | ||
|
||
markers = [:circle, :square, :diamond, :cross, :xcross, :utriangle, :dtriangle, :rtriangle, :ltriangle, :pentagon, :hexagon, :heptagon, :octagon, :star4, :star5, :star6, :star7, :star8, :vline, :hline] | ||
colors = [:red, :green, :blue, :orange, :purple, :brown, :black, :grey] | ||
pl = plot(layout=(2, 3), size=(1300, 800), xlim=(0, 1), | ||
bottom_margin=5mm, left_margin=5mm, right_margin=4mm) # Change layout to 2 rows and 3 columns | ||
ylims = [(-1, 1), (-1 / 4, 1 / 4)] | ||
for i in [1, 2] | ||
paths = [] | ||
sig = sigs[i] | ||
y = sum(Yplot(t, sig, A, f, q) for _ in 1:nsim1) / nsim1 | ||
for c in [1, 2] | ||
ylims!(pl[(i-1)*3+c], ylims[i]) | ||
xx = [p[1] for path in paths for p in path] | ||
yy = [p[2][c] for path in paths for p in path] | ||
ols = lm(@formula(y ~ x + x^2), DataFrame(x=xx, y=yy)) | ||
Random.seed!(6421) | ||
for path in paths | ||
marker = rand(markers) | ||
color = rand(colors) | ||
if i == 1 | ||
for p in path | ||
scatter!(pl[(i-1)*3+c], [p[1]], [p[2][c] - sol(p[1])[c]], label="", marker=marker, color=color, alpha=0.5) | ||
end | ||
end | ||
plot!(pl[(i-1)*3+c], [p[1] for p in path], [p[2][c] - sol(p[1])[c] for p in path], label="", alpha=0.5, color=color, linewidth=2) | ||
xlabel!(pl[(i-1)*3+c], "time") | ||
ylabel!(pl[(i-1)*3+c], "error") | ||
end | ||
tt = range(0, t, length=100) | ||
hline!(pl[(i-1)*3+c], [0], label="0 error", color=:black, linewidth=3) | ||
plot!(pl[(i-1)*3+c], tt, predict(ols, DataFrame(x=tt)) .- [sol(t)[c] for t in tt], label="OLS y ~ x+x^2", linewidth=3, color=:red) | ||
title!(pl[(i-1)*3+c], "error, sig=$sig, component=$c", titiefontsize=10) | ||
#qqplot of time | ||
plot!(pl[(i-1)*3+3], sort(rand(length(xx))), sort(xx), title="uniform qqplot of time sig=$sig", label="", linewidth=3) | ||
xlabel!(pl[(i-1)*3+3], "uniform") | ||
ylabel!(pl[(i-1)*3+3], "Poisson process") | ||
end | ||
end | ||
|
||
display(pl) | ||
savefig(pl, "latex/main paper/julia_plots/main_poisson_error.pdf") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters