Skip to content

Delay implementation introduces artifacts in solution #24

@maedoc

Description

@maedoc

I had a hard time writing a descriptive title, apologies. I am testing the solvers on a non-stiff network of oscillators, checking that the coherence of the oscillators coverges to an expected analytic result and discovered that the solution appears to be wrong for non-EM solvers (why is EM unaffected?) when I set the delay to zero.

Definition of the additive noise oscillator model and history function

The functions defining the problem are as follows

struct kp
    G::Float64
    σ::Float64
    n::UInt64
    τ::Float64
end

# Kuramoto order parameter
kopz(sol) = [angle(mean(exp.(1.0im .* u_t))) for u_t in sol.u];
kop(sol) = [abs(mean(exp.(1.0im .* u_t))) for u_t in sol.u];

function kf(du,u,h,p,t)
    G = p.G/p.n
    du .= 5*2*π/1000
    for j=1:p.n
        for i=1:p.n
            if i!=j
                uⱼ = h(p, t - p.τ; idxs=j)[1]
                du[i] += G * sin(uⱼ - u[i])
            end
        end
    end
end

function kf(du,u,p,t)
    G = p.G/p.n
    du .= 5*2*π/1000
    for j=1:p.n
        for i=1:p.n
            if i!=j
                uⱼ = u[j]
                du[i] += G * sin(uⱼ - u[i])
            end
        end
    end
end

function kg(du,u,h,p,t)
    du .= sqrt(2*p.σ)
end

function kg(du,u,p,t)
    du .= sqrt(2*p.σ)
end

function kh(p,t;idxs=nothing)
    x = (1:p.n)/p.n*2*pi .+ t .* 2 .* pi
    collect(idxs==nothing ? x : x[idxs])
end

Here I use the SDDE solver but set the delay to zero

g = 0.1
p = kp(g, g/2.5, 100, 0.0); # the last zero here sets the delay
ic = kh(p, 0.0);
T = 1000
prob = SDDEProblem(kf, kg, ic, kh, (0.,T), p);
eprob = EnsembleProblem(prob)
@time sol = solve(eprob, SOSRA(), dt=1, adaptive=false, trajectories=10,saveat=0:1:T);
plot(hcat([kop(s) for s in sol]...),linealpha=0.2)

image
which shows the coherence of the network over time for each realization, but the result is wrong.

Suspecting the delay implementation (but not delays themselves, since they are set to zero),

prob = SDEProblem(kf, kg, ic, (0.,T), p);
eprob = EnsembleProblem(prob)
@time sol = solve(eprob, SOSRA(), dt=1, adaptive=false, trajectories=10,saveat=0:1:T);
plot(hcat([kop(s) for s in sol]...),linealpha=0.2)

image
which is correct. But, EM doesn't seem to mind,

prob = SDDEProblem(kf, kg, ic, kh, (0.,T), p);
eprob = EnsembleProblem(prob)
@time sol = solve(eprob, EM(), dt=1, trajectories=10,saveat=0:1:T);
plot(hcat([kop(s) for s in sol]...),linealpha=0.2)

image
though EM should use a shorter time step to be as accurate as SOSRA.

For reference, I include a SOSRA run with higher tolerance,

prob = SDEProblem(kf, kg, ic, (0.,T), p);
eprob = EnsembleProblem(prob)
@time sol = solve(eprob, SOSRA(), tol=1e-9, trajectories=10,saveat=0:1:T);
plot(hcat([kop(s) for s in sol]...),linealpha=0.2)

image

I hope this is detailed enough to explain the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions