pyuncertainnumber.propagation.mixed_up ====================================== .. py:module:: pyuncertainnumber.propagation.mixed_up Functions --------- .. autoapisummary:: pyuncertainnumber.propagation.mixed_up.interval_monte_carlo pyuncertainnumber.propagation.mixed_up.slicing pyuncertainnumber.propagation.mixed_up.double_monte_carlo pyuncertainnumber.propagation.mixed_up.bi_imc Module Contents --------------- .. py:function:: interval_monte_carlo(vars: list[pyuncertainnumber.pba.intervals.Interval | pyuncertainnumber.pba.distributions.Distribution | pyuncertainnumber.pba.pbox_abc.Pbox], func: callable, interval_strategy, n_sam: int, dependency: pyuncertainnumber.pba.dependency.Dependency = None, random_state=None, side_effects=False, **kwargs) -> pyuncertainnumber.pba.pbox_abc.Pbox Interval Monte Carlo for propagation of pbox :param vars: a list of constructs :type vars: list :param func: response function. By default, iterable signature is expected. :type func: callable :param interval_strategy: strategy for interval discretisation, options include {'direct', 'endpoints', 'subinterval'} :type interval_strategy: str :param n_sam: number of samples for each input :type n_sam: int :param dependency: dependency structure (e.g. vine copula or archimedean copula :param random_state: random seed for reproducibility :param side_effects: whether return auxiliary outputs (side effects) during propagation If true, the alpha-cut samples in the uniform space will be returned as well. otherwise, the default is False and only the p-box is returned. :type side_effects: bool .. note:: When choosing ``interval_strategy``, "direct" requires function signature to take a list of inputs, whereas "subinterval" and "endpoints" require the function to have a vectorised signature. :returns: Pbox .. rubric:: Example >>> from pyuncertainnumber import pba >>> def foo(x): return x[0] ** 3 + x[1] + x[2] >>> a = pba.normal([2, 3], [1]) >>> b = pba.normal([10, 14], [1]) >>> c = pba.normal([4, 5], [1]) >>> corre_matrix = np.array([[1, 0.5, 0.3], [0.5, 1, 0.4], [0.3, 0.4, 1]]) >>> de = pba.Dependency(family='gaussian', corr=corre_matrix) >>> mix = interval_monte_carlo(vars=[a,b,c], >>> ... func=foo, >>> ... n_sam=20, >>> ... dependency=de, >>> ... interval_strategy='direct') .. py:function:: slicing(vars: list[pyuncertainnumber.pba.distributions.Distribution | pyuncertainnumber.pba.intervals.Interval | pyuncertainnumber.pba.pbox_abc.Pbox], func, interval_strategy, n_slices, outer_discretisation=True, dependency=None, **kwargs) -> pyuncertainnumber.pba.pbox_abc.Pbox classic slicing algoritm for rigorous propagation of pbox :param vars: list of constructs :type vars: list :param func: response function :type func: callable :param interval_strategy: strategy for interval discretisation, options include {'direct', 'endpoints', 'subinterval'} :type interval_strategy: str :param n_slices: number of slices for each input :param outer_discretisation: whether to use outer discretisation for pbox. By default is True for rigorous propagation; however, alpha-cut style interval are also supported. :type outer_discretisation: bool :param dependency: dependency structure (e.g. vine copula or archimedean copula). .. tip:: Merely independence assumption is supported by now. Other dependency structures are at beta developement now. .. note:: When choosing ``interval_strategy``, "direct" requires function signature to take a list of inputs, whereas "subinterval" and "endpoints" require the function to have a vectorised signature. :returns: Pbox .. rubric:: Example >>> from pyuncertainnumber import pba >>> def foo(x): return x[0] ** 3 + x[1] + x[2] >>> a = pba.normal([2, 3], [1]) >>> b = pba.normal([10, 14], [1]) >>> c = pba.normal([4, 5], [1]) >>> mix = slicing(vars=[a,b,c], >>> ... func=foo, >>> ... n_slices=20, >>> ... interval_strategy='direct') .. py:function:: double_monte_carlo(joint_distribution: pyuncertainnumber.pba.distributions.Distribution | pyuncertainnumber.pba.distributions.JointDistribution, epistemic_vars: list[pyuncertainnumber.pba.intervals.Interval], n_a: int, n_e: int, func: callable, side_effects=False, parallel=False) -> tuple[pyuncertainnumber.pba.pbox_abc.Pbox, list, numpy.ndarray] Double-loop Monte Carlo or nested Monte Carlo for mixed uncertainty propagation :param joint_distribution: an aleatoric sampler based on joint distribution of aleatory variables (or marginal one in 1d case). A sampler is basically anything (univariate or multivariate) that has the `sample` interface whereby it can sample a given number of samples. :type joint_distribution: Distribution or JointDistribution :param epistemic_vars: a list epistemic variables in the form of Interval :type epistemic_vars: list :param n_a: number of aleatory samples :type n_a: int :param n_e: number of epistemic samples :type n_e: int :param parallel: parallel processing. Only use it for heavy computation (black-box) due to overhead :type parallel: Boolean .. hint:: consider a function mapping f(X) -> y - :math:`X` in :math:`R^5` with `n_a=1000`will suggest f(1000, 5) - resulting sample array: with `n_e=2`, the response :math:`y` : (n_ep+2, n_a) e.g. (4, 1000) side_effects (bool): whether return auxiliary outputs (side effects) during propagation If true, the alpha-cut samples in the uniform space will be returned as well. otherwise, the default is False and only the p-box is returned. :returns: - a p-box enveloping all the CDFs from the epistemic samples - a list of ECDFs for each epistemic sample - numpy array of shape ``(n_e+2, n_a)`` as a collection of CDFs for the response - the epistemic samples used Otherwise, just the p-box. :rtype: If `side_effects` is True, a tuple containing the following items .. note:: The result array can be interpreted as a collection of CDFs for the response function evaluated at the aleatory samples for each epistemic sample. One can further envelope these CDFs into a ``Pbox`` or ``UncertainNumber`` object. .. rubric:: Example >>> from pyuncertainnumber import pba >>> # vectorised function signature with matrix input (2D np.ndarray) >>> def foo_vec(x): ... return x[:, 0] ** 3 + x[:, 1] + x[:, 2] + x[:, 3] >>> dist_a = pba.Distribution('gaussian', (5, 1)) >>> dist_b = pba.Distribution('uniform', (2, 3)) >>> c = pba.Dependency('gaussian', params=0.8) >>> joint_dist = pba.JointDistribution(copula=c, marginals=[dist_a, dist_b]) >>> xe1 = pba.I(1, 2) >>> xe2 = pba.I(3, 4) >>> t = double_monte_carlo( ... joint_distribution=joint_dist, ... epistemic_vars=[xe1, xe2], ... n_a=20, ... n_e=3, ... func=foo_vec ... ) .. py:function:: bi_imc(x, y, func, dependency=None, n_sam=100) Bivariate interval monte carlo for convenience :param x: Pbox :type x: Pbox :param y: Pbox :type y: Pbox :param func: callable which takes vector-type of inputs :param dependency: dependency structure (regular copula)