Skip to content

Commit

Permalink
Fix startpoint sampling for hierarchical optimization (#1105)
Browse files Browse the repository at this point in the history
* Fix startpoint sampling for hierarchical optimization

See #1096

* fixed pars

* fixup

---------

Co-authored-by: Doresic <[email protected]>
  • Loading branch information
dweindl and Doresic authored Aug 7, 2023
1 parent 234634b commit 8c70d76
Showing 1 changed file with 22 additions and 3 deletions.
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)
),
**problem_kwargs,
)

Expand Down

0 comments on commit 8c70d76

Please sign in to comment.