Repository navigation
Conversation
e2290ab to
408403c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #560 +/- ##
==========================================
+ Coverage 78.44% 78.81% +0.36%
==========================================
Files 68 69 +1
Lines 7876 8037 +161
Branches 1406 1445 +39
==========================================
+ Hits 6178 6334 +156
- Misses 1214 1215 +1
- Partials 484 488 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
74b7276 to
e74ee3b
Compare
e1d0f09 to
2c303c3
Compare
| problem["scaling"].nominal_value = None | ||
| problem["offset1"].nominal_value = 0 | ||
| problem["offset2"].lb = -1 | ||
| problem["offset2"].ub = 10 | ||
| with pytest.warns(UserWarning, match="no positive nominal value"): | ||
| problem, _ = reparametrize_log( | ||
| problem, ["scaling", "offset1", "offset2"] | ||
| ) |
There was a problem hiding this comment.
Is this warning for offset1? If so, then maybe it's fine if the spec allows -inf for log10_offset1 nominal value.
| @pytest.mark.parametrize("prior", [C.UNIFORM, C.NORMAL, C.GAMMA]) | ||
| def test_reparametrize_log_inexpressible_prior(prior): | ||
| problem = _problem() | ||
| problem["scaling"].prior_distribution = prior | ||
| problem["scaling"].prior_parameters = [1, 2] | ||
| with pytest.raises(ValueError, match="cannot be expressed"): | ||
| reparametrize_log(problem, ["scaling"]) |
There was a problem hiding this comment.
Docstring? Is the issue that we can't implement the same "uniform" distribution after log-scaling the parameter?
| ln_b = math.log(10) | ||
| # not `math.log(x) / ln_b`, which is inexact for powers of 10 | ||
| log_b = math.log10 |
There was a problem hiding this comment.
ln and log are the same for me -- maybe log_factor for ln_b/log_function for log_b?
| if problem.extensions.sciml is not None: | ||
| raise NotImplementedError( | ||
| "Reparametrization of PEtab SciML problems is not supported." | ||
| ) |
There was a problem hiding this comment.
NotImplementedError if any kind of extension is required in the problem config?
| if model.sbml_model.getParameter(p) is None: | ||
| raise NotImplementedError( | ||
| f"Model entity `{p}' is not an SBML parameter." | ||
| ) |
There was a problem hiding this comment.
Fine as is. Although I guess this error should also occur elsewhere/earlier in the package in general, that a parameter in the parameter table must be a parameter in the model.
| elif p in priors or par.prior_distribution is None or not par.estimate: | ||
| # priors of non-estimated parameters are irrelevant | ||
| prior_distribution, prior_parameters = None, [] |
There was a problem hiding this comment.
re: not par.estimate: is it necessary to drop the pre-existing prior instead of converting it? Seems more like a NotImplementedError
| ) | ||
|
|
||
| if par.estimate: | ||
| lb = log_b(par.lb) if par.lb > 0 else -math.inf |
There was a problem hiding this comment.
I guess we could define somewhere, some log and log10 functions like
def log10(x):
return math.log10(x) if x != 0 else -math.inf
| set_initial_assignment( | ||
| model, | ||
| parameter_id, | ||
| b_expr ** sp.Symbol(new_id), |
There was a problem hiding this comment.
petab_symbol? Probably irrelevant.
| b_expr: sp.Expr, | ||
| log_b, | ||
| ) -> None: | ||
| """Log-transform placeholders overridden by reparametrized parameters.""" |
There was a problem hiding this comment.
Describe here any potential issues? e.g. that placeholders need to be overridden by either no reparametrized parameters, or only reparametrized parameters with the same base.
PEtab v2 has no `parameterScale`. To estimate a parameter `p` on log scale (and to specify priors for `log10(p)`), `p` has to be replaced by a new parameter `log10_p` with `p = 10^log10_p`. `reparametrize_log` does this for a given set of parameters on a copy of the problem and returns the copy and the mapping of old to new IDs: * parameter table: log-transformed bounds and nominal values (a lower bound of 0 becomes -inf); priors given explicitly, or derived from `log-normal`, `log-laplace` and `log-uniform` priors * SBML model: new parameter `log10_p` and initial assignment `p = 10^log10_p` * observable/noise formulas and condition table target values: `p` -> `10^log10_p` * measurement table overrides: `p` -> `log10_p`, numeric overrides are log-transformed, and the placeholder `ph` -> `10^ph` in the formulas Base e is supported as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2c303c3 to
7fc047b
Compare
PEtab v2 has no
parameterScale. To estimate a parameter<id>on log scale, or to specify a prior forlog10(<id>), the v2 spec recommends replacing<id>by a new parameterlog10_<id>with<id> = 10^log10_<id>.This adds
petab.v2.reparametrize_log(problem, parameter_ids, ...), which does this for the given parameters on a copy of the problem and returns the copy and the mapping of old to new parameter IDs:priorsargument, or derived fromlog-normal,log-laplaceandlog-uniformpriors on<id>(other priors on<id>raise)log10_<id>and initial assignment<id> = 10^log10_<id>(replacing any existing one;<id>staysconstant=true)<id>→10^log10_<id>phis replaced by10^phin the formulasA lower bound of
0becomes-inf, following PEtab-dev/PEtab#682. If other parameters have priors, such a parameter needs an explicit prior, since the defaultuniform(lb, ub)would be improper; otherwise, aValueErroris raised.Base e (
log_<id>) is supported as well. The procedure follows the one described in the proposed v1→v2 migration guide (PEtab-dev/PEtab#680).Split off from #539, which uses this in
petab1to2(reparametrize=...)to preserve v1 parameter-scale priors.🤖 Generated with Claude Code