This function creates a function for advancing the state of an SPN model
using a simple Euler-Maruyama discretisation of the CLE on a 1D regular grid. The resulting function (closure) can be
used in conjunction with other functions (such as
for simulating realisations of SPN models in space and time.
An R list with named components representing a stochastic
Petri net (SPN). Should contain
A vector of diffusion coefficients - one coefficient for each reacting species, in order. The coefficient is the reaction rate for a reaction for a molecule moving into an adjacent compartment. The hazard for a given molecule leaving the compartment is therefore twice this value (as it can leave to the left or the right).
Time step for the Euler-Maruyama discretisation.
An R function which can be used to advance the state of the SPN model
N by using a simple Euler-Maruyama algorithm. The function closure has
x0 is a matrix
with rows corresponding to species and columns corresponding to voxels,
representing the initial condition,
t0 represent the initial state and time, and
deltat represents the amount of time by which the process should be advanced. The function closure returns a matrix representing the simulated state of the system at the new time.
1 2 3 4 5 6 7 8 9 10 11 12
N=200 T=40 data(spnModels) x0=matrix(0,nrow=2,ncol=N) rownames(x0)=c("x1","x2") x0[,round(N/2)]=LV$M stepLV1D = StepCLE1D(LV,c(0.6,0.6),dt=0.05) xx = simTs1D(x0,0,T,0.2,stepLV1D) op=par(mfrow=c(1,2)) image(xx[1,,],main="Prey",xlab="Space",ylab="Time") image(xx[2,,],main="Predator",xlab="Space",ylab="Time") par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.