-
Notifications
You must be signed in to change notification settings - Fork 4
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
Random Draws For SEIR Parameters Per Slot #429
base: dev
Are you sure you want to change the base?
Conversation
Created a test that shows the issue of the SEIR parameters not being randomly drawn per a slot wheras the outcome parameters are. Test currently fails.
Added a method to reinit distribution parameters. When the `Parameters` class is initialized it creates this distribution parameters but also captures the random seed at the time of initialization which makes the draws non-random across processes. Added a method to reinitialize distribution parameters when reseeding. Not a perfect solution, the ambigious random seed settings is rather confusing for development.
Added a unit test to the `Parameters` class unit tests for the `reinitialize_distributions` method that demonstrates how this method affects the seeding behavior across workers.
I did some testing of how random draws of parameters work for each parameter type, using the config config_sample_2pop_modifiers_test_random.yml which is now in the tutorials folder In the original code in the main branch, the behavior is:
Thus variation in In this branch, the behavior is:
So now variation in However note that users are likely surprised by the variation by location in If I instead run a config where for both seir and outcome modifiers I use
which is what we expect. I don't know how to make To summarize, yes this PR seems to fix the main underlying problem, but this issue has led me to notice a behavior that needs to be documented better and discussed - during forward-only simulations, when Thoughts from @jcblemai, @shauntruelove, @saraloo on the desired behavior here would be helpful. |
_test_random has one parameter of each type (seir, outcome, seir_modifiers, outcome_modifiers) that varies by slot _test_random_subpop_groups is same as above but for snpi and hnpi parameters it uses subpop_groups to force the same for all locations
Nice investigation. Agree we need to clearly document what matches / doesn't when stochastically simulating. Where in the gitbook do you think it's best to capture that? Regarding behavior, all the stochastic features should match in the same way in my opinion. Weird that spar seems to deviate, so we should figure out why that is. I kind of think that location shouldn't cause a different sample either, but it's most important that we have consistent behavior. |
I agree Alison on consistency. The current state is not motivated by anything but historical hastly made decisions during COVID (fixed R0 across subpops, but age structure different in each state). We should change that carefully. Now:
|
1f77156
to
64b180c
Compare
Hmm yes thanks for this investigation @alsnhll , agree with @jcblemai it's just historical decision making responsible for these inconsistencies. I'm not entirely sure what we should define here... I see a few arguments either way
Could use some discussion wrt how to harmonise these definitions. In any case, needs to be made clear in docs etc.
Similar inconsistencies in the npi parameters too as alison points out - ie we can group |
Work on this has been paused until after the next release due to higher priority items. |
Added a utility to `gempyor.testing` to run a python script in a seperate process for unit testing purposes. Consolidated existing unit tests to use this new functionality.
Instead of generating a random seed in `onerun_delayframe_outcomes` based on the sim id use an explicit random seed passed by `run_parallel_outcomes`, added internal wrapper `_onerun_delayframe_outcomes_with_random_seed` to facilitate per an @jcblemai suggestion.
Move helper being used in tests into `gempyor.utils.read_directory`. This helper will filter files in a given `model_output/` directory and combine them into one single pandas DataFrame. Not designed for prod use, but helpful in testing or small runs.
Added `gempyor.testing.setup_example_from_tutorials` testing helper to construct an example config and inputs from a file in the `examples/tutorials/` directory.
Changed `gempyor.testing.setup_example_from_tutorials` to use `$FLEPI_PATH` instead of using `__file__` because the the latter only works when the package is installed with the `--editable` flag from pip.
Refactored the unit tests for `flepimop simulate` related to SEIR parameter draws to use configurable config files and assertions with the purpose of expanding test cases.
Mostly for readability.
Added in test cases working with the 'config_sample_2pop_modifiers_test_random.yml' configuration file as well as making assertions on the outcome/SEIR modifier draws.
Changed out `np.random.randint` for `np.random.choice` to prevent the unlikely possibility of replacement draws.
This PR is now ready for review again. The biggest changes since the last comments are:
The behavior is now:
A question that was discussed, but doesn't seem like we came to a strong conclusion on is "Should |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice, appreciate the seed handling. Very nice that we get same behavior. Does hpar varies per location even without an helper file ? In any case, I think hpar and spar should be harmonized and I'm agnostic to the choice taken.
I'm not sure what you mean by this, could you elaborate? What helper file are you referring to? |
outcome config option Also, to answer my question above: even without param_from_file, outcomes probabilities are "one draw per subpop" making them inconsistent with how spar are used. |
I think harmonising |
Describe your changes.
This pull request addresses the bug described in GH-406 where new seir parameters were not drawn across slots.
Does this pull request make any user interface changes? If so please describe.
The user interface changes are:
Parameters.reinitialize_distributions
method that recreates the randomly drawn seir parameters so that they do not hold onto the prior random state, andSEIR.run_parallel_SEIR
will now draw random seir parameters across jobs.These changes have not been documented yet, @alsnhll where do you think is the best place to describe this behavior (I'll make these changes before marking this PR as ready for review)?
What does your pull request address? Tag relevant issues.
This pull request addresses GH-406.
Tag relevant team members.
@alsnhll