-
Notifications
You must be signed in to change notification settings - Fork 7
v2: Startpoint sampling #380
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| from pathlib import Path | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| import numpy as np | ||
| import pandas as pd | ||
| import sympy as sp | ||
| from pydantic import AnyUrl, BaseModel, Field | ||
|
|
@@ -22,10 +23,10 @@ | |
| observables, | ||
| parameter_mapping, | ||
| parameters, | ||
| sampling, | ||
| yaml, | ||
| ) | ||
| from ..v1.core import concat_tables, get_visualization_df | ||
| from ..v1.distributions import Distribution | ||
| from ..v1.models.model import Model, model_factory | ||
| from ..v1.yaml import get_path_prefix | ||
| from ..v2.C import * # noqa: F403 | ||
|
|
@@ -726,24 +727,29 @@ def get_optimization_to_simulation_parameter_mapping(self, **kwargs): | |
| ) | ||
| ) | ||
|
|
||
| def sample_parameter_startpoints(self, n_starts: int = 100, **kwargs): | ||
| """Create 2D array with starting points for optimization | ||
| def get_priors(self) -> dict[str, Distribution]: | ||
| """Get prior distributions. | ||
|
|
||
| See :py:func:`petab.sample_parameter_startpoints`. | ||
| :returns: The prior distributions for the estimated parameters. | ||
| """ | ||
| return sampling.sample_parameter_startpoints( | ||
| self.parameter_df, n_starts=n_starts, **kwargs | ||
| ) | ||
| return { | ||
| p.id: p.prior_dist | ||
| for p in self.parameter_table.parameters | ||
| if p.estimate | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems reasonable to drop non-estimated parameter priors, but then users might see unexpected posterior values. e.g. if they perform MAP then fix the parameters to those values and recompute, there will be an undocumented change in the posterior value because their
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I am not sure. It's effectively a different problem then (kind of like changing your prior to a Dirac delta?), so that a change in the posterior should be expected, isn't it?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, a change can be expected, but then priors should be treated as an error since they are dropped, or?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'd say it shouldn't be an error. It's the same as with bounds for fixed parameters. Those are explicitly allowed to be specified with estimate=false (specs):
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, same issue there, but the worst thing that happens there is that the user looks into their parameter estimates and sees that they can't find the parameter that they thought they estimated. In the priors case, it would be difficult to notice the mistake. But you're right, and since it's nice to toggle parameters on or off without having to change other columns, fine to not have an error. As you like, but a warning/info/debug for unused priors could still be nice
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That could be part of some (yet to be implemented) warning mode for validation then, but I'd still find it somewhat confusing to treat priors different than bounds in that situation. Maybe that's something to leave to the parameter estimation tools. |
||
| } | ||
|
|
||
| def sample_parameter_startpoints(self, n_starts: int = 100, **kwargs): | ||
| """Create 2D array with starting points for optimization""" | ||
| priors = self.get_priors() | ||
| return np.vstack([p.sample(n_starts) for p in priors.values()]).T | ||
|
|
||
| def sample_parameter_startpoints_dict( | ||
| self, n_starts: int = 100 | ||
| ) -> list[dict[str, float]]: | ||
| """Create dictionaries with starting points for optimization | ||
|
|
||
| See also :py:func:`petab.sample_parameter_startpoints`. | ||
|
|
||
| Returns: | ||
| A list of dictionaries with parameter IDs mapping to samples | ||
| :returns: | ||
| A list of dictionaries with parameter IDs mapping to sampled | ||
| parameter values. | ||
| """ | ||
| return [ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.