UGentBiomath / COVID19-Model

Compartmental SEIQRD model to model the effects of government policies on SARS-CoV-2 spread in Belgium. Macro-economic Input-Output model to assess the economic impact of sector closure and changes in consumption patterns. Quality-adjusted life-years model to assess the health economic impact of SARS-CoV-2.
MIT License
23 stars 30 forks source link

time dependant functions not working for stratified parameters #368

Open woldmuyn opened 2 years ago

woldmuyn commented 2 years ago

Technical questions

Description

Time dependant functions is not working for stratified parameters, because of bug in parameter check.

What I Did

The specified time-dependent parameter 'alpha' is not an existing model parameter

in _validate_time_dependent_parameters(self)

all_param_names = model.parameter_names.copy()

for lst in model.parameters_stratified_names:
    all_param_names.extend(lst)

if model.stratification:
    all_param_names.extend(model.stratification)

print(all_param_names)

output: ['Ki', 'Kp', 'covid_H', 'covid_dH', 'covid_min', 'a', 'l', 'p', 'h', 'a', 'b', 'e', 't', 'a', 'g', 'a', 'm', 'm', 'a', 'MDC_keys']

Solution

Change extend to append

twallema commented 2 years ago

Note that in the following model, there is one stratified parameter alpha, which is stratified according to the only stratification Nc in this model. If the parameter alpha is defined as a list inside a list in the parameters_stratified_names.

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

    state_names = ['S','E','Ia','Im','R','Im_inc']
    parameter_names = ['beta','sigma','f_a','gamma']
    parameters_stratified_names = [['alpha'],]
    stratification = ['Nc']

    @staticmethod
    def integrate(t, S, E, Ia, Im, R, Im_inc, beta, sigma, f_a, gamma, alpha, Nc):

        # Calculate total population
        T = S+E+Ia+Im+R
        # Calculate differentials
        dS = -beta*Nc@((Ia+Im)*S/T)
        dE = beta*Nc@((Ia+Im)*S/T) - 1/sigma*E
        dIa = f_a*E/sigma - 1/gamma*Ia
        dIm = (1-f_a)/sigma*E - 1/gamma*Im
        dR = 1/gamma*(Ia+Im)
        # Calculate incidence mild disease
        dIm_inc_new = (1-f_a)/sigma*E - Im_inc

        return dS, dE, dIa, dIm, dR, dIm_inc_new

as opposed to,

parameters_stratified_names = ['alpha',]

Then the TDPFs do work..