Skip to content

Commit ddb289f

Browse files
dilpathdweindl
andauthored
Add post--model-selection analysis methods (#125)
* track iterations; fix `ModelHash.get_model`; add `Model.__repr__` * add analysis module * fixme: use pypesto PR branch * unfix pypesto in tox.ini to use pyproject.toml * sort iterations in `group_by_iteration` * add `VIRTUAL_INITIAL_MODEL_HASH` * method to convert Models to dataframe; update plotting code * update vis notebook * doc analysis methods briefly * move models criterion getter to `Models`; add `Models.values()` for backwards compatibility; update plot code * test case 0009: add caveat * update expected test case results --------- Co-authored-by: Daniel Weindl <dweindl@users.noreply.github.com>
1 parent 9b9b95b commit ddb289f

37 files changed

+868
-1102
lines changed

doc/analysis.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Analysis
2+
========
3+
4+
After using PEtab Select to perform model selection, you may want to operate on all "good" calibrated models.
5+
The PEtab Select Python library provides some methods to help with this. Please request any missing methods.
6+
7+
See the Python API docs for the :class:`petab_select.Models` class, which provides some methods. In particular, :attr:`petab_select.Models.df` can be used
8+
to get a quick overview over all models, as a pandas dataframe.
9+
10+
Additionally, see the Python API docs for the ``petab_select.analysis`` module, which contains some methods to subset and group models,
11+
or compute "weights" (e.g. Akaike weights).

doc/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ petab-select Python API
77
:toctree: generated
88

99
petab_select
10+
petab_select.analyze
1011
petab_select.candidate_space
1112
petab_select.constants
1213
petab_select.criteria

doc/examples/calibrated_models/calibrated_models.yaml

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
AICc: 37.97523003111246
33
NLLH: 17.48761501555623
44
estimated_parameters:
5-
sigma_x2: 4.462298385653177
5+
sigma_x2: 4.462298422134608
6+
iteration: 1
67
model_hash: M_0-000
78
model_id: M_0-000
89
model_subspace_id: M_0
@@ -17,11 +18,12 @@
1718
petab_yaml: petab_problem.yaml
1819
predecessor_model_hash: virtual_initial_model
1920
- criteria:
20-
AICc: -0.1754060811089051
21-
NLLH: -4.0877030405544525
21+
AICc: -0.17540608110890332
22+
NLLH: -4.087703040554452
2223
estimated_parameters:
2324
k3: 0.0
24-
sigma_x2: 0.12242920113658744
25+
sigma_x2: 0.12242920113658338
26+
iteration: 2
2527
model_hash: M_1-000
2628
model_id: M_1-000
2729
model_subspace_id: M_1
@@ -36,11 +38,12 @@
3638
petab_yaml: petab_problem.yaml
3739
predecessor_model_hash: M_0-000
3840
- criteria:
39-
AICc: -0.27451405630430337
40-
NLLH: -4.137257028152152
41+
AICc: -0.27451438069575573
42+
NLLH: -4.137257190347878
4143
estimated_parameters:
42-
k2: 0.10147827639089564
43-
sigma_x2: 0.12142256779953603
44+
k2: 0.10147824307890803
45+
sigma_x2: 0.12142219599557078
46+
iteration: 2
4447
model_hash: M_2-000
4548
model_id: M_2-000
4649
model_subspace_id: M_2
@@ -55,11 +58,12 @@
5558
petab_yaml: petab_problem.yaml
5659
predecessor_model_hash: M_0-000
5760
- criteria:
58-
AICc: -0.7053270517931587
59-
NLLH: -4.352663525896579
61+
AICc: -0.7053270766271886
62+
NLLH: -4.352663538313594
6063
estimated_parameters:
61-
k1: 0.20160888007873565
62-
sigma_x2: 0.11713858557052499
64+
k1: 0.20160925279667963
65+
sigma_x2: 0.11714017664827497
66+
iteration: 2
6367
model_hash: M_3-000
6468
model_id: M_3-000
6569
model_subspace_id: M_3
@@ -74,12 +78,13 @@
7478
petab_yaml: petab_problem.yaml
7579
predecessor_model_hash: M_0-000
7680
- criteria:
77-
AICc: 9.294672948206841
78-
NLLH: -4.352663525896579
81+
AICc: 9.294672923372811
82+
NLLH: -4.352663538313594
7983
estimated_parameters:
80-
k1: 0.20160888007873565
84+
k1: 0.20160925279667963
8185
k3: 0.0
82-
sigma_x2: 0.11713858557052499
86+
sigma_x2: 0.11714017664827497
87+
iteration: 3
8388
model_hash: M_5-000
8489
model_id: M_5-000
8590
model_subspace_id: M_5
@@ -94,12 +99,13 @@
9499
petab_yaml: petab_problem.yaml
95100
predecessor_model_hash: M_3-000
96101
- criteria:
97-
AICc: 7.852170288089528
98-
NLLH: -5.073914855955236
102+
AICc: 7.8521704398854
103+
NLLH: -5.0739147800573
99104
estimated_parameters:
100-
k1: 0.20924739987621038
101-
k2: 0.0859065470362628
102-
sigma_x2: 0.1038731029818225
105+
k1: 0.20924804320838675
106+
k2: 0.0859052351446815
107+
sigma_x2: 0.10386846319370771
108+
iteration: 3
103109
model_hash: M_6-000
104110
model_id: M_6-000
105111
model_subspace_id: M_6
@@ -113,3 +119,25 @@
113119
k3: 0
114120
petab_yaml: petab_problem.yaml
115121
predecessor_model_hash: M_3-000
122+
- criteria:
123+
AICc: 35.94352968170024
124+
NLLH: -6.028235159149878
125+
estimated_parameters:
126+
k1: 0.6228488917665873
127+
k2: 0.020189424009226256
128+
k3: 0.0010850434974038557
129+
sigma_x2: 0.08859278245811462
130+
iteration: 4
131+
model_hash: M_7-000
132+
model_id: M_7-000
133+
model_subspace_id: M_7
134+
model_subspace_indices:
135+
- 0
136+
- 0
137+
- 0
138+
parameters:
139+
k1: estimate
140+
k2: estimate
141+
k3: estimate
142+
petab_yaml: petab_problem.yaml
143+
predecessor_model_hash: M_3-000

doc/examples/example_cli_famos.ipynb

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": 1,
25+
"execution_count": null,
2626
"id": "1f04dce0",
2727
"metadata": {},
2828
"outputs": [],
@@ -44,7 +44,7 @@
4444
},
4545
{
4646
"cell_type": "code",
47-
"execution_count": 2,
47+
"execution_count": null,
4848
"id": "a81560e6",
4949
"metadata": {},
5050
"outputs": [],
@@ -109,69 +109,10 @@
109109
},
110110
{
111111
"cell_type": "code",
112-
"execution_count": 3,
112+
"execution_count": null,
113113
"id": "bb1a5144",
114114
"metadata": {},
115-
"outputs": [
116-
{
117-
"name": "stdout",
118-
"output_type": "stream",
119-
"text": [
120-
"Executing iteration 1\n",
121-
"Executing iteration 2\n",
122-
"Executing iteration 3\n",
123-
"Executing iteration 4\n",
124-
"Executing iteration 5\n",
125-
"Executing iteration 6\n",
126-
"Executing iteration 7\n",
127-
"Executing iteration 8\n",
128-
"Executing iteration 9\n",
129-
"Executing iteration 10\n",
130-
"Executing iteration 11\n",
131-
"Executing iteration 12\n",
132-
"Executing iteration 13\n",
133-
"Executing iteration 14\n",
134-
"Executing iteration 15\n",
135-
"Executing iteration 16\n",
136-
"Executing iteration 17\n",
137-
"Executing iteration 18\n",
138-
"Executing iteration 19\n"
139-
]
140-
},
141-
{
142-
"name": "stderr",
143-
"output_type": "stream",
144-
"text": [
145-
"petab_select/petab_select/candidate_space.py:1142: RuntimeWarning: Model `model_subspace_1-0001011010010010` has been previously excluded from the candidate space so is skipped here.\n",
146-
" return_value = self.inner_candidate_space.consider(model)\n"
147-
]
148-
},
149-
{
150-
"name": "stdout",
151-
"output_type": "stream",
152-
"text": [
153-
"Executing iteration 20\n",
154-
"Executing iteration 21\n",
155-
"Executing iteration 22\n",
156-
"Executing iteration 23\n",
157-
"Executing iteration 24\n",
158-
"Executing iteration 25\n",
159-
"Executing iteration 26\n",
160-
"Executing iteration 27\n",
161-
"Executing iteration 28\n",
162-
"Executing iteration 29\n",
163-
"Executing iteration 30\n",
164-
"Executing iteration 31\n",
165-
"Executing iteration 32\n",
166-
"Executing iteration 33\n",
167-
"Executing iteration 34\n",
168-
"Executing iteration 35\n",
169-
"Executing iteration 36\n",
170-
"Executing iteration 37\n",
171-
"Model selection has terminated.\n"
172-
]
173-
}
174-
],
115+
"outputs": [],
175116
"source": [
176117
"%%bash -s \"$petab_select_problem_yaml\" \"$output_path_str\"\n",
177118
"petab_select_problem_yaml=$1\n",
@@ -217,7 +158,7 @@
217158
},
218159
{
219160
"cell_type": "code",
220-
"execution_count": 4,
161+
"execution_count": null,
221162
"id": "93caf071",
222163
"metadata": {},
223164
"outputs": [],
@@ -227,7 +168,7 @@
227168
},
228169
{
229170
"cell_type": "code",
230-
"execution_count": 5,
171+
"execution_count": null,
231172
"id": "cb61d0f7",
232173
"metadata": {},
233174
"outputs": [],

doc/examples/model_selection/calibrated_M1_4.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ criteria:
33
estimated_parameters:
44
k2: 0.15
55
k3: 0.0
6+
iteration: 1
67
model_hash: M1_4-000
78
model_id: M1_4-000
89
model_subspace_id: M1_4

doc/examples/model_selection/calibrated_M1_7.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ estimated_parameters:
44
k1: 0.25
55
k2: 0.1
66
k3: 0.0
7+
iteration: 2
78
model_hash: M1_7-000
89
model_id: M1_7-000
910
model_subspace_id: M1_7

doc/examples/model_selection/calibrated_models_1.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- criteria:
22
AIC: 180
33
estimated_parameters: {}
4+
iteration: 1
45
model_hash: M1_0-000
56
model_id: M1_0-000
67
model_subspace_id: M1_0
@@ -17,6 +18,7 @@
1718
- criteria:
1819
AIC: 100
1920
estimated_parameters: {}
21+
iteration: 1
2022
model_hash: M1_1-000
2123
model_id: M1_1-000
2224
model_subspace_id: M1_1
@@ -33,6 +35,7 @@
3335
- criteria:
3436
AIC: 50
3537
estimated_parameters: {}
38+
iteration: 1
3639
model_hash: M1_2-000
3740
model_id: M1_2-000
3841
model_subspace_id: M1_2

0 commit comments

Comments
 (0)