where $G$ is a Gaussian random variable $\mathcal{N}(0,\sigma^2)$.
Size of an individual of age $a$ : $x_0 + ga$.
Competition : If a individual of size $x$ encounters an individual of size $y$, then it can die with the intensity $ U (x, y)$.
Initial population is a dataframe with three columns:
birth
(mandatory) : Date of birth of individuals in initial population (here the initial time is $t_0=0$).death
(mandatory) : Date of death (NA
if alive).birth_size
corresponding to the size at birth.# Generate population
N <- 900 # Number of individuals in the initial population
x0 <- 1.06
agemin <- 0.
agemax <- 2.
pop_init <- data.frame(
"birth" = -runif(N, agemin, agemax), # Age of each individual chosen uniformly in [0,2]
"death" = as.double(NA),
"birth_size" = x0 # All individuals have initially the same birth size x0.
)
head(pop_init)
birth | death | birth_size | |
---|---|---|---|
<dbl> | <dbl> | <dbl> | |
1 | -1.1390462 | NA | 1.06 |
2 | -0.1650035 | NA | 1.06 |
3 | -0.7701448 | NA | 1.06 |
4 | -1.1031752 | NA | 1.06 |
5 | -1.7765681 | NA | 1.06 |
6 | -0.2058391 | NA | 1.06 |
params_birth <- list( # parameters for birth event.
"p" = 0.03,
"sigma" = sqrt(0.01),
"alpha" = 1)
params_death <- list(
"g" = 1,
"beta" = 2./300.,
"c" = 1.2
)
mk_event_individual
.I
: age(I,t)
, I.birth_size
....kernel_code
. New individual is called ... newI
.birth_event <- mk_event_individual( type = "birth",
intensity_code = 'result = alpha * (4 - I.birth_size);',
kernel_code = 'if (CUnif() < p)
newI.birth_size = min(max(0., CNorm(I.birth_size, sigma)), 4.);
else
newI.birth_size = I.birth_size;')
mk_event_interaction
.I
interacts with individual named J
death_event <- mk_event_interaction( # Event with intensity of type interaction
type = "death",
interaction_code = "double x_I = I.birth_size + g * age(I,t);
double x_J = J.birth_size + g * age(J,t);
result = beta * ( 1.- 1./(1. + c * exp(-4. * (x_I-x_J))));" # U
)
model <- mk_model(
characteristics = get_characteristics(pop_init),
events = list(birth_event, death_event),
parameters = c(params_birth, params_death) # Model parameters
)
summary(model)
Events: #1: individual event of type birth #2: interaction event of type death --------------------------------------- Individual description: names: birth death birth_size R types: double double double C types: double double double --------------------------------------- R parameters available in C++ code: names: p sigma alpha g beta c R types: double double double double double double C types: double double double double double double
birth_intensity_max <- 4*params_birth$alpha
U_max <- params_death$beta
sim_out <- popsim(model = model,
population = pop_init,
events_bounds = c('birth'=birth_intensity_max, 'death'=U_max),
parameters = c(params_birth, params_death),
age_max = 2,
time = 500)
Simulation on [0, 500]
sim_out$logs[["effective_events"]] / sim_out$logs[["proposed_events"]]
sim_out$logs[["duration_main_algorithm"]]
sim_out$population
: all individuals present in the population over the period $[0, 500]$. pop_out <- sim_out$population
tail(pop_out)
birth | death | birth_size | |
---|---|---|---|
<dbl> | <dbl> | <dbl> | |
304712 | 497.9870 | 499.9870 | 2.754715 |
304713 | 498.6642 | 499.9919 | 2.564276 |
304714 | 499.1359 | 499.9885 | 2.578342 |
304715 | 499.7084 | 499.9961 | 2.578342 |
304716 | 499.8724 | 499.9893 | 2.675707 |
304717 | 499.9892 | 500.0007 | 2.948514 |
pyr1 <- age_pyramid(pop_out, ages = seq(0,2,by=0.2), time = 500)
params_death$g <- 0.3
sim_out <- popsim(model = model,
population = pop_init,
events_bounds = c('birth'=birth_intensity_max, 'death'=U_max),
parameters = c(params_birth, params_death),
age_max = 2,
time = 500)
Simulation on [0, 500]
N <- 2000
pop_init_big <- data.frame(
"birth" = -runif(N, agemin, agemax), # Age of each individual chosen uniformly in [0,2]
"death" = as.double(NA),
"birth_size" = x0 # All individuals have initially the same birth size x0.
)
params_birth$alpha <- 6
params_birth$p <- 0.01 # Mutation probability
params_death$beta <- 1/100
params_death$g <- 1
birth_intensity_max <- 4*params_birth$alpha
U_max <- params_death$beta
sim_out <- popsim(
model = model,
population = pop_init_big,
events_bounds = c('birth'=birth_intensity_max, 'death'=U_max),
parameters = c(params_birth, params_death),
age_max = 2,
time = 500)
Simulation on [0, 500]
sim_out$logs[["duration_main_algorithm"]]