Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RateSystem #117

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/RateSys.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# | | | |
# t_i autonomous t_ni non-autonomous t_nf autonomous t_f
# | | | |

using DynamicalSystems
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be sufficient to use DynamicalSystemsBase.

using Plots

# we write

function RateSyst(tni,tnf,f,λ,p_λ,initvals)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, these are quite many positional arguments, which makes it less user-friendly. What do you think of reorganising this in the following structure:

RateSystem(ds::ContinuousTimeDynamicalSystem, rate_protocol::function)

where ds can be a CoupledODEs or a CoupledSDEs and rate_protocol is your λ function that determines how the parameters change over time. This function could have the structure

rate_protocol(u, p_lambda, t; t_start=0.0, t_end=Inf, kwargs...)

i.e. it would contain all the input arguments needed to define the rate forcing function. Behind the scenes, this would then create and return a new CoupledODEs or CoupledSDEs with the explicit time dependence specified by rate_protocol.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming here is just a suggestion, but generally I think we should give more descriptive names than just lambda or tnf (clarity over brevity!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds great, thanks Reyk! However, rate_protocol should not depend on u, in my opinion.

func(u,p,t) = combined_system(u,t,tni,tnf,f,λ,p_λ);
return ContinuousDynamicalSystem(func, initvals, Float64[], t0=tni)
oameye marked this conversation as resolved.
Show resolved Hide resolved
end

function combined_system(u,t,tni,tnf,f,λ,p_λ)
lambda = t < tni ? λ(u,p_λ,tni) : tni <= t <= tnf ? λ(u,p_λ,t) : λ(u,p_λ,tnf)
return f(u,lambda,t)
oameye marked this conversation as resolved.
Show resolved Hide resolved
end;


oameye marked this conversation as resolved.
Show resolved Hide resolved
###############
# user writes

function f(u::SVector{1, Float64},p::SVector{1, Float64},t::Float64)
oameye marked this conversation as resolved.
Show resolved Hide resolved
x = u[1]
λ = p[1]
dx = (x+λ)^2 - 1
oameye marked this conversation as resolved.
Show resolved Hide resolved
return SVector{1}(dx)
end;

function λ(p::Vector{Float64},t::Float64)
r,λ_max = p
lambda = (λ_max/2)*(tanh(λ_max*r*t/2) +1)
oameye marked this conversation as resolved.
Show resolved Hide resolved
return SVector{1}(lambda)
end;

tni=-10.; tnf=10.; p_λ = [1.0,3.0]; initvals = [-4.];
sys = RateSyst(tni,tnf,f,λ,p_λ,initvals)

traj=trajectory(sys,40.,t0=-20.)
oameye marked this conversation as resolved.
Show resolved Hide resolved

trajic=[traj[1][i][1] for i in 1:length(traj[1])]
plot(collect(traj[2]),trajic)
oameye marked this conversation as resolved.
Show resolved Hide resolved


oameye marked this conversation as resolved.
Show resolved Hide resolved
# further ideas
# function futureSyst(RateSyst)
# Canard Trajectories

# \dot(x) = f(x(t),λ(t))



oameye marked this conversation as resolved.
Show resolved Hide resolved
Loading