|
5 | 5 | import numpy as np |
6 | 6 | import pandas as pd |
7 | 7 | import pytest |
8 | | -from scipy.stats import norm |
9 | 8 |
|
10 | 9 | import petab.v1 |
11 | | -from petab.v1 import get_simulation_conditions |
| 10 | +from petab.v1 import ESTIMATE, get_simulation_conditions |
| 11 | +from petab.v1.distributions import Distribution |
12 | 12 | from petab.v1.priors import priors_to_measurements |
13 | 13 |
|
14 | 14 |
|
@@ -102,33 +102,34 @@ def test_priors_to_measurements(problem_id): |
102 | 102 |
|
103 | 103 | # get prior objective function contribution |
104 | 104 | parameter_ids = petab_problem_priors.parameter_df.index.values[ |
105 | | - (petab_problem_priors.parameter_df[petab.v1.ESTIMATE] == 1) |
| 105 | + (petab_problem_priors.parameter_df[ESTIMATE] == 1) |
106 | 106 | & petab_problem_priors.parameter_df[ |
107 | 107 | petab.v1.OBJECTIVE_PRIOR_TYPE |
108 | 108 | ].notna() |
109 | 109 | ] |
110 | | - priors = petab.v1.get_priors_from_df( |
111 | | - petab_problem_priors.parameter_df, |
112 | | - mode="objective", |
113 | | - parameter_ids=parameter_ids, |
114 | | - ) |
| 110 | + priors = [ |
| 111 | + Distribution.from_par_dict( |
| 112 | + petab_problem_priors.parameter_df.loc[par_id], type_="objective" |
| 113 | + ) |
| 114 | + for par_id in parameter_ids |
| 115 | + ] |
115 | 116 | prior_contrib = 0 |
| 117 | + x_scaled_dict = dict( |
| 118 | + zip( |
| 119 | + petab_problem_priors.x_free_ids, |
| 120 | + petab_problem_priors.x_nominal_free_scaled, |
| 121 | + strict=True, |
| 122 | + ) |
| 123 | + ) |
116 | 124 | for parameter_id, prior in zip(parameter_ids, priors, strict=True): |
117 | | - prior_type, prior_pars, par_scale, par_bounds = prior |
118 | | - if prior_type == petab.v1.PARAMETER_SCALE_NORMAL: |
119 | | - prior_contrib += norm.logpdf( |
120 | | - petab_problem_priors.x_nominal_free_scaled[ |
121 | | - petab_problem_priors.x_free_ids.index(parameter_id) |
122 | | - ], |
123 | | - loc=prior_pars[0], |
124 | | - scale=prior_pars[1], |
125 | | - ) |
| 125 | + if prior.type == petab.v1.PARAMETER_SCALE_NORMAL: |
| 126 | + prior_contrib -= prior.neglogprior(x_scaled_dict[parameter_id]) |
126 | 127 | else: |
127 | 128 | # enable other models, once libpetab has proper support for |
128 | 129 | # evaluating the prior contribution. until then, two test |
129 | 130 | # problems should suffice |
130 | 131 | assert problem_id == "Raimundez_PCB2020" |
131 | | - pytest.skip(f"Prior type {prior_type} not implemented") |
| 132 | + pytest.skip(f"Prior type {prior.type} not implemented") |
132 | 133 |
|
133 | 134 | assert np.isclose( |
134 | 135 | llh_priors + prior_contrib, llh_measurements, rtol=1e-3, atol=1e-16 |
|
0 commit comments