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

Order of non-stratified vs. stratified parameters in the integrate function shouldn't matter when initializing a model #9

Open
twallema opened this issue Nov 28, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@twallema
Copy link
Owner

Suggestion

Consider an SIR model stratified into two age groups (0-20 yo, 20-120 yo) with two parameters: beta, the per-contact chance of infection, and gamma, the recovery rate of the infected individuals. In the example beta is stratified and gamma is not.

class SIRstratified(ODEModel):

    # state variables and parameters
    state_names = ['S', 'I', 'R']
    parameter_names = ['gamma']
    parameters_stratified_names = ['beta']
    stratification_names = ['age_groups']

    @staticmethod
    def integrate(t, S, I, R, beta, gamma):
        """Basic SIR model"""
        # Model equations
        N = S + I + R
        dS = -beta*S*I/N
        dI = beta*S*I/N - gamma*I
        dR = gamma*I
        return dS, dI, dR

parameters = {"gamma": 0.2, "beta": np.array([0.8, 0.9])}
initial_states = {"S": [600_000 - 20, 400_000 - 10], "I": [20, 10], "R": [0, 0]}
coordinates = {'age_groups': ['0-20','20-120']}
model = SIRstratified(initial_states, parameters, coordinates=coordinates)

Providing the parameter beta before gamma yields the following error:

ValueError: The parameters in the 'integrate' function definition do not match the parameter_names + parameters_stratified_names + stratification: ['beta', 'gamma'] vs ['gamma', 'beta']

Ideally, the order in which the parameters are given should not matter when initializing the model.

@twallema twallema added the enhancement New feature or request label Nov 28, 2022
@twallema
Copy link
Owner Author

twallema commented Jan 9, 2023

This issue is partly resolved by PR #19. The order of the states, parameters, stratified parameters supplied to the integrate function does not matter as they are now keyworded. However, the user should still return the differentials in the same order as the state_names variable. Perhaps this can be resolved by using a dictionary, however, this may complicate matters when applying numba.njit to the integrate function. To be reconsidered at some later point.

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

No branches or pull requests

1 participant