diff --git a/examples/example_16/ob03235_2_full.yaml b/examples/example_16/ob03235_2_full.yaml index 130d321e..c0a61d25 100644 --- a/examples/example_16/ob03235_2_full.yaml +++ b/examples/example_16/ob03235_2_full.yaml @@ -6,7 +6,12 @@ photometry_files: # For files with time starting with 245...: # - {..., add_2450000: False} fit_method: EMCEE -# Method options: EMCEE (default), MultiNest, UltraNest +# Options: EMCEE, MultiNest, UltraNest. +# If not given, EMCEE is used if starting_parameters are given or MultiNest +# if prior_limits are given. +# If MultiNest/UltraNest is selected: starting_parameters, fit_constraints, +# min_values and max_value cannot be provided. The trace plot cannot be +# generated as well. model: methods: 2452800. point_source 2452833. VBBL 2452845. point_source 2452860. default method: point_source_point_lens @@ -78,12 +83,27 @@ max_values: s: 2. alpha: 360. fitting_parameters: + ## EMCEE only n_walkers: 20 n_steps: 4 n_burn: 2 progress: True posterior file: ob03235_2_models.npy posterior file fluxes: all + ## MultiNest only (basename, multimodal, evidence tolerance) + # basename: out_ob08092_O4_MN- + # multimodal: True + # # evidence tolerance: 0.5 + ## UltraNest only (log directory, derived parameter names, show_status, + ## dlogz, frac_remain, max_num_improvement_loops) + # log directory: ultranest_outputs/ + # derived parameter names: source_flux blending_flux + # show_status: True + # dlogz: 2. + # frac_remain: 0.5 + # max_num_improvement_loops: 0 + ## Both for MultiNest and UltraNest (number of live points) + # n_live_points: 20 plots: best model: # You can skip the line below - the light curve will be plotted on screen. diff --git a/examples/example_16/ob08092-o4_UN.yaml b/examples/example_16/ob08092-o4_UN.yaml index b555d5b9..2cd8b6a0 100644 --- a/examples/example_16/ob08092-o4_UN.yaml +++ b/examples/example_16/ob08092-o4_UN.yaml @@ -10,6 +10,14 @@ fitting_parameters: derived parameter names: source_flux blending_flux show_status: True n_live_points: 1000 + # `n_live_points` can also be named `min_num_live_points` + # If it is smaller than 40, `cluster_num_live_points` is also reduced. + # UltraNest may increase n_live_points if it is too low to achieve the + # logz accuracy (default=0.5). It can be avoided increasing dlogz: + dlogz: 2. + # The parameters below can reduce runtime (default is -1 and 0.01) + # frac_remain: 0.5 + # max_num_improvement_loops: 0 plots: best model: file: out_ob08092_O4_UN_model.png diff --git a/examples/example_16/ulens_model_fit.py b/examples/example_16/ulens_model_fit.py index 504b9879..10083054 100644 --- a/examples/example_16/ulens_model_fit.py +++ b/examples/example_16/ulens_model_fit.py @@ -242,9 +242,22 @@ class UlensModelFit(object): ``show_status`` (*bool*) - whether to show integration progress as a status line or not. Default is *True*. - ``n_live_points`` (*int*) - minimum number of live points + ``min_num_live_points`` (*int*) - minimum number of live points throughout the run. Default value is 400. + ``dlogz`` (*float*) - Target evidence uncertainty, in order to + obtain a logz error below a threshold. Default value is 0.5. + It can be increased to allow `min_num_live_points` values below: + sqrt(iterations) / dlogz = sqrt(1000) / 0.5 ~ 64. + + ``frac_remain`` (*float*) - Integrate until this fraction of the + integral is left in the remainder. Numbers smaller than 0.01 + ensure that peaks are discovered, higher numbers can be set if + the posterior is simple. Default value is 0.01. + + ``max_num_improvement_loops`` (*int*) - Limit the number of times + the algorithm is repeated to improve. Default value is -1. + fit_constraints: *dict* Constraints on model other than minimal and maximal values. @@ -1360,7 +1373,8 @@ def _parse_fitting_parameters_MultiNest(self): allowed = strings + bools + ints + floats only_UltraNest = ['log directory', 'derived parameter names', - 'show status'] + 'show status', 'dlogz', 'frac_remain', + 'max_num_improvement_loops'] for item in only_UltraNest: settings.pop(item, None) @@ -1434,7 +1448,7 @@ def _check_output_files_MultiNest(self): def _parse_fitting_parameters_UltraNest(self): """ - make sure MultiNest fitting parameters are properly defined + Make sure UltraNest fitting parameters are properly defined """ self._kwargs_UltraNest = dict() self._kwargs_UltraNest['viz_callback'] = False @@ -1445,9 +1459,11 @@ def _parse_fitting_parameters_UltraNest(self): required = [] bools = ['show_status'] - ints = ['n_live_points'] + ints = ['min_num_live_points', 'max_num_improvement_loops'] + if 'n_live_points' in settings: + ints[0] = 'n_live_points' strings = ['log directory', 'derived parameter names'] - floats = [] + floats = ['dlogz', 'frac_remain'] allowed = strings + bools + ints + floats only_MultiNest = ['basename', 'multimodal', 'evidence tolerance'] @@ -1468,7 +1484,8 @@ def _parse_fitting_parameters_UltraNest(self): self._derived_params_UltraNest = value.split() keys = {"n_live_points": "min_num_live_points"} - same_keys = ["show_status"] + 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) @@ -2672,9 +2689,10 @@ def _run_fit_UltraNest(self): """ Run Ultranest fit """ - self._kwargs_UltraNest['dlogz'] = 100. # 0.5... 100. took 15min - self._kwargs_UltraNest['dKL'] = 100. # 0.5 - self._kwargs_UltraNest['frac_remain'] = 0.005 + min_n_live = self._kwargs_UltraNest['min_num_live_points'] + cluster_n_live = 40 if min_n_live >= 40 else min_n_live + self._kwargs_UltraNest['cluster_num_live_points'] = cluster_n_live + self._result_UltraNest = self._sampler.run(**self._kwargs_UltraNest) def _finish_fit(self):