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

Adding check_parameter_positivity() function to seir.py #428

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

emprzy
Copy link
Collaborator

@emprzy emprzy commented Dec 17, 2024

Describe your changes.

This pull request introduces a function called check_parameter_positivity() to seir.py. check_parameter_positivity() takes in an array of parsed parameters, as well as parameter names, subpopulation names, and dates, checks for the existence of negative parameter values, and throws a ValueError error if they are found. When throwing the error, check_parameter_positivity() will only print the earliest (w.r.t date) negative parameter to avoid redundant feedback. Example output will resemble:

The earliest date negative for each subpop and unique parameter are:
subpop: 50000, parameter eta_X0toX3_highIE*1*1*nuage18to64HR: 2023-07-21
subpop: 32000, parameter eta_X1toX4_highIE*1*1*nuage0to17: 2024-02-15
subpop: 28000, parameter eta_X1toX4_highIE*1*1*nuage18to64LR: 2025-06-01

A test function, test_check_parameter_positivity() has also been added to test_seir.py to test check_parameter_positivity().

Does this pull request make any user interface changes? If so please describe.

No changes to the user interface.

What does your pull request address? Tag relevant issues.

This pull request addresses GH #215.

Tag relevant team members.

@jcblemai

@emprzy
Copy link
Collaborator Author

emprzy commented Dec 17, 2024

Still need to add the test function (not ready yet for review)

@TimothyWillard TimothyWillard added enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. quick issue Short or easy fix. next release Marks a PR as a target to include in the next release. low priority Low priority. labels Dec 18, 2024
@TimothyWillard TimothyWillard linked an issue Dec 18, 2024 that may be closed by this pull request
@emprzy emprzy marked this pull request as ready for review December 18, 2024 18:02
@emprzy
Copy link
Collaborator Author

emprzy commented Dec 18, 2024

@jcblemai I have initial concerns that I did not properly instantiate ModelInfo in my test_seir.py::test_neg_params() function. Also, I'm hesitant about the parameters I passed into my neg_params() (line ~163 of seir.py) function call being correct extractions of the specific data that the function calls for. Haven't run checks yet but wanted to say that's what I will likely need help on.

@jcblemai
Copy link
Collaborator

I'm very, very bad at naming things (Carl, Tim are definitely very good at this) but neg_param() is not informative enough as a function name, something like check_parameter_positivity or something seems more suitable.

@jcblemai
Copy link
Collaborator

jcblemai commented Dec 19, 2024

parsed_parameter has shape (n_parsed_parameters(unique_strings) X n_times X n_subpop), is that what's causing the CI error ?

EDIT: no, see below:

@jcblemai
Copy link
Collaborator

oh and you are right, this is not passing the right parameters. Basically, within flepimop the workflow is

  1. parameters are drawn > parameters array, same for all subpop and times (except if the parameter is a time series), an array of dimensions n_parameters, n_times, n_subpop (unsure of the order)
  2. Modifiers are applied, this changes the array (not the dimensions) so parameters varies in time and subpop according to their modifiers
  3. Then, the compartments module computes the way to aggregate parameters for the sampler, e.g if on transition has a rate of beta * phi / gamma we do NOT want to pass beta, phi, and gamma to the simulator because
  • it's a jit compiled function so parsing this formula there is a big hassle and waste of time
  • we don't use these values separately anyway
    So instead compartments compute unique_strings (each one being a formula, a constant, or a a parameter name), and then if you give a parameter array (as above, modified by NPI) to the compartments module it will pre-compute these unique_strings (which are different parameters in some sort) by parsing each formula. This array is called, bad name, parsed_parameter and has size n_unique_strings, n_days, n_subpop

Your function checks the parsed_parameters because each of these steps can input a negative value. You then want to test the fully parsed thing.

Hence, to test, once you have modinf you need to:

# draw some parameters
p_draw = modinf.parameters.parameters_quick_draw(n_days=modinf.n_days, nsubpops=modinf.nsubpops)

# p_draw > SEE SCREENSHOT 2!!! A  SINGLE LINE

# build a modifier object
npi_seir = seir.build_npi_SEIR(modinf=modinf, load_ID=False, sim_id2load=None, config=config)
# apply the NPI to the parameters
reduced_parameters = modinf.parameters.parameters_reduce(p_draw, npi_seir)

# reduced_parameters > SEE SCREENSHOT 2!!! A TIMESERIE

# parse the compartments:
unique_strings, transition_array,proportion_array, proportion_info  = self.modinf.compartments.get_transition_array()

# parse the unique_string and compute the parsed parameter objects
parsed_parameters = modinf.compartments.parse_parameters(reduced_parameters, modinf.parameters.pnames, unique_strings)

# parsed_parameters > SEE SCREENSHOT 3!!! now it's a time series that is computed from a formula
Screenshot 2024-12-19 at 15 49 02 Screenshot 2024-12-19 at 15 49 08 Screenshot 2024-12-19 at 15 49 16

@emprzy emprzy changed the title Adding neg_params() function to seir.py Adding check_parameter_positivity() function to seir.py Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. low priority Low priority. next release Marks a PR as a target to include in the next release. quick issue Short or easy fix.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detect negative rate and give a nice error when that happens
3 participants