Skip to content
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

Fix startpoint sampling for hierarchical optimization #1105

Merged
merged 5 commits into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions pypesto/petab/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,37 @@ def create_prior(self) -> Union[NegLogParameterPriors, None]:
else:
return None

def create_startpoint_method(self, **kwargs) -> StartpointMethod:
def create_startpoint_method(
self, x_ids: Sequence[str] = None, **kwargs
) -> StartpointMethod:
"""Create a startpoint method.

Parameters
----------
x_ids:
If provided, create a startpoint method that only samples the
parameters with the given IDs.
**kwargs:
Additional keyword arguments passed on to
:meth:`pypesto.startpoint.FunctionStartpoints.__init__`.
"""

def startpoint_method(n_starts: int, **kwargs):
return petab.sample_parameter_startpoints(
startpoints = petab.sample_parameter_startpoints(
self.petab_problem.parameter_df, n_starts=n_starts
)
if x_ids is None:
return startpoints

# subset parameters according to the provided parameter IDs
from petab.C import ESTIMATE

parameter_df = self.petab_problem.parameter_df
pars_to_estimate = list(
parameter_df.index[parameter_df[ESTIMATE] == 1]
)
x_idxs = [pars_to_estimate.index(x_id) for x_id in x_ids]
return startpoints[:, x_idxs]

return FunctionStartpoints(function=startpoint_method, **kwargs)

Expand Down Expand Up @@ -740,7 +757,9 @@ def create_problem(
x_names=x_ids,
x_scales=x_scales,
x_priors_defs=prior,
startpoint_method=self.create_startpoint_method(),
startpoint_method=self.create_startpoint_method(
x_ids=np.delete(x_ids, x_fixed_indices)
),
Doresic marked this conversation as resolved.
Show resolved Hide resolved
**problem_kwargs,
)

Expand Down