twallema / pySODM

Simulating and Optimising Dynamical Models in Python 3
Other
9 stars 2 forks source link

Drop suffix names in model declaration #58

Closed twallema closed 1 year ago

twallema commented 1 year ago

Describe your fixes/additions/changes

This PR may break existing code but is easy to fix

Addresses issue #50.

Models were previously defined as follows,

class ODE_influenza_model(ODEModel):
    """
    Simple SEIR model for influenza with undetected carriers
    """

    state_names = ['S','E','Ip','Iud','Id','R','Im_inc']
    parameter_names = ['alpha', 'beta', 'gamma', 'delta','N']
    parameter_stratified_names = ['f_ud']
    dimension_names = ['age_group']

    @staticmethod
    def integrate(t, S, E, Ip, Iud, Id, R, Im_inc, alpha, beta, gamma, delta, N, f_ud):

        # Calculate total population
        T = S+E+Ip+Iud+Id+R
        # Calculate differentials
        dS = -beta*N@((Ip+Iud+0.22*Id)*S/T)
        dE = beta*N@((Ip+Iud+0.22*Id)*S/T) - 1/alpha*E
        dIp = 1/alpha*E - 1/gamma*Ip
        dIud = f_ud/gamma*Ip - 1/delta*Iud
        dId = (1-f_ud)/gamma*Ip - 1/delta*Id
        dR = 1/delta*(Iud+Id)
        # Calculate incidence mild disease
        dIm_inc_new = (1-f_ud)/gamma*Ip - Im_inc

        return dS, dE, dIp, dIud, dId, dR, dIm_inc_new

But I found the _names suffix to state_names, parameter_names etc quite redundant so I changed it into states, parameters etc. See below, this PR may break existing code.

class ODE_influenza_model(ODEModel):
    """
    Simple SEIR model for influenza with undetected carriers
    """

    states = ['S','E','Ip','Iud','Id','R','Im_inc']
    parametes = ['alpha', 'beta', 'gamma', 'delta','N']
    stratified_parameters = ['f_ud']
    dimensions = ['age_group']

    @staticmethod
    def integrate(t, S, E, Ip, Iud, Id, R, Im_inc, alpha, beta, gamma, delta, N, f_ud):

        # Calculate total population
        T = S+E+Ip+Iud+Id+R
        # Calculate differentials
        dS = -beta*N@((Ip+Iud+0.22*Id)*S/T)
        dE = beta*N@((Ip+Iud+0.22*Id)*S/T) - 1/alpha*E
        dIp = 1/alpha*E - 1/gamma*Ip
        dIud = f_ud/gamma*Ip - 1/delta*Iud
        dId = (1-f_ud)/gamma*Ip - 1/delta*Id
        dR = 1/delta*(Iud+Id)
        # Calculate incidence mild disease
        dIm_inc_new = (1-f_ud)/gamma*Ip - Im_inc

        return dS, dE, dIp, dIud, dId, dR, dIm_inc_new

Might decide to drop the stratified parameters concept to make the code more sleak but still undecided atm.