Skip to content

Commit

Permalink
#46 ensure current solution statistic remains the same with randomize…
Browse files Browse the repository at this point in the history
… start values
  • Loading branch information
fbergmann committed Apr 4, 2024
1 parent e1cb008 commit 8cc613e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion basico/task_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,10 @@ def get_simulation_results(values_only=False, update_parameters=True, **kwargs):
if type(solution) is dict or type(solution) is list:
solution = pd.DataFrame(data=solution)
else:
solution = run_parameter_estimation(method='Current Solution Statistics', write_report=False)
settings = basico.get_task_settings(basico.T.PARAMETER_ESTIMATION, model=dm)
solution = run_parameter_estimation(method='Current Solution Statistics', write_report=False, randomize_start_values=False, model=dm)
# restore settings
basico.set_task_settings(basico.T.PARAMETER_ESTIMATION, settings)

exp_data = []
sim_data = []
Expand Down
16 changes: 16 additions & 0 deletions tests/test_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def setUp(self):
self.model = basico.load_example('LM')
self.assertTrue(self.model.getModel().getObjectName() ==
'Kinetics of a Michaelian enzyme measured spectrophotometrically')
basico.add_parameter_set('initial_state')

def tearDown(self):
basico.remove_datamodel(self.model)
Expand Down Expand Up @@ -136,6 +137,21 @@ def test_run(self):
self.assertTrue(sol is not None)
self.assertAlmostEqual(sol.loc['(R1).k2'].sol, 1.0, places=2)

def test_current_solution(self):
before = basico.get_simulation_results()
# ensure the results are the same, even if randomize values
# is activated
settings = basico.get_task_settings('Parameter Estimation')
settings['problem']['Randomize Start Values'] = True
basico.set_task_settings('Parameter Estimation', settings)

# now run again
after = basico.get_simulation_results()

# ensure that the results are the same
self.assertTrue(np.allclose(before[1][0].values, after[1][0].values))


def test_remove(self):
fit_items = basico.get_fit_parameters()
self.assertIsNotNone(fit_items)
Expand Down

0 comments on commit 8cc613e

Please sign in to comment.