Lobz / facilitation

A R/cpp framework for facilitation IBMs
1 stars 2 forks source link

(optimization) How about returning the lifestories of individuals instead of snapshots? #22

Closed Lobz closed 8 years ago

Lobz commented 8 years ago

The return data structure is taking too long to assemble, specially if we have to use a mixed-type list like Rcpp list, which is super inefficient. I believe that if we return only one line per event, we will actually reduce the size of the return structure. You can see from the snipped below (I ommited part of the output), the size of the return data.frame is way bigger than the number of actual events. Moreover, we could optimize the output by having each individual register its whole life history, so that 1) we don't need to repeat information on each individual 2) we can collect all this info when either the individual dies or the simulation ends.

> numstages <- 3
> deathrates <- c(2, 0.2, 0.2)  # death rates for seed, sapling and adult
> growthrates <- c(1, 0.2)      # transition rates seed-->sapling and sapling-->adult
> reproductionrate <- 10        # reproduction rate (only adult)
> dispersalradius <- 2          # average distance a seed falls from the parent (distance is gaussian)
> times <- seq(0,12,.3)         # array of times of interest
> initialpop <- c(100,100,100,0)    # initial pop. sizes for the 3 stages plus the facilitator species
> facindex <- c(0,1)            # this will be the values by which facilitator decreases seeds and seedlings deathrates
> effects <- c(0,0,0, 0,-0.5,0, 0,0,-0.2) # the effects reducing deathrate (negative values increase deathrates)
> radius <- c(0,0.5,2,2)        # this are the distances up to which the individuals can have effect on others, by stage + facilitator
> h <- 50                       # arena height
> w <- 50                       # arena width

> x <- facByRates(times=times, n=numstages, Ds=deathrates, Gs=growthrates, dispersal=dispersalradius, R=reproductionrate, interactions=effects, fac=facindex, init=initialpop, rad=radius, h=h, w=w)
(...)
#Total number os turns: 97694
> max(x$data$id) # estimate for the total number of individuals
[1] 74543
> dim(x$data)
[1] 1073284      13
andrechalom commented 8 years ago

This looks SOOOO COOL.

On Fri, Jun 3, 2016 at 8:17 PM, M Salles notifications@github.com wrote:

The return data structure is taking too long to assemble, specially if we have to use a mixed-type list like Rcpp list, which is super inefficient. I believe that if we return only one line per event, we will actually reduce the size of the return structure. You can see from the snipped below (I ommited part of the output), the size of the return data.frame is way bigger than the number of actual events. Moreover, we could optimize the output by having each individual register its whole life history, so that 1) we don't need to repeat information on each individual 2) we can collect all this info when either the individual dies or the simulation ends.

numstages <- 3 deathrates <- c(2, 0.2, 0.2) # death rates for seed, sapling and adult growthrates <- c(1, 0.2) # transition rates seed-->sapling and sapling-->adult reproductionrate <- 10 # reproduction rate (only adult) dispersalradius <- 2 # average distance a seed falls from the parent (distance is gaussian) times <- seq(0,12,.3) # array of times of interest initialpop <- c(100,100,100,0) # initial pop. sizes for the 3 stages plus the facilitator species facindex <- c(0,1) # this will be the values by which facilitator decreases seeds and seedlings deathrates effects <- c(0,0,0, 0,-0.5,0, 0,0,-0.2) # the effects reducing deathrate (negative values increase deathrates) radius <- c(0,0.5,2,2) # this are the distances up to which the individuals can have effect on others, by stage + facilitator h <- 50 # arena height w <- 50 # arena width

x <- facByRates(times=times, n=numstages, Ds=deathrates, Gs=growthrates, dispersal=dispersalradius, R=reproductionrate, interactions=effects, fac=facindex, init=initialpop, rad=radius, h=h, w=w) (...)

Total number os turns: 97694

max(x$data$id) # estimate for the total number of individuals [1] 74543 dim(x$data) [1] 1073284 13

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Lobz/facilitation/issues/22, or mute the thread https://github.com/notifications/unsubscribe/AB5w9VkWk9pN4qAB6ziQh8xhrbC3QciNks5qILYKgaJpZM4It-2A .

Lobz commented 8 years ago

IT'S ALIVE