Skip to content

Commit

Permalink
Added check of derived parameter names for UltraNest
Browse files Browse the repository at this point in the history
  • Loading branch information
rapoliveira committed Sep 17, 2024
1 parent d0376cf commit adad769
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions examples/example_16/ulens_model_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,14 @@ def run_fit(self):
self._check_ulens_model_parameters()
self._get_parameters_ordered()
self._get_parameters_latex()
self._parse_fitting_parameters()
self._set_prior_limits()
self._parse_fit_constraints()
if self._fit_method == "EMCEE":
self._parse_starting_parameters()

self._check_fixed_parameters()
self._make_model_and_event()
self._parse_fitting_parameters()
if self._fit_method == "EMCEE":
self._get_starting_parameters()

Expand Down Expand Up @@ -1488,22 +1488,36 @@ def _parse_fitting_parameters_UltraNest(self):
self._check_required_and_allowed_parameters(required, allowed)
self._check_parameters_types(settings, bools, ints, floats, strings)
self._log_dir_UltraNest = settings.pop("log directory", None)
if self._log_dir_UltraNest is not None:
if not path.exists(self._log_dir_UltraNest):
raise ValueError("log directory value in fitting_parameters"
"does not exist.")
elif not path.isdir(self._log_dir_UltraNest):
raise ValueError("log directory value in fitting_parameters"
"exists, but it is a file.")
value = settings.pop("derived parameter names", "")
self._derived_param_names_UltraNest = value.split()
self._check_dir_and_parameter_names_Ultranest()

keys = {"n_live_points": "min_num_live_points"}
same_keys = ["min_num_live_points", 'max_num_improvement_loops',
"show_status", "dlogz", "frac_remain"]
keys = {**keys, **{key: key for key in same_keys}}
self._set_dict_safely(self._kwargs_UltraNest, settings, keys)

def _check_dir_and_parameter_names_Ultranest(self):
"""
Checks if the path to `log directory` exists and is a directory,
and also if the number of `derived parameter names` matches the
number of derived fluxes.
"""
if self._log_dir_UltraNest is not None:
if not path.exists(self._log_dir_UltraNest):
raise ValueError("log directory value in fitting_parameters"
"does not exist.")
elif not path.isdir(self._log_dir_UltraNest):
raise ValueError("log directory value in fitting_parameters"
"exists, but it is a file.")

n_datasets = len(self._datasets)
n_fluxes = self._n_fluxes_per_dataset
if len(self._derived_param_names_UltraNest) != n_datasets * n_fluxes:
raise ValueError("The number of `derived parameter names` must "
"match the number of derived fluxes.")

def _set_prior_limits(self):
"""
Set minimum and maximum values of the prior space
Expand Down

0 comments on commit adad769

Please sign in to comment.