Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Returns
-------
prior:
A valid pyabc.Distribution for the parameters to estimate.
"""
# add default values
parameter_df = petab.normalize_parameter_df(
self.petab_problem.parameter_df)
prior_dct = {}
# iterate over parameters
for _, row in parameter_df.reset_index().iterrows():
# check whether we can ignore
if not self.fixed_parameters and row[petab.C.ESTIMATE] == 0:
# ignore fixed parameters
continue
if not self.free_parameters and row[petab.C.ESTIMATE] == 1:
# ignore free parameters
continue
# pyabc currently only knows objective priors, no
# initialization priors
prior_type = row[petab.C.OBJECTIVE_PRIOR_TYPE]
pars_str = row[petab.C.OBJECTIVE_PRIOR_PARAMETERS]
prior_pars = tuple(float(val) for val in pars_str.split(';'))
# create random variable from table entry
if prior_type in [petab.C.PARAMETER_SCALE_UNIFORM,
petab.C.UNIFORM]:
lb, ub = prior_pars
self.minimize_options = minimize_options
self.model_id = self.row[MODEL_ID]
self._AIC = None
self._BIC = None
if self.valid:
# TODO warning/error if x_fixed_estimated is not a parameter ID in
# the PEtab parameter table. A warning is currently produced in
# `row2problem` above.
# Could move to a separate method that is only called when a
# criterion that requires the number of estimated parameters is
# called (same for self.n_measurements).
self.estimated = x_fixed_estimated | set(
self.petab_problem.parameter_df.query(f'{ESTIMATE} == 1').index
)
self.n_estimated = len(self.estimated)
self.n_measurements = len(petab_problem.measurement_df)
self.pypesto_problem = row2problem(row,
petab_problem,
x_guess=x_guess)
self.minimize_result = None
# TODO autorun may be unnecessary now that the `minimize_options`
# argument is implemented.
if autorun:
if minimize_options:
self.set_result(minimize(self.pypesto_problem,
**minimize_options))
for key in [YAML_FILENAME_COLUMN, MODEL_NAME_COLUMN]:
if key in row.keys():
row.pop(key)
for par_id, par_val in row.items():
if par_id not in petab_problem.x_ids:
print(Fore.YELLOW + f'Warning: parameter {par_id} is not defined '
f'in PETab model. It will be ignored.')
continue
if not np.isnan(par_val):
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 0
petab_problem.parameter_df[NOMINAL_VALUE].loc[par_id] = par_val
# petab_problem.parameter_df.lowerBound.loc[par_id] = float("NaN")
# petab_problem.parameter_df.upperBound.loc[par_id] = float("NaN")
else:
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 1
# petab_problem.parameter_df.nominalValue.loc[par_id] = float(
# "NaN")
# chose standard objective in case none is provided
importer = PetabImporter(petab_problem)
if obj is None:
obj = importer.create_objective()
pypesto_problem = importer.create_problem(obj)
return pypesto_problem
# row.pop(key)
row_parameters = {k: row[k] for k in row if k not in NOT_PARAMETERS}
for par_id, par_val in row_parameters.items():
#for par_id, par_val in row.items():
if par_id not in petab_problem.x_ids:
logger.info(Fore.YELLOW + f'Warning: parameter {par_id} is not defined '
f'in PETab model. It will be ignored.')
continue
if not np.isnan(par_val):
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 0
petab_problem.parameter_df[NOMINAL_VALUE].loc[par_id] = par_val
# petab_problem.parameter_df.lowerBound.loc[par_id] = float("NaN")
# petab_problem.parameter_df.upperBound.loc[par_id] = float("NaN")
else:
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 1
# petab_problem.parameter_df.nominalValue.loc[par_id] = float(
# "NaN")
# Any parameter values in `x_guess` for parameters that are not estimated
# should be filtered out and replaced with
# - their corresponding values in `row` if possible, else
# - their corresponding nominal values in the `petab_problem.parameter_df`.
# TODO reconsider whether filtering is a good idea (x_guess is no longer
# the latest MLE then). Similar todo exists in
# `ModelSelectorMethod.new_model_problem`.
if x_guess is not None:
filtered_x_guess = []
for par_id, par_val in x_guess:
if petab_problem.parameter_df[ESTIMATE].loc[par_id] == 1:
filtered_x_guess.append(par_val)
else:
# row.pop(key)
row_parameters = {k: row[k] for k in row if k not in NOT_PARAMETERS}
for par_id, par_val in row_parameters.items():
#for par_id, par_val in row.items():
if par_id not in petab_problem.x_ids:
print(Fore.YELLOW + f'Warning: parameter {par_id} is not defined '
f'in PETab model. It will be ignored.')
continue
if not np.isnan(par_val):
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 0
petab_problem.parameter_df[NOMINAL_VALUE].loc[par_id] = par_val
# petab_problem.parameter_df.lowerBound.loc[par_id] = float("NaN")
# petab_problem.parameter_df.upperBound.loc[par_id] = float("NaN")
else:
petab_problem.parameter_df[ESTIMATE].loc[par_id] = 1
# petab_problem.parameter_df.nominalValue.loc[par_id] = float(
# "NaN")
# chose standard objective in case none is provided
importer = PetabImporter(petab_problem)
if obj is None:
obj = importer.create_objective()
pypesto_problem = importer.create_problem(obj)
return pypesto_problem