Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time dependant functions not working for stratified parameters #368

Open
woldmuyn opened this issue Nov 11, 2022 · 1 comment
Open

time dependant functions not working for stratified parameters #368

woldmuyn opened this issue Nov 11, 2022 · 1 comment

Comments

@woldmuyn
Copy link
Contributor

Technical questions

  • Python version: 3.10.6
  • Operating System: windows10 64 bit

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
Copy link
Collaborator

twallema commented Nov 14, 2022

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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants