MRC-CSO-SPHSU / UKSEABMLib.jl

MIT License
1 stars 1 forks source link

the usage of memoization in do_marriages #40

Closed AtiyahElsheikh closed 1 year ago

AtiyahElsheikh commented 1 year ago

Memoization is a technique that consider storing intermediate computational results to be directly used afterwords rather than re-computation. This is rather more popular in dynamic programming (e.g. fibonanci numbers, path algorithms in networks etc.)

simulation function can be applied at an agent-level (i.e. process is applied to an agent after another) or at a model-level (process is applied to all agents).

For example, the marriage function was implemented in a way to suite the application of simulation functions at agent-level. For this reason, the share of married men within population is memoized for each iteration. among others, e.g. eligible women.

When applying the simulation function at model level, all these quantities can be pre-computed easily and used when needed.

As expected, it turned out that the more natural approach is more efficient in terms of memory and runtime. In this particular case, it seems memoization was consuming alot of storage (or may be it is not properly implemented).