pyuncertainnumber.propagation.mixed_up¶
Functions¶
|
Interval Monte Carlo for propagation of pbox |
|
classic slicing algoritm for rigorous propagation of pbox |
|
Double-loop Monte Carlo or nested Monte Carlo for mixed uncertainty propagation |
|
Bivariate interval monte carlo for convenience |
Module Contents¶
- pyuncertainnumber.propagation.mixed_up.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
- Parameters:
vars (list) – a list of constructs
func (callable) – response function. By default, iterable signature is expected.
interval_strategy (str) – strategy for interval discretisation, options include {‘direct’, ‘endpoints’, ‘subinterval’}
n_sam (int) – number of samples for each input
dependency – dependency structure (e.g. vine copula or archimedean copula
random_state – random seed for reproducibility
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.
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
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')
- pyuncertainnumber.propagation.mixed_up.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
- Parameters:
vars (list) – list of constructs
func (callable) – response function
interval_strategy (str) – strategy for interval discretisation, options include {‘direct’, ‘endpoints’, ‘subinterval’}
n_slices – number of slices for each input
outer_discretisation (bool) – whether to use outer discretisation for pbox. By default is True for rigorous propagation; however, alpha-cut style interval are also supported.
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
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')
- pyuncertainnumber.propagation.mixed_up.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
- Parameters:
joint_distribution (Distribution or JointDistribution) – 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.
epistemic_vars (list) – a list epistemic variables in the form of Interval
n_a (int) – number of aleatory samples
n_e (int) – number of epistemic samples
parallel (Boolean) – parallel processing. Only use it for heavy computation (black-box) due to overhead
Hint
consider a function mapping f(X) -> y
\(X\) in \(R^5\) with `n_a=1000`will suggest f(1000, 5)
resulting sample array: with n_e=2, the response \(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 responsethe epistemic samples used
Otherwise, just the p-box.
- Return type:
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
PboxorUncertainNumberobject.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 ... )