Skip to content

Commit

Permalink
test continuous GD
Browse files Browse the repository at this point in the history
  • Loading branch information
ISIPINK committed Apr 3, 2024
1 parent ef73fb1 commit 5ebcc61
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
62 changes: 62 additions & 0 deletions experiments/tests_period_8/lineareq_ode.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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.5
AA = [2 1; 0 -1]
b = [1, 0]
A(s) = -a * AA' * AA .+ (rand() - 0.5) / 3
q = [0.55, -0.05]
f(s) = a * AA' * b
sol(s) = AA \ b
print(sol(1))

Random.seed!(2234)
paths = []
t = 6
sigs = [5.0, 100.0]
nsim1 = 20

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),
bottom_margin=5mm, left_margin=5mm, right_margin=4mm) # Change layout to 2 rows and 3 columns
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]
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
hline!(pl[(i-1)*3+c], [0], label="0 error", color=:black, linewidth=3)
title!(pl[(i-1)*3+c], "error, sig=$sig, component=$c", titiefontsize=10)
end
end

display(pl)
Binary file modified latex/main paper/julia_plots/main_poisson_convergence.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions latex/main paper/plots_julia_code/main_poisson_convergence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ end

a = 1
A(s) = [a 0; 1 a]
q = [1, 0]
f(s) = zero(q)
q = [1.0, 0.0]
f(s) = 0.0
sol(s) = [exp(a * s), s * exp(a * s)]
sig = 1.0
t = 1.0
Expand Down

0 comments on commit 5ebcc61

Please sign in to comment.