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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
baeafb3
Set up stochattic probability-based transitions to allow for measurin…
Rowanmh Oct 11, 2021
4037277
add stochastic_rounding
Rowanmh Oct 12, 2021
425223d
Random seed for parset sampling, random.randn -> default_rng sampling
Rowanmh Nov 5, 2021
e3c6285
default_rng for programs/covouts also
Rowanmh Nov 5, 2021
6cbcb6f
Update project.py
Rowanmh Nov 5, 2021
752154a
Update project.py
Rowanmh Nov 5, 2021
3965276
Pass the same random number generator within a given model run rather…
Rowanmh Nov 7, 2021
ac4e458
Consistent seeding
Rowanmh Nov 7, 2021
1e7c94f
Pass generators within kwargs, and handle that option in parallel_pro…
Rowanmh Nov 7, 2021
930c10e
Optional acceptance criteria for sampled_sims - to ensure that sample…
Rowanmh Nov 7, 2021
0b4e493
Update project.py
Rowanmh Nov 7, 2021
0e3bb45
Acceptance criteria evaluated during runtime or postprocessing as app…
Rowanmh Nov 8, 2021
224c2a6
Merge branch 'develop' into stochastic_transitions
Rowanmh Feb 22, 2023
211a7fd
Fix ResidualJunctionCompartment not applying stochasticity correctly …
kelvinburke Mar 1, 2023
98b7274
Whitespace
Rowanmh Mar 3, 2023
b955a10
Merge pull request #473 from atomicateam/stochastic_transitions_fix
Rowanmh May 10, 2023
3188662
Merge remote-tracking branch 'origin/master' into stochastic_transitions
RomeshA Jun 18, 2023
33b9da7
Merge pull request #486 from atomicateam/develop
RomeshA Sep 26, 2023
d1839ee
Merge pull request #488 from atomicateam/develop
RomeshA Oct 20, 2023
a545715
Add rng_sampler=None to Programset.sample()
kelvinburke Nov 1, 2023
61ffc2d
Merge branch 'develop' into stochastic_transitions
Rowanmh Nov 1, 2023
da06bbb
Merge branch 'stochastic_transitions' of github.com:atomicateam/atomi…
RomeshA Nov 2, 2023
72f231d
Keep "Output" column in worksheet and don't group by output, just pri…
kelvinburke Nov 2, 2023
76a1dba
Also make sure the required_width of a column fits the column name
kelvinburke Nov 2, 2023
1ee101c
Add "constant" to reserved_keywords
Rowanmh Nov 6, 2023
efcf4c2
Merge remote-tracking branch 'origin/databook_fixes' into stochastic_…
Rowanmh Nov 10, 2023
eb464d0
Merge remote-tracking branch 'origin/dont-group-results-excel' into s…
Rowanmh Nov 10, 2023
70f34cd
Use ax = fig.gca() instead of ax = plt.gca() so that you can have mul…
kelvinburke Nov 24, 2023
02c4cb9
Improve error message when different y-labels
kelvinburke Nov 24, 2023
17efbee
Merge pull request #495 from atomicateam/develop
RomeshA Feb 5, 2024
269f712
Add test_tox_markovchain.py
kelvinburke Apr 11, 2024
c9dfa22
Merge remote-tracking branch 'origin/stochastic_transitions' into sto…
RomeshA Jun 5, 2024
c6d990c
Merge remote-tracking branch 'origin/develop' into stochastic_transit…
RomeshA Jun 5, 2024
9dcb653
Fix tests
RomeshA Jun 7, 2024
e39b780
Fix seed selection
RomeshA Jun 7, 2024
8abb36a
Implement very simple example of test reordering for further use later
RomeshA Jun 7, 2024
2a8bc1e
Formatting pass
RomeshA Jun 7, 2024
3e76bf7
Update to Python 3.12
RomeshA Jun 26, 2024
a8ef28d
Enable auto calibration of transfers
RomeshA Jun 27, 2024
c6dbf4b
Update test pipeline
RomeshA Jun 27, 2024
5af7e4b
Update documentation
RomeshA Jun 27, 2024
9a353e1
Update setup.py
RomeshA Jun 27, 2024
8a1b0c1
Merge remote-tracking branch 'origin/develop' into enable-transfer-ca…
RomeshA Jun 27, 2024
6a49703
Update deprecated scipy function
RomeshA Jun 28, 2024
222ad88
Merge branch 'enable-transfer-calibration' into stochastic_transitions
RomeshA Jun 28, 2024
c2fe4ae
Rename stochastic to multinomial
RomeshA Aug 19, 2024
d1c2223
Prefill interaction tables with Y/N more logically
Rowanmh Sep 2, 2024
c752086
More informative sc.prepr output (useful when debugging)
Rowanmh Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This file records changes to the codebase grouped by version release. Unreleased changes are generally only present during development (relevant parts of the changelog can be written and saved in that section before a version number has been assigned)

## [1.28.5] - 2023-06-28

- Enable automated calibration of transfers and updated documentation to cover this feature

## [1.28.4] - 2023-05-27

- Added an option to save initial compartment sizes inside a `ParameterSet`. Importantly, this saved representation allows setting the initial _subcompartment_ sizes for a `TimedCompartment`. It therefore offers the possibility of initializing the model in a steady state computed from a previous simulation run, that would not be possible to initialize conventionally because standard initialization uniformly distributes people into the subcompartments of a timed compartment.
Expand Down
7 changes: 4 additions & 3 deletions atomica/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def _update_parset(parset, y_factors, pars_to_adjust):
tokens = par_name.split("_from_")
par = parset.transfers[tokens[0]][tokens[1]]
par.y_factor[pop_name] = y_factors[i]
raise NotImplementedError


def _calculate_objective(y_factors, pars_to_adjust, output_quantities, parset, project):
Expand Down Expand Up @@ -123,7 +122,10 @@ def calibrate(project, parset: ParameterSet, pars_to_adjust, output_quantities,
:param pars_to_adjust: list of tuples, (par_name,pop_name,lower_limit,upper_limit)
the pop name can be None, which will be expanded to all populations
relevant to the parameter independently, or 'all' which will instead operate
on the meta y factor.
on the meta y factor. To calibrate a transfer, the parameter name should be set to
``'<tranfer_code_name>_from_<from_pop>'`` and then the destination population can be specified
as the ``pop_name``. For example, to automatically calibrate an aging transfer 'age' from 5-14
to 15-64, the tuple would contain ``pars_to_adjust=[('age_from_5-14','15-64',...)]``
:param output_quantities: list of tuples, (var_label,pop_name,weight,metric), for use in the objective
function. pop_name=None will expand to all pops. pop_name='all' is not supported
:param max_time: If using ASD, the maximum run time
Expand Down Expand Up @@ -243,7 +245,6 @@ def calibrate(project, parset: ParameterSet, pars_to_adjust, output_quantities,
tokens = par_name.split("_from_")
par = args["parset"].transfers[tokens[0]][tokens[1]]
logger.debug("parset.transfers['{}']['{}'].y_factor['{}']={:.2f}".format(tokens[0], tokens[1], pop_name, par.y_factor[pop_name]))
raise NotImplementedError # Transfers might be handled differently in Atomica

args["parset"].name = "calibrated_" + args["parset"].name

Expand Down
55 changes: 28 additions & 27 deletions atomica/demos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""

Check failure on line 1 in atomica/demos.py

View check run for this annotation

Azure Pipelines / atomicateam.atomica

atomica/demos.py

F821 undefined name 'demos'
Raw output
52:82 F821 undefined name 'demos'
Defines some defaults for Atomica projects

Version: 2018sep24
Expand All @@ -11,10 +11,30 @@
from .scenarios import BudgetScenario
from .utils import TimeSeries

__all__ = ["demo", "make_demo_scenarios"]


def demo(which: str = None, do_run: bool = True, addprogs: bool = True) -> Project:
__all__ = ["demo", "demo_projects", "make_demo_scenarios"]


demo_projects = [
"udt",
"udt_dyn",
"usdt",
"cervicalcancer",
"sir",
"diabetes",
"combined",
"service",
"hypertension",
"hypertension_dyn",
"hiv",
"hiv_dyn",
"tb_simple",
"tb_simple_dyn",
"tb",
"dt",
]


def demo(which: str = "sir", do_run: bool = True, addprogs: bool = True) -> Project:
"""
Return a demo project

Expand All @@ -25,30 +45,11 @@

"""

options = [
"udt",
"udt_dyn",
"usdt",
"cervicalcancer",
"sir",
"diabetes",
"combined",
# 'service',
"hypertension",
"hypertension_dyn",
"hiv",
"hiv_dyn",
"tb_simple",
"tb_simple_dyn",
"environment",
"tb",
]

dtdict = sc.odict.fromkeys(options, 1.0)
dtdict = sc.odict.fromkeys(demo_projects, 1.0)
dtdict["tb"] = 0.5

if which is None or which not in options:
raise Exception("Supported project types are:\n%s" % ("\n".join(options)))
if which not in demo_projects:
raise Exception("Supported demonstration projects are:\n%s" % ("\n".join(demos)))

framework = LIBRARY_PATH / f"{which}_framework.xlsx"
databook = LIBRARY_PATH / f"{which}_databook.xlsx"
Expand All @@ -61,7 +62,7 @@
if do_run:
P.run_sim(store_results=True)

if addprogs:
if addprogs and progbook.exists():
logger.debug("Loading progbook")
P.load_progbook(progbook)

Expand Down
5 changes: 3 additions & 2 deletions atomica/excel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in atomica/excel.py

View check run for this annotation

Azure Pipelines / atomicateam.atomica

atomica/excel.py

E226 missing whitespace around arithmetic operator
Raw output
1202:186 E226 missing whitespace around arithmetic operator
"""
Miscellaneous utility functions for Excel files

Expand Down Expand Up @@ -424,7 +424,8 @@
raise Exception('Unknown TimeDependentConnections type - must be "transfer" or "interaction"')

def __repr__(self):
return '<TDC %s "%s">' % (self.type.title(), self.code_name)
# return '<TDC %s "%s">' % (self.type.title(), self.code_name)
return sc.prepr(self)

@classmethod
def from_tables(cls, tables: list, interaction_type):
Expand Down Expand Up @@ -834,7 +835,7 @@
from_idx = self.from_pops.index(from_pop)
to_idx = self.to_pops.index(to_pop)
if boolean_choice:
value = "Y" if value else "N"
value = "Y" if (value.vals or value.assumption) else "N"
content[from_idx, to_idx] = value

# Write the content
Expand Down
3 changes: 1 addition & 2 deletions atomica/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,8 @@ def _convert_framework_columns(framework):
framework._validate()
return framework


@migration("ParameterSet", "1.28.3", "1.28.4", "Add initialization atttribute")
def _parset_add_initialization(parset):
parset.initialization = None
return parset


Loading
Loading