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

Stochastic transitions #474

Draft
wants to merge 48 commits into
base: develop
Choose a base branch
from
Draft

Stochastic transitions #474

wants to merge 48 commits into from

Conversation

RomeshA
Copy link
Contributor

@RomeshA RomeshA commented May 21, 2023

WIP PR for adding stochastic transition functionality

Rowanmh and others added 16 commits October 12, 2021 03:38
…g probability of e.g. elimination of a disease
…ropriate

Random seeds for runs ensures consistency (some needless rerunning of seeded runs that will fail between scenarios though)
…with a ">" residual link.

 - `outflow` wasn't updated with the stochastic outflow_fractions, and
 - The probabilities need to sum to 1 in a multinomial so we give the residual probability to the residual link
 - Also checks that net_inflow is an integer and throws an error if it is not
Fix ResidualJunctionCompartment not applying stochasticity correctly
@RomeshA
Copy link
Contributor Author

RomeshA commented May 21, 2023

One thing that would be nice to look into for this is having the Sim use an on-board RNG more generally, since random numbers are also supported inside parameter functions. That might simplify some of the logic around accessing the RNG if it's always present. @Rowanmh is it necessary for each stochastic compartment to have its own RNG?

@@ -2248,6 +2322,23 @@ def build(self, parset):
obj.preallocate(self.t, self.dt)
pop.initialize_compartments(parset, self.framework, self.t[0])

#More finally, set up acceptance criteria for those which should be checked at runtime (variables that have ._is_dynamic = True), and those which can only be checked after conclusion
if self.acceptance_criteria:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should be more generic about this in Atomica e.g., support a generic callable and defer the specific validation method to the user


if rand_seed is not None:
rng = np.random.default_rng(seed = rand_seed)
seed_samples = rng.integers(1e15, size=n_samples)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some new recommendations for this using SeedSequence

atomica/model.py Outdated
@@ -1954,13 +2016,16 @@ def report_characteristic(charac, n_indent=0):

# Otherwise, insert the values
for i, c in enumerate(comps):
c[0] = max(0.0, x[i])
if self.stochastic:
c[0] = stochastic_rounding(max(0.0, x[i]), rng_sampler = self.rng_sampler)#integer values (still represented as floats)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the rounding is done here after checking initial condition validity is it possible that this could introduce invalid initial conditions? Or otherwise introduce discrepancies with the initial characteristic values?

Rowanmh and others added 24 commits November 6, 2023 11:12
Previous "if value" didn't make sense as an object - was always True, using (value.vals of value.assumption) will still generally return True based on defaults, but allows prefilling interaction tables when generating a databook if data has been specified already
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

Successfully merging this pull request may close these issues.

3 participants