KendrickOrg / kendrick

Domain-Specific Modeling for Epidemiology
MIT License
49 stars 14 forks source link

Try to build more generic stochastic algorithms #211

Closed SergeStinckwich closed 3 years ago

SergeStinckwich commented 3 years ago

In the iteration loop for the Gillespie algorithm, there is a reference to compartments. The algorithm should be more generic (not only used for epidemiological models).

doGillespieIteration: t
    | rates deltaT chosen transitions |
    rates := OrderedCollection new.
    model t: t.
    transitions := model transitions.
    transitions
        do: [ :tr | 
            | prob |
            (tr from at: #status) = #empty
                ifTrue: [ model currentCompartment: tr to ]
                ifFalse: [ model currentCompartment: tr from ].
            model nextCompartment: tr to.
            prob := (tr probability value: model) abs.
            rates add: prob * (model atCompartment: tr from) ].
    rates sum = 0
        ifTrue: [ ^ 0.0 ].
    deltaT := rand2 next ln negated / rates sum.
    chosen := self rouletteWheelSelectAmong: rates.
    (transitions at: chosen) executeOn: model times: 1.
    ^ deltaT

Same problem in TauLeap iteration loop.

SergeStinckwich commented 3 years ago

First step in https://github.com/UNU-Macau/kendrick/commit/b88d89e8728d286818433f9dd7a392ebc94391d5