pyuncertainnumber.propagation.p¶
Classes¶
Base class blueprint. Not for direct use |
|
Aleatoric uncertainty propagation class for Distribution constructs only |
|
Epistemic uncertainty propagation class for construct |
|
Mixed uncertainty propagation class for construct |
|
High-level integrated class for the propagation of uncertain numbers |
Module Contents¶
- class pyuncertainnumber.propagation.p.P(vars, func, method, dependency=None)¶
Bases:
abc.ABCBase class blueprint. Not for direct use
- _vars¶
- func¶
- method¶
- dependency = None¶
- post_init_check()¶
some checks
- abstractmethod type_check()¶
if the nature of the UN suitable for the method
- abstractmethod method_check()¶
if the method is suitable for the nature of the UN
- class pyuncertainnumber.propagation.p.AleatoryPropagation(vars, func, method, dependency=None)¶
Bases:
PAleatoric uncertainty propagation class for Distribution constructs only
- Parameters:
vars (Distribution) – a list of uncertain numbers objects
func (callable) – the response or performance function applied to the uncertain numbers
method (str) – a string indicating the method to be used for propagation.
dependency (string or Dependency) – a Dependency object(i.e. a copula function) to model the dependency structure among input variables. Strings such as “independence” accepted for independence.
Note
Supported methods include “monte_carlo”. Note that “taylor_expansion” is not supported herein but implemented as a standalone function in the module taylor_expansion.py.
Caution
This function supports with low-level constructs NOT the high-level UN (uncertain number) objects. For UN objects, use Propagation class as an high-level API.
See also
Propagation(): the high-level API for uncertain number propagation.Example
>>> from pyuncertainnumber import pba >>> from pyuncertainnumber.propagation.p import AleatoryPropagation >>> def foo(x): return x[0] ** 3 + x[1] + x[2] >>> a_d = pba.Distribution('gaussian', (3,1)) >>> b_d = pba.Distribution('gaussian', (10, 1)) >>> c_d = pba.Distribution('uniform', (5, 10)) >>> aleatory = AleatoryPropagation(vars=[a_d, b_d, c_d], func=foo, method='monte_carlo') >>> result = aleatory(n_sam=1000)
- type_check()¶
only distributions
- method_check()¶
if the method is suitable for the nature of the UN
- run(n_sam: int = 1000)¶
doing the propagation
- class pyuncertainnumber.propagation.p.EpistemicPropagation(vars, func, method)¶
Bases:
PEpistemic uncertainty propagation class for construct
- Parameters:
vars (Interval) – a list of interval objects
func (callable) – the response or performance function applied to the uncertain numbers
method (str) – a string indicating the method to be used for propagation
interval_strategy (str) – a strategy for interval propagation, including {‘endpoints’, ‘subinterval’}
Caution
This function supports with low-level constructs NOT the high-level UN (uncertain number) objects. For UN objects, use Propagation class as an high-level API.
See also
Propagation(): the high-level API for uncertain number propagation.Example
>>> from pyuncertainnumber import pba >>> from pyuncertainnumber.propagation.p import EpistemicPropagation >>> def foo(x): return x[0] ** 3 + x[1] + x[2] >>> a = pba.I(1, 5) >>> b = pba.I(7, 13) >>> c = pba.I(5, 10) >>> ep = EpistemicPropagation(vars=[a,b,c], func=foo, method='subinterval') >>> result = ep(n_sub=20, style='endpoints')
- type_check()¶
only intervals
- method_check()¶
if the method is suitable for the nature of the UN
- run(**kwargs)¶
doing the propagation
- class pyuncertainnumber.propagation.p.MixedPropagation(vars, func, method, dependency=None, interval_strategy=None)¶
Bases:
PMixed uncertainty propagation class for construct
- Parameters:
vars (Pbox or DempsterShafer) – a list of uncertain numbers objects
func (callable) – the response or performance function applied to the uncertain numbers
method (str) – a string indicating the method to be used for pbox propagation, including {‘interval_monte_carlo’, ‘slicing’, ‘double_monte_carlo’}.
dependency (string or Dependency) – a Dependency object(i.e. a copula function) to model the dependency structure among input variables. Strings such as “independence” accepted for independence.
interval_strategy (str) – a sub-level strategy selector for interval propagation, including {‘direct’, ‘subinterval’, ‘endpoints’}.
Caution
This function supports with low-level constructs NOT the high-level UN (uncertain number) objects. For UN objects, use Propagation class as an high-level API.
See also
Propagation(): the high-level API for uncertain number propagation.Warning
The computation cost increases exponentially with the number of input variables and the number of slices. Be cautious with the choice of number of slices
n_slicesgiven the number of input variablesvarsof the response function.Note
Discussion of the methods and strategies. When choosing
interval_strategy, “direct” requires function signature to take a list of inputs, whereas “subinterval” and “endpoints” require the function to take a vectorised signature. Currently, only “interval_monte_carlo” supports with dependency structures (e.g. copulas).When calling the run function to do propagation, extra keyword arguments are needed to be passed down to the selected method. For example, n_sam for “interval_monte_carlo”; n_slices for “slicing”; n_outer, n_inner for “double_monte_carlo”.
Example
>>> from pyuncertainnumber import pba >>> from pyuncertainnumber.propagation.p import MixedPropagation >>> 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 = MixedPropagation(vars=[a,b,c], func=foo, method='slicing', interval_strategy='subinterval') >>> result = mix.run(n_slices=20, n_sub=2, style='endpoints')
- interval_strategy = None¶
- type_check()¶
Inspection if inputs are mixed uncertainy model
- method_check()¶
Check if the method is suitable for mixed uncertainty propagation
- run(**kwargs)¶
doing the propagation. Extra keyword are needed to be passed down to the selected method
- class pyuncertainnumber.propagation.p.Propagation(vars: list[pyuncertainnumber.characterisation.uncertainNumber.UncertainNumber], func: callable, method: str, dependency: str | pyuncertainnumber.pba.dependency.Dependency = None, interval_strategy: str = None)¶
High-level integrated class for the propagation of uncertain numbers
- Parameters:
vars (UncertainNumber) – a list of uncertain numbers objects
func (Callable) – the response or performance function applied to the uncertain numbers
method (str) – a string indicating the method to be used for propagation (e.g. “monte_carlo”, “endpoint”, etc.) which may depend on the constructs of the uncertain numbers. See notes about function signature.
dependency (string or Dependency) – a Dependency object(i.e. a copula function) to model the dependency structure among input variables. Strings such as “independence” accepted for independence.
interval_strategy (str) – a strategy for interval propagation, including {‘direct’, ‘subinterval’, ‘endpoints’} which will affect the function signature of the response function. See notes about function signature.
Caution
This class supports with high-level computation with UncertainNumber objects.
Note
Discussion of the methods and strategies. When choosing
interval_strategy, “direct” requires function signature to take a list of inputs, whereas “subinterval” and “endpoints” require the function to take a vectorised signature.Warning
The computation cost increases exponentially with the number of input variables and the number of slices. Be cautious with the choice of number of slices
n_slicesgiven the number of input variablesvarsof the response function.Example
>>> import pyuncertainnumber as pun >>> # construction of uncertain number objects >>> a = pun.I(2, 3) >>> b = pun.normal(4, 1) >>> c = pun.uniform([4,5], [9,10])
>>> # vectorised function signature with matrix input (2D np.ndarray) >>> def foo_vec(x): return x[:, 0] ** 3 + x[:, 1] + x[:, 2]
>>> # high-level propagation API >>> p = Propagation(vars=[a,b,c], >>> func=foo, >>> method='slicing', >>> interval_strategy='subinterval' >>> )
>>> # heavy-lifting of propagation >>> t = p.run(n_sam=20, n_sub=2, style='endpoints')
- _vars¶
- _func¶
- method¶
- dependency = None¶
- interval_strategy = None¶
- _post_init_check()¶
Some checks after initialisation
- assign_method()¶
Assign the propagation method based on the essence of constructs
- property constructs¶
return the underlying constructs
- run(**kwargs)¶
Doing the propagation and return UN
- Returns:
the result of the propagation as an uncertain number object
- Return type: