Description Usage Arguments Value See Also Examples
View source: R/StepGillespie.R
This function creates a function for advancing the state of an SPN model using the Gillespie algorithm. The resulting function (closure) can be used in conjunction with other functions (such as simTs
) for simulating realisations of SPN models.
1 |
N |
An R list with named components representing a stochastic
Petri net (SPN). Should contain |
An R function which can be used to advance the state of the SPN model N
by using the Gillespie algorithm. The function closure has interface function(x0,t0,deltat,...)
, where x0
and 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 vector representing the simulated state of the system at the new time.
StepEulerSPN
, StepGillespie1D
,
simTs
, simTimes
, simSample
, StepFRM
,
StepPTS
, StepCLE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # load up the Lotka-Volterra (LV) model
data(spnModels)
LV
# create a stepping function
stepLV = StepGillespie(LV)
# step the function
print(stepLV(c(x1=50,x2=100),0,1))
# simulate a realisation of the process and plot it
out = simTs(c(x1=50,x2=100),0,100,0.1,stepLV)
plot(out)
plot(out,plot.type="single",lty=1:2)
# simulate a realisation using simTimes
times = seq(0,100,by=0.1)
plot(ts(simTimes(c(x1=50,x2=100),0,times,stepLV),start=0,deltat=0.1),plot.type="single",lty=1:2)
# simulate a realisation at irregular times
times = c(0,10,20,50,100)
out2 = simTimes(c(x1=50,x2=100),0,times,stepLV)
print(out2)
|
Loading required package: abind
Loading required package: parallel
$Pre
[,1] [,2]
[1,] 1 0
[2,] 1 1
[3,] 0 1
$Post
[,1] [,2]
[1,] 2 0
[2,] 0 2
[3,] 0 0
$M
x1 x2
50 100
$h
function (x, t, th = c(th1 = 1, th2 = 0.005, th3 = 0.6))
{
with(as.list(c(x, th)), {
return(c(th1 * x1, th2 * x1 * x2, th3 * x2))
})
}
<environment: 0x23bd3e0>
x1 x2
67 71
x1 x2
0 50 100
10 103 54
20 106 32
50 63 220
100 147 311
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.