Implementing Gillespie's Stochastic Simulation Algorithm

356 views
Skip to first unread message

Simon Frost

unread,
Apr 9, 2014, 4:40:40 AM4/9/14
to julia...@googlegroups.com
Dear All,

I'm implementing Gillespie's direct method for stochastic simulation:


I'm loosely following the API for the now-orphaned R package GillespieSSA:



In Julia, the analogous function call is something like the following.

function ssa(x0::Vector{Int64},a::Vector{Expr},nu::Matrix{Float64,2},parms::Expr,tf::Float64,ignore_negative_state::Bool,console_interval::Int64,census_interval::Int64,verbose::Bool,max_wall_time::Float64)

However, as I've never done metaprogramming in Julia before, I was wondering whether anyone had any input to make the model definition as clean as possible (i.e. without cluttering the syntax with symbols, while not polluting the environment)?

Best
Simon


David P. Sanders

unread,
Apr 10, 2014, 11:19:14 AM4/10/14
to julia...@googlegroups.com
Hi Simon,

This is a nice idea! I'm very interested.

Unfortunately, I don't have the necessary experience either, but there are other packages which could be useful, such as ODE solvers, which have the same issue of how to best define the model. For example:


Personally, the ssa() function you are proposing seems rather complicated. Perhaps it would be better to have some kind of new type that wraps all the needed parameters in one place? 

Best
David.




 

David P. Sanders

unread,
Apr 10, 2014, 11:26:20 AM4/10/14
to julia...@googlegroups.com


El jueves, 10 de abril de 2014 10:19:14 UTC-5, David P. Sanders escribió:


El miércoles, 9 de abril de 2014 03:40:40 UTC-5, Simon Frost escribió:
Dear All,

I'm implementing Gillespie's direct method for stochastic simulation:


I'm loosely following the API for the now-orphaned R package GillespieSSA:



In Julia, the analogous function call is something like the following.

function ssa(x0::Vector{Int64},a::Vector{Expr},nu::Matrix{Float64,2},parms::Expr,tf::Float64,ignore_negative_state::Bool,console_interval::Int64,census_interval::Int64,verbose::Bool,max_wall_time::Float64)

However, as I've never done metaprogramming in Julia before, I was wondering whether anyone had any input to make the model definition as clean as possible (i.e. without cluttering the syntax with symbols, while not polluting the environment)?

Best
Simon

Hi Simon,

This is a nice idea! I'm very interested.

Unfortunately, I don't have the necessary experience either, but there are other packages which could be useful, such as ODE solvers, which have the same issue of how to best define the model. For example:



And 

In fact, as a first step, I guess it would be much easier to just pass in a standard Julia function, rather than trying to parse something.

Simon Frost

unread,
Apr 11, 2014, 9:03:33 AM4/11/14
to julia...@googlegroups.com

Dear David,

It probably would be easier to pass a function that, given the current states and the parameters, returned a Float64 vector of rates. The main issue that I have is that eval can't see all the variables defined in the function scope, so my code runs fine if run globally, but not as a function. If I go along that route, it would probably be best to define an appropriate model type, rather like Tim Vaughan's MASTER program:


I'll tweak my code to work with functions, and push to github when I get a chance.

Best
Simon

Simon Frost

unread,
Apr 11, 2014, 5:19:24 PM4/11/14
to julia...@googlegroups.com
I just added a draft implementation along the lines of ODE.jl:


David P. Sanders

unread,
Apr 11, 2014, 8:56:22 PM4/11/14
to julia...@googlegroups.com


El viernes, 11 de abril de 2014 16:19:24 UTC-5, Simon Frost escribió:
I just added a draft implementation along the lines of ODE.jl:


At a first glance it looks nice; I hope I get a chance to look at it in more detail soon.

 
Reply all
Reply to author
Forward
0 new messages