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

EventQueueABM example giving incorrect results #1110

Closed
sdwfrost opened this issue Dec 10, 2024 · 9 comments
Closed

EventQueueABM example giving incorrect results #1110

sdwfrost opened this issue Dec 10, 2024 · 9 comments
Labels
question Further information is requested

Comments

@sdwfrost
Copy link

Describe the bug

I'm trying out the continuous time version of a toy model I use for demonstrating simulation/inference capabilities in Julia. Previously, I have coded up a StandardABM, which works fine, and gives results comparable to a hand-coded exanmple. However, although my EventQueueABM runs without error, it is not giving the correct dynamics. A version of the same model, but using SimJulia, can be found here. The peak number of infected individuals in my model comes too late - I've checked with different population sizes/multiple runs, and this is a systematic effect, not a stochastic one. I think that I'm implementing the model correctly - do you have any suggestions?

Minimal Working Example

Julia script: https://github.com/epirecipes/sir-julia/blob/master/script/des_agentsjl/des_agentsjl.jl
Julia Markdown: https://github.com/epirecipes/sir-julia/blob/master/tutorials/des_agentsjl/des_agentsjl.jmd

Agents.jl version

v6.1.12

@Datseris Datseris added the question Further information is requested label Dec 10, 2024
@Datseris
Copy link
Member

Hi, what is the thing that you believe is behaving "incorrectly"? Is it the event queing, the propensity timing estimation, or something else? The result of the continuous time implementation is:

image

and the result of the discrete time, scaled to the same time units is:

image

The blue and green curves to me seem very similar but for the continuous time case they need to be run for longer time, like tf=50. Is this the problem that you are reporting? I haven't read your source code in deep detail yet.

@slwu89
Copy link

slwu89 commented Dec 10, 2024

@sdwfrost see epirecipes/sir-julia#153, I found our issue, sorry, not quite in time =)

@Datseris
Copy link
Member

thanks @sdwfrost . Yes, the event queue is always a bit tricky to wrap your head around when moving from the discrete time. One needs to take care of when an event should be scheduled and when not, because for the continuous time scheduled event == triggered event.

I assume this is safe to close now.

@sdwfrost
Copy link
Author

Thanks @slwu89 and @Datseris - it wasn't apparent to me that one needed to explicitly set propensities to zero.

@Datseris
Copy link
Member

Datseris commented Dec 10, 2024

That's why the two graphs look the same but the continuous time is "slower": even though the infect action function does check whether an agent is infected, it was still scheduled and triggered for non infected agents, essentially "wasting" some of the agents' time, if this makes any sense. As an event for an agent is scheduled always after a previous event has happened, this effectively slowed down the simulation.

Does it make sense now?

Its because for continuous time all events (actions) take time, regardless if they actually alter any agent property or not.

@Tortar
Copy link
Member

Tortar commented Dec 10, 2024

By the way I'm pleased by the fact that our des works so much faster than the SimJulia one

@Datseris
Copy link
Member

What's the numbers? I can't seem to find them at the repo now...

@Tortar
Copy link
Member

Tortar commented Dec 10, 2024

@Datseris
Copy link
Member

Oh yeah, that is almost 10x 🔥

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants