From 5387e8d4e99dd3c9014fbc559d87731696026072 Mon Sep 17 00:00:00 2001 From: Johannes Buchner Date: Wed, 23 Oct 2024 10:11:12 +0200 Subject: [PATCH] doc: make pydoclint happy --- setup.cfg | 4 ++- ultranest/calibrator.py | 2 +- ultranest/integrator.py | 49 +++++++++++++++++++++---------------- ultranest/netiter.py | 20 +++++++-------- ultranest/ordertest.py | 8 +++--- ultranest/plot.py | 32 +++++++++++++++--------- ultranest/popstepsampler.py | 10 ++++++-- ultranest/stepsampler.py | 25 +++++++++++++++---- ultranest/store.py | 5 ++++ ultranest/utils.py | 9 +++++-- ultranest/viz.py | 3 +-- 11 files changed, 108 insertions(+), 59 deletions(-) diff --git a/setup.cfg b/setup.cfg index 78dd7114..ba2026a2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,8 @@ [flake8] +style = numpy +check-return-types = False exclude = docs -extend-ignore = E501,F401,E128,E231,E124 +extend-ignore = E501,F401,E128,E231,E124,SIM114,DOC105,DOC106,DOC107,DOC301,DOC501,DOC503,DOC203,B006,SIM102,SIM113,DOC202 per-file-ignores = ultranest/plot.py: B006 ultranest/integrator.py: B006 diff --git a/ultranest/calibrator.py b/ultranest/calibrator.py index cd432386..9f82c111 100644 --- a/ultranest/calibrator.py +++ b/ultranest/calibrator.py @@ -15,7 +15,7 @@ def _substitute_log_dir(init_args, nsteps): """Append `nsteps` to `log_dir` argument, if set. Parameters - ----------- + ---------- init_args: dict arguments passed :py:class:`ReactiveNestedSampler`, may contain the key `'log_dir'`. diff --git a/ultranest/integrator.py b/ultranest/integrator.py index 7d04fb86..80ad7433 100644 --- a/ultranest/integrator.py +++ b/ultranest/integrator.py @@ -166,10 +166,6 @@ def resume_from_similar_file( new likelihood function transform: function new transform function - verbose: bool - show progress - ndraw: int - set to >1 if functions can take advantage of vectorized computations max_tau: float Allowed dissimilarity in the live point ordering, quantified as normalised Kendall tau distance. @@ -178,9 +174,13 @@ def resume_from_similar_file( when the live point order differs. Near 1 are completely different live point orderings. Values in between permit mild disorder. + verbose: bool + show progress + ndraw: int + set to >1 if functions can take advantage of vectorized computations Returns - ---------- + ------- sequence: dict contains arrays storing for each iteration estimates of: @@ -554,17 +554,24 @@ def run( Parameters ---------- - update_interval_iter: + update_interval_iter: None | int Update region after this many iterations. - update_interval_ncall: + update_interval_ncall: None | int Update region after update_interval_ncall likelihood calls. - log_interval: + log_interval: None | int Update stdout status line every log_interval iterations - dlogz: + dlogz: float Target evidence uncertainty. - max_iters: + max_iters: None | int maximum number of integration iterations. + Returns + ------- + results: dict + dictionary with posterior *samples* and original *weighted_samples*, + number of likelihood calls *ncall*, + number of nested sampling iterations *niter*, evidence + estimate *logz* and uncertainty *logzerr*. """ if update_interval_ncall is None: update_interval_ncall = max(1, round(self.num_live_points)) @@ -2190,6 +2197,14 @@ def _should_node_be_expanded( ---------- it: int current iteration + Llo: float + lower loglikelihood bound for the strategy + Lhi: float + upper loglikelihood bound for the strategy + minimal_widths_sequence: list + list of likelihood intervals with minimum number of live points + target_min_num_children: int + minimum number of live points currently targeted node: node The node to consider parallel_values: array of floats @@ -2198,14 +2213,6 @@ def _should_node_be_expanded( maximum number of likelihood function calls allowed max_iters: int maximum number of nested sampling iteration allowed - Llo: float - lower loglikelihood bound for the strategy - Lhi: float - upper loglikelihood bound for the strategy - minimal_widths_sequence: list - list of likelihood intervals with minimum number of live points - target_min_num_children: - minimum number of live points currently targeted live_points_healthy: bool indicates whether the live points have become linearly dependent (covariance not full rank) @@ -2286,8 +2293,8 @@ def run( max_num_improvement_loops=-1, min_num_live_points=400, cluster_num_live_points=40, - insertion_test_window=10, insertion_test_zscore_threshold=4, + insertion_test_window=10, region_class=MLFriends, widen_before_initial_plateau_num_warn=10000, widen_before_initial_plateau_num_max=50000, @@ -2379,7 +2386,7 @@ def run( Returns - ------ + ------- results (dict): Results dictionary, with the following entries: - samples (ndarray): re-weighted posterior samples: distributed according @@ -3148,7 +3155,7 @@ def read_file(log_dir, x_dim, num_bootstraps=20, random=True, verbose=False, che whether to perform MWW insertion order test for assessing convergence Returns - ---------- + ------- sequence: dict contains arrays storing for each iteration estimates of: diff --git a/ultranest/netiter.py b/ultranest/netiter.py index 3ad2b561..d9407cdc 100644 --- a/ultranest/netiter.py +++ b/ultranest/netiter.py @@ -265,7 +265,7 @@ def count_tree(roots): list of :py:class:`TreeNode` specifying the roots of the tree. Returns - -------- + ------- count: int total number of nodes maxwidth: int @@ -301,7 +301,7 @@ def count_tree_between(roots, lo, hi): upper value threshold Returns - -------- + ------- nnodes: int total number of nodes in the value interval lo .. hi (inclusive). maxwidth: int @@ -343,7 +343,7 @@ def find_nodes_before(root, value): selection threshold Returns - -------- + ------- list_of_parents: list of nodes parents list_of_nforks: list of floats @@ -415,14 +415,14 @@ def add(self, newpointu, newpointp): """Save point. Parameters - ----------- + ---------- newpointu: array point (in u-space) newpointp: array point (in p-space) Returns - --------- + ------- index: int index of the new point in the pile """ @@ -448,7 +448,7 @@ def make_node(self, value, u, p): """Store point in pile, and create a new tree node that points to it. Parameters - ----------- + ---------- value: float value to store in node (loglikelihood) u: array @@ -457,7 +457,7 @@ def make_node(self, value, u, p): point (in p-space) Returns - --------- + ------- node: :py:class:`TreeNode` node """ @@ -868,11 +868,11 @@ def combine_results(saved_logl, saved_nodeids, pointpile, main_iterator, mpi_com Point pile. main_iterator: :py:class:`BreadthFirstIterator` iterator used - mpi_comm: + mpi_comm: None | object MPI communicator object, or None if MPI is not used. Returns - -------- + ------- results: dict All information of the run. Important keys: Number of nested sampling iterations (niter), @@ -996,7 +996,7 @@ def logz_sequence(root, pointpile, nbootstraps=12, random=True, onNode=None, ver Whether to perform a rolling insertion order rank test Returns - -------- + ------- results: dict Run information, see :py:func:`combine_results` sequence: dict diff --git a/ultranest/ordertest.py b/ultranest/ordertest.py index 33d7f07d..866847bc 100644 --- a/ultranest/ordertest.py +++ b/ultranest/ordertest.py @@ -33,10 +33,10 @@ def infinite_U_zscore(sample, B): Parameters ---------- - B: int - maximum rank allowed. sample: array of integers values between 0 and B (inclusive). + B: int + maximum rank allowed. Returns ------- @@ -72,10 +72,10 @@ def add(self, order, N): Parameters ---------- - N: int - maximum rank allowed. order: int rank between 0 and N (inclusive). + N: int + maximum rank allowed. """ if not 0 <= order <= N: raise ValueError("order %d out of %d invalid" % (order, N)) diff --git a/ultranest/plot.py b/ultranest/plot.py index 6bd8e80b..2b5cc589 100644 --- a/ultranest/plot.py +++ b/ultranest/plot.py @@ -59,17 +59,21 @@ def cornerplot( Parameters ---------- + results: dict + data dictionary min_weight: float cut off low-weight posterior points. Avoids meaningless stragglers when plot_datapoints is True. with_legend: bool whether to add a legend to show meaning of the lines. - color : str - ``matplotlib`` style color for all histograms. + logger: None | object + where to log + levels: list + list of credible interval levels + plot_datapoints : bool + Draw individual data points. plot_density : bool Draw the density colormap. - plot_contours : bool - Draw the contours. show_titles : bool Displays a title above each 1-D histogram showing the 0.5 quantile with the upper and lower errors supplied by the quantiles argument. @@ -77,6 +81,8 @@ def cornerplot( If true, suppress warnings for small datasets. contour_kwargs : dict Any additional keyword arguments to pass to the `contour` method. + color : str + ``matplotlib`` style color for all histograms. quantiles: list fractional quantiles to show on the 1-D histograms as vertical dashed lines. **corner_kwargs: dict @@ -240,16 +246,20 @@ class PredictionBand: plt.show() To plot onto a specific axis, use `band.line(..., ax=myaxis)`. - - Parameters - ---------- - x: array - The independent variable - """ def __init__(self, x, shadeargs={}, lineargs={}): - """Initialise with independent variable *x*.""" + """Initialise. + + Parameters + ---------- + x: array + Independent variable. + shadeargs: dict + default arguments for shade function. + lineargs: dict + default arguments for line function. + """ self.x = x self.ys = [] self.shadeargs = shadeargs diff --git a/ultranest/popstepsampler.py b/ultranest/popstepsampler.py index b4b0b3b0..89b72e6e 100644 --- a/ultranest/popstepsampler.py +++ b/ultranest/popstepsampler.py @@ -484,10 +484,10 @@ def setup_brackets(self, mask_starting, region): Parameters ---------- - region: MLFriends object - Region mask_starting: np.array(nwalkers, dtype=bool) which walkers to set up. + region: MLFriends object + Region """ if self.log: @@ -519,7 +519,13 @@ def advance(self, transform, loglike, Lmin, region): loglikelihood function Lmin: float current log-likelihood threshold + region: MLFriends object + Region + Returns + ------- + nc: int + Number of likelihood function calls """ movable = self.generation < self.nsteps all_movable = movable.all() diff --git a/ultranest/stepsampler.py b/ultranest/stepsampler.py index 7dc16400..dbaa538c 100644 --- a/ultranest/stepsampler.py +++ b/ultranest/stepsampler.py @@ -452,7 +452,7 @@ def select_random_livepoint(us, Ls, Lmin): """Select random live point as chain starting point. Parameters - ----------- + ---------- us: array positions of live points Ls: array @@ -518,7 +518,7 @@ def __call__(self, us, Ls, Lmin): """Select live point as chain starting point. Parameters - ----------- + ---------- us: array positions of live points Ls: array @@ -1008,6 +1008,16 @@ def __next__(self, region, Lmin, us, Ls, transform, loglike, ndraw=10, plot=Fals tregion: :py:class:`WrappingEllipsoid` optional ellipsoid in transformed space for rejecting proposals + Returns + ------- + u: None | array + newly sampled untransformed point, or None if not successful yet + p: None | array + newly sampled transformed point, or None if not successful yet + L: None | float + log-likelihood value, or None if not successful yet + nc: int + number of likelihood function calls """ # find most recent point in history conforming to current Lmin for j, (_uj, Lj) in enumerate(self.history): @@ -1097,12 +1107,17 @@ def move(self, ui, region, ndraw=1, plot=False): ---------- ui: array current point + region: object + ignored ndraw: int number of points to draw. - region: - ignored - plot: + plot: bool ignored + + Returns + ------- + unew: array + proposed point """ # propose in that direction direction = self.generate_direction(ui, region, scale=self.scale) diff --git a/ultranest/store.py b/ultranest/store.py index fdf8dd53..f74623fb 100644 --- a/ultranest/store.py +++ b/ultranest/store.py @@ -75,6 +75,11 @@ def flush(self): def pop(self, Lmin): """Request from the storage a point sampled from <= Lmin with L > Lmin. + Parameters + ---------- + Lmin: float + loglikelihood threshold + Returns ------- index: int diff --git a/ultranest/utils.py b/ultranest/utils.py index 2a398f4e..8156160c 100644 --- a/ultranest/utils.py +++ b/ultranest/utils.py @@ -221,7 +221,7 @@ def listify(*args): Parameters ---------- - args: iterable + *args: iterable Lists to concatenate. Returns @@ -468,6 +468,11 @@ def distributed_work_chunk_size(num_total_tasks, mpi_rank, mpi_size): process id mpi_size : int total number of processes + + Returns + ------- + chunk_size: int + number of tasks for process number `mpi_rank` """ return (num_total_tasks + mpi_size - 1 - mpi_rank) // mpi_size @@ -482,7 +487,7 @@ def submasks(mask, *masks): ---------- mask : np.array(dtype=bool) selection of some array - masks : list of np.array(dtype=bool) + *masks : list of np.array(dtype=bool) each further mask is a subselection Returns diff --git a/ultranest/viz.py b/ultranest/viz.py index 1f722ae0..b2309903 100644 --- a/ultranest/viz.py +++ b/ultranest/viz.py @@ -33,7 +33,7 @@ def round_parameterlimits(plo, phi, paramlimitguess=None): """Guess the current parameter range. Parameters - ----------- + ---------- plo: array of floats for each parameter, current minimum value phi: array of floats @@ -49,7 +49,6 @@ def round_parameterlimits(plo, phi, paramlimitguess=None): for each parameter, rounded maximum value formats: array of float tuples for each parameter, string format for representing it. - """ with np.errstate(divide='ignore'): expos = log10(np.abs([plo, phi]))