I am trying to simulate a stochastic process on [0,1] that will hit the boundary with probability 1 in a finite amount of time. The package I am using is the SDE solver in DifferentialEquation.jl. However, all the recipes I found need a fixed time span for the solver. i.e. I can only specify a common time frame, say, 0\le t\le T for all the sample paths in the ensemble. But I want the solver to stop after hitting the boundary, or continue to solve for longer time if the path has not hit the boundary before T, is it possible in DifferentialEquations.jl?
My cumbersome solution now is to do a while-loop for each solving attempt with a fixed time frame, and break out if at the end of each iteration the process has hit the boundary, otherwise continue to solve using the end state of the process at the last iteration. But I think it is not quite efficient.
I thought I mention here that if someone is interested in the inverse problem - that is observing the hitting time of the boundary and then trying to say something about the underlying process - please ping me.
I tried this Callback with SDE and it works great, but when I used in in Discrete Problems, there seems to be some instability in the performance. For instance, I try the following toy example:
f(u,p,t) = u+1
prob = DiscreteProblem(f,3,(0.0,20.0))
rate(u,p,t) = 1
affect!(integrator) = (integrator.u = integrator.u + 1)
jump = ConstantRateJump(rate,affect!)
condition(u,t,integrator) = (u >= 10)
function affect_stop!(integrator)
println("hit!")
terminate!(integrator)
end
cb = DiscreteCallback(condition,affect_stop!)
jump_prob = JumpProblem(prob,Direct(),jump)
sol = solve(jump_prob,callback=cb)
The solution is supposed to stop when it reached 10 and print out “hit!”
The jump process went on even after it was terminated. Then I thought maybe it is because I added a continuous-time jump process to the iteration, and I should use the ContinuousCallback() function, but switching to that also doesn’t work.