pyuncertainnumber.pba.utils =========================== .. py:module:: pyuncertainnumber.pba.utils Exceptions ---------- .. autoapisummary:: pyuncertainnumber.pba.utils.NotIncreasingError Classes ------- .. autoapisummary:: pyuncertainnumber.pba.utils.CustomEdgeRectHandler Functions --------- .. autoapisummary:: pyuncertainnumber.pba.utils.extend_ecdf pyuncertainnumber.pba.utils.sorting pyuncertainnumber.pba.utils.reweighting pyuncertainnumber.pba.utils.uniform_reparameterisation pyuncertainnumber.pba.utils.find_nearest pyuncertainnumber.pba.utils.plot_intervals pyuncertainnumber.pba.utils.read_json pyuncertainnumber.pba.utils.is_increasing pyuncertainnumber.pba.utils.condensation pyuncertainnumber.pba.utils.condensation_bounds pyuncertainnumber.pba.utils.condensation_bound pyuncertainnumber.pba.utils.smooth_condensation pyuncertainnumber.pba.utils.equi_selection pyuncertainnumber.pba.utils.create_colored_edge_box pyuncertainnumber.pba.utils.expose_functions_as_public pyuncertainnumber.pba.utils.left_right_switch pyuncertainnumber.pba.utils.build_constraints_from_pbox_robust pyuncertainnumber.pba.utils.variance_bounds_via_lp pyuncertainnumber.pba.utils.get_mean_var_from_ecdf pyuncertainnumber.pba.utils.sample_ecdf_in_pbox pyuncertainnumber.pba.utils.area_between_ecdfs pyuncertainnumber.pba.utils._ecdf_value_on_left_of_intervals Module Contents --------------- .. py:function:: extend_ecdf(cdf) add zero and one to the ecdf :param CDF_bundle: .. py:function:: sorting(list1, list2) .. py:function:: reweighting(*masses) reweight the masses to sum to 1 .. py:function:: uniform_reparameterisation(a, b) reparameterise the uniform distribution to a, b .. py:function:: find_nearest(array, value) Find index/indices of nearest value(s) in `array` to each `value`. Efficient for both scalar and array inputs. .. py:function:: plot_intervals(vec_interval: list[pyuncertainnumber.pba.intervals.number.Interval], ax=None, **kwargs) plot the intervals in a vectorised form :param vec_interval: vectorised interval objects .. py:function:: read_json(file_name) .. py:function:: is_increasing(arr) check if 'arr' is increasing .. py:exception:: NotIncreasingError Bases: :py:obj:`Exception` Common base class for all non-exit exceptions. .. py:function:: condensation(bound, number: int) a joint implementation for condensation :param number: the number to be reduced :type number: int :param bound: either the left or right bound to be reduced :type bound: array-like .. note:: It will keep the first and last from the bound .. py:function:: condensation_bounds(bounds, number) condense the bounds of number pbox :param number: the number to be reduced :type number: int :param bounds: the left and right bound to be reduced :type bounds: list or tuple .. py:function:: condensation_bound(bound, number) condense the bounds of number pbox :param number: the number to be reduced :type number: int :param bound: either the left or right bound to be reduced :type bound: array-like .. py:function:: smooth_condensation(bounds, number=200) .. py:function:: equi_selection(arr, n) draw n equidistant points from the array .. py:function:: create_colored_edge_box(x0, y0, width, height, linewidth=1) .. py:class:: CustomEdgeRectHandler Bases: :py:obj:`matplotlib.legend_handler.HandlerBase` .. py:method:: create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans) .. py:function:: expose_functions_as_public(mapping, wrapper) expose private functions as public APIs :param mapping: a dictionary containing private function names mapped to public APIs :type mapping: dict :param wrapper: a function that wraps the original functions (e.g., the decorator UNtoUN) :type wrapper: callable .. note:: the decorator which wraps the original function returning Pbox into returning UN, hence making the public UN API .. py:function:: left_right_switch(left, right) .. note:: right quantile should be greater and equal than left quantile .. py:function:: build_constraints_from_pbox_robust(q_a, p_a, q_b, p_b, x_grid, n=None, eps=1e-12) Returns x, L, U, n and also the envelopes F_L, F_U on x_grid. If F_L==F_U (degenerate p-box), we set L=U=round(n*F) exactly to avoid infeasibility. .. py:function:: variance_bounds_via_lp(q_a, p_a, q_b, p_b, x_grid, n=None, mu_grid=101) .. py:function:: get_mean_var_from_ecdf(q, p) Numerically estimate the mean and var from ECDF data :param q: quantiles :type q: array-like :param p: probabilities :type p: array-like .. rubric:: Example >>> # Given ECDF data an example >>> q = [1, 2, 3, 4] >>> p = [0.25, 0.5, 0.75, 1.0] >>> mean, var = get_mean_var_from_ecdf(q, p) .. py:function:: sample_ecdf_in_pbox(q_a, p_a, q_b, p_b, x_grid=None, n=None, rng=None, eps=1e-12) Sample a random ECDF (quantile & probability vectors) lying inside the p-box defined by lower envelope (q_a, p_a) and upper envelope (q_b, p_b). :param q_a: arrays Lower (left) bounding quantile function sampled at probabilities p_a. :param p_a: arrays Lower (left) bounding quantile function sampled at probabilities p_a. :param q_b: arrays Upper (right) bounding quantile function sampled at probabilities p_b. :param p_b: arrays Upper (right) bounding quantile function sampled at probabilities p_b. :param x_grid: array or None Discrete support where ECDF masses are allowed to sit. If None, uses the union of q_a and q_b sorted and uniqued. You can also pass a custom grid (e.g., np.linspace(min(q_a), max(q_b), 200)). :param n: int or None ECDF size (number of jumps). If None, defaults to len(p_a). :param rng: numpy.random.Generator or None Random generator to control reproducibility. :param eps: float Small tolerance to avoid rounding issues in DP bounds. Returns q : ndarray (length n) Quantile vector (nondecreasing), values taken from x_grid. p : ndarray (length n) Probability vector for the ECDF: p[r] = (r+1)/n. .. note:: Choose an x-grid (or let the function use the union of q_a and q_b). # x_grid = np.linspace(min(q_a), max(q_b), 200) # e.g., a uniform 200-point support .. rubric:: Example >>> p = pba.normal([4, 6], 1) >>> ecdf_q, ecdf_p = sample_ecdf_in_pbox(p.left, p.p_values, p.right, p.p_values) .. py:function:: area_between_ecdfs(x_upper, p_upper, x_lower, p_lower) Compute the area between two ECDFs defined by (x_upper, p_upper) and (x_lower, p_lower). :param x_upper: arrays defining the upper ECDF :param p_upper: arrays defining the upper ECDF :param x_lower: arrays defining the lower ECDF :param p_lower: arrays defining the lower ECDF .. py:function:: _ecdf_value_on_left_of_intervals(x, p, grid_left) Right-continuous ECDF value used on [grid_left[k], grid_right[k]). For values below the first x, value is 0. For above the last x, value stays at p[-1].