actuarialopensource / benchmarks

Some performance tests for actuarial applications
MIT License
14 stars 4 forks source link

try transducers approach for term life benchmark #33

Closed MatthewCaseres closed 3 months ago

MatthewCaseres commented 1 year ago

I'm just curious to see what it looks like

serenity4 commented 11 months ago

Transducers may be used at two layers:

Another idea for transducers would be to decompose the different simulation stages (maturity, new policies, deaths, lapses), and then have a simulation step be invoked as a transducer:

events = SimulationEvents()
new_policies = policies |> Maturity(events) |> NewPolicies(events) |> Deaths(events) |> Lapses(events)`

# with maybe something like
SimulationStep(events) = Maturity(events) |> NewPolicies(events) |> Deaths(events) |> Lapses(events)

I'm still not convinced that transducers are the best language to model term life simulations, but we could probably fit our current LifeSimulator.jl implementation as a transducer with the ideas above (and it can be fun to try at least). There can be other designs, although I think this one would be a good one to start with.

I think generally speaking performance might be harder to ensure with transducers, notably I think memory reuse can be tricky. policies |> step |> collect would have to either reuse data from policies by mutating it - which is probably not what a user would want - or use a new vector of policies, in which case memory usage jumps from P to 2P.

MatthewCaseres commented 3 months ago

This issue is being closed, apologies for getting enamored by the shiny object that we ended up not using! If someone wants to do this fine, but this is being put so far in the back log it is just going to be closed for now.