Skip to content

Commit 265bf2d

Browse files
authored
740 Fix ParameterStudy examples in Python (#741)
1 parent b813601 commit 265bf2d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pycode/examples/simulation/migration_parameter_study.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ def parameter_study():
8585
2000)
8686
model.apply_constraints()
8787
graph.add_node(id=1, model=model)
88-
migration_coefficients = 0.1 * np.ones(8)
88+
migration_coefficients = 0.1 * np.ones(model.populations.numel())
8989
migration_params = mio.MigrationParameters(migration_coefficients)
9090
# one coefficient per (age group x compartment)
9191
graph.add_edge(0, 1, migration_params)
9292
# directed graph -> add both directions so coefficients can be different
9393
graph.add_edge(1, 0, migration_params)
9494

9595
# process the result of one run
96-
def handle_result(graph):
96+
def handle_result(graph, run_idx):
9797
print(f'run {handle_result.c}')
9898
handle_result.c = handle_result.c + 1
9999
for node_idx in range(graph.num_nodes):

pycode/examples/simulation/parameter_studies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def parameter_study():
7373
print(model.parameters.ContactPatterns.cont_freq_mat[1].baseline)
7474
# process the result of one run
7575

76-
def handle_result(graph):
76+
def handle_result(graph, run_idx):
7777
group = secir.AgeGroup(0)
7878
print("run {} with infection rate {:.2G}".format(handle_result.c, graph.get_node(
7979
0).property.model.parameters.TransmissionProbabilityOnContact[group].value))
@@ -93,8 +93,8 @@ def handle_result(graph):
9393
graph = secir.ModelGraph()
9494
graph.add_node(0, model)
9595
graph.add_node(1, model)
96-
graph.add_edge(0, 1, 0.01 * np.ones(8*num_groups))
97-
graph.add_edge(1, 0, 0.01 * np.ones(8*num_groups))
96+
graph.add_edge(0, 1, 0.01 * np.ones(model.populations.numel()*num_groups))
97+
graph.add_edge(1, 0, 0.01 * np.ones(model.populations.numel()*num_groups))
9898

9999
study = secir.ParameterStudy(graph, t0=1, tmax=10, dt=0.5, num_runs=3)
100100
study.run(handle_result)

0 commit comments

Comments
 (0)