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

Startpoints as dict #188

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion petab/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,13 +767,32 @@ def create_parameter_df(self, *args, **kwargs):
*args, **kwargs)

def sample_parameter_startpoints(self, n_starts: int = 100):
"""Create starting points for optimization
"""Create 2D array with starting points for optimization

See :py:func:`petab.sample_parameter_startpoints`.
"""
return sampling.sample_parameter_startpoints(
self.parameter_df, n_starts=n_starts)

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
parameter values.
"""
return [
dict(zip(self.x_free_ids, parameter_values))
for parameter_values in self.sample_parameter_startpoints(
n_starts=n_starts
)
]

def unscale_parameters(
self,
x_dict: Dict[str, float],
Expand Down
9 changes: 9 additions & 0 deletions tests/test_petab.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ def test_startpoint_sampling(fujita_model_scaling):
assert -3 <= sp[1] <= 3


def test_startpoint_sampling_dict(fujita_model_scaling):
n_starts = 10
startpoints = fujita_model_scaling.sample_parameter_startpoints_dict(
n_starts)
assert len(startpoints) == n_starts
for startpoint in startpoints:
assert set(startpoint.keys()) == set(fujita_model_scaling.x_free_ids)


def test_create_parameter_df(
condition_df_2_conditions): # pylint: disable=W0621
"""Test petab.create_parameter_df."""
Expand Down