pyuncertainnumber.propagation.uncertaintyPropagation ==================================================== .. py:module:: pyuncertainnumber.propagation.uncertaintyPropagation Functions --------- .. autoapisummary:: pyuncertainnumber.propagation.uncertaintyPropagation.aleatory_propagation pyuncertainnumber.propagation.uncertaintyPropagation.mixed_propagation pyuncertainnumber.propagation.uncertaintyPropagation.epistemic_propagation pyuncertainnumber.propagation.uncertaintyPropagation.Propagation pyuncertainnumber.propagation.uncertaintyPropagation.plotPbox pyuncertainnumber.propagation.uncertaintyPropagation.main Module Contents --------------- .. py:function:: aleatory_propagation(vars: list = None, results: pyuncertainnumber.propagation.utils.Propagation_results = None, func: Callable = None, n_sam: int = 500, method: str = 'monte_carlo', save_raw_data=False, *, base_path=np.nan, **kwargs) This function propagates aleatory uncertainty through a given function (`func`) using either Monte Carlo or Latin Hypercube sampling, considering the aleatory uncertainty represented by a list of `UncertainNumber` objects (`vars`). :param - vars: A list of UncertainNumber objects, each representing an input variable with its associated uncertainty. :type - vars: list :param - func: The function to propagate uncertainty through. :type - func: Callable :param - n_sam: The number of samples to generate. Default is 500. :type - n_sam: int :param - method: The sampling method ('monte_carlo' or 'latin_hypercube'). Defaults to 'monte_carlo'. :type - method: str, optional :param - save_raw_data: Whether to save raw data ('yes' or 'no'). Defaults to 'no'. :type - save_raw_data: str, optional :param - base_path: Path for saving results (if save_raw_data is 'yes'). Defaults to np.nan. :type - base_path: str, optional :param - **kwargs: Additional keyword arguments to be passed to the UncertainNumber constructor. signature: aleatory_propagation(x:np.ndarray, f:Callable, n:int, ...) -> Propagation_results .. note:: - If the `f` function returns multiple outputs, the `all_output` array will be 2-dimensional y and x for all x samples. :returns: A `Propagation_results` object containing: - 'un': A list of UncertainNumber objects, each representing the output(s) of the function. - 'raw_data': A dictionary containing raw data (if save_raw_data is 'yes'): - 'x': All generated input samples. - 'f': Corresponding output values for each input sample. :rtype: Propagation_results :raises ValueError: For invalid method, save_raw_data, or missing arguments. .. py:function:: mixed_propagation(vars: list, func: Callable = None, results: pyuncertainnumber.propagation.utils.Propagation_results = None, method='second_order_extremepoints', n_disc: Union[int, numpy.ndarray] = 10, condensation: int = None, tOp: Union[float, numpy.ndarray] = 0.999, bOt: Union[float, numpy.ndarray] = 0.001, save_raw_data='no', *, base_path=np.nan, **kwargs) Performs mixed uncertainty propagation through a given function. This function handles uncertainty propagation when there's a mix of aleatory and epistemic uncertainty in the input variables. :param - vars: A list of uncertain variables, which can be a mix of different uncertainty types (e.g., intervals, distributions). :type - vars: list :param - func: The function to propagate uncertainty through. :type - func: Callable :param - results: An object to store propagation results. Defaults to None, in which case a new `Propagation_results` object is created. :type - results: Propagation_results, optional :param - method: The mixed uncertainty propagation method. Can be one of: 'second_order_endpoints', 'second_order_vertex', 'second_order_extremepoints', 'first_order_extremepoints'. Defaults to 'second_order_extremepoints'. :type - method: str, optional :param - n_disc: Number of discretization points for interval variables. Defaults to 10. :type - n_disc: Union[int, np.ndarray], optional :param - condensation: Parameter for reducing the complexity of the output uncertainty representation. Defaults to None. :type - condensation: int, optional :param - tOp: Upper threshold or bound used in some methods. Defaults to 0.999. :type - tOp: Union[float, np.ndarray], optional :param - bOt: Lower threshold or bound used in some methods. Defaults to 0.001. :type - bOt: Union[float, np.ndarray], optional :param - save_raw_data: Whether to save raw data ('yes' or 'no'). Defaults to 'no'. :type - save_raw_data: str, optional :param - base_path: Path for saving results (if save_raw_data is 'yes'). Defaults to np.nan. :type - base_path: str, optional :param - **kwargs: Additional keyword arguments passed to the underlying propagation methods. signature: mixed_propagation(vars: list, func: Callable, results: Propagation_results = None, ...) -> Propagation_results .. rubric:: Notes - It can be used if each uncertain number is exrpessed in terms of precise distributions. :returns: A `Propagation_results` object containing the results of the mixed uncertainty propagation. The format of the results depends on the chosen `method`. :rtype: Propagation_results :raises ValueError: For invalid `method` or `save_raw_data`. .. rubric:: Examples >>> a = mixed_propagation(vars= [y, L, I, F, E], func= cantilever_beam_func, method= 'second_order_extremepoints', n_disc=8, #save_raw_data= "no"#, save_raw_data= "yes", base_path= base_path ) .. py:function:: epistemic_propagation(vars, func, method: str = None, save_raw_data=False, *, results: pyuncertainnumber.propagation.utils.Propagation_results = None, n_sub: numpy.integer = None, n_sam: numpy.integer = None, x0: numpy.ndarray = None, base_path=np.nan, tol_loc: numpy.ndarray = None, options_loc: dict = None, method_loc='Nelder-Mead', pop_size=1000, n_gen=100, tol=0.001, n_gen_last=10, algorithm_type='NSGA2', **kwargs) Performs epistemic uncertainty propagation through a given function. This function implements various methods for propagating epistemic uncertainty, typically represented as intervals. :param - vars: A list of `UncertainNumber` objects representing the input variables with their associated interval uncertainty. :type - vars: list :param - func: The function to propagate uncertainty through. :type - func: Callable :param - results: An object to store propagation results. Defaults to None, in which case a new `Propagation_results` object is created. :type - results: Propagation_results, optional :param - n_sub: Number of subintervals for subinterval methods. Defaults to None. :type - n_sub: np.integer, optional :param - n_sam: Number of samples for sampling-based methods. Defaults to None. :type - n_sam: np.integer, optional :param - x0: Initial guess for local optimization methods. Defaults to None. :type - x0: np.ndarray, optional :param - method: The uncertainty propagation method to use. Defaults to "endpoint". :type - method: str, optional :param - save_raw_data: Whether to save raw data ('yes' or 'no'). Defaults to "no". :type - save_raw_data: str, optional :param - base_path: Path for saving results (if save_raw_data is 'yes'). Defaults to np.nan. :type - base_path: str, optional :param - tol_loc: Tolerance for local optimization. Defaults to None. :type - tol_loc: np.ndarray, optional :param - options_loc: Options for local optimization. Defaults to None. :type - options_loc: dict, optional :param - method_loc: Method for local optimization. Defaults to 'Nelder-Mead'. :type - method_loc: str, optional :param - pop_size: Population size for genetic algorithms. Defaults to 1000. :type - pop_size: int, optional :param - n_gen: Number of generations for genetic algorithms. Defaults to 100. :type - n_gen: int, optional :param - tol: Tolerance for genetic algorithms. Defaults to 1e-3. :type - tol: float, optional :param - n_gen_last: Number of last generations for genetic algorithms. Defaults to 10. :type - n_gen_last: int, optional :param - algorithm_type: Type of genetic algorithm. Defaults to 'NSGA2'. :type - algorithm_type: str, optional :param - **kwargs: Additional keyword arguments passed to the `UncertainNumber` constructor. signature: epistemic_propagation(vars: list, func: Callable, results: Propagation_results = None, ...) -> Propagation_results .. rubric:: Notes - It supports a wide range of techniques, including: 1. Interval-based methods: - `endpoints` or `vertex`: Calculates the function output at the endpoints or vertices of the input intervals. - `extremepoints`: Considers all possible combinations of interval endpoints to find the extreme values of the output. - `subinterval` or `subinterval_reconstitution`: Divides the input intervals into subintervals and performs propagation on each subinterval. 2. Sampling-based methods: - `monte_carlo`, `latin_hypercube`: Uses Monte Carlo or Latin Hypercube sampling within the input intervals. - `monte_carlo_endpoints`, `latin_hypercube_endpoints`: Combines sampling with evaluation at interval endpoints. - `cauchy`, `endpoint_cauchy`, `endpoints_cauchy`: Uses Cauchy deviates for sampling. 3. Optimization-based methods: - `local_optimization` or `local_optimisation`: Uses local optimization algorithms to find the minimum or maximum output values. - `genetic_optimisation` or `genetic_optimization`: Uses genetic algorithms for global optimization. :returns: A `Propagation_results` object containing the results of the epistemic uncertainty propagation. The format of the results depends on the chosen `method`. :rtype: - Propagation_results :raises - ValueError: For invalid `method`, `save_raw_data`, or missing arguments. :raises - TypeError: If `func` is not callable for optimization methods. .. rubric:: Example >>> a = epistemic_propagation(vars= [ y, L, I, F, E], func= cantilever_beam_func, method= 'extremepoints', n_disc=8, save_raw_data= "no" ) .. py:function:: Propagation(vars: list, func: Callable, results: pyuncertainnumber.propagation.utils.Propagation_results = None, n_sub: numpy.integer = 3, n_sam: numpy.integer = 500, x0: numpy.ndarray = None, method=None, n_disc: Union[int, numpy.ndarray] = 10, condensation: int = None, tOp: Union[float, numpy.ndarray] = 0.999, bOt: Union[float, numpy.ndarray] = 0.001, save_raw_data='no', *, base_path=np.nan, tol_loc: numpy.ndarray = None, options_loc: dict = None, method_loc='Nelder-Mead', pop_size=1000, n_gen=100, tol=0.001, n_gen_last=10, algorithm_type='NSGA2', **kwargs) Performs uncertainty propagation through a given function with uncertain inputs. This function automatically selects and executes an appropriate uncertainty propagation method based on the types of uncertainty in the input variables. It supports interval analysis, probabilistic methods, and mixed uncertainty propagation. :param - vars: A list of uncertain variables. :type - vars: list :param - func: The function through which to propagate uncertainty. :type - func: Callable :param - results: An object to store propagation results. Defaults to None, in which case a new `Propagation_results` object is created. :type - results: Propagation_results, optional :param - n_sub: Number of subintervals for interval-based methods. Defaults to 3. :type - n_sub: np.integer, optional :param - n_sam: Number of samples for Monte Carlo simulation. Defaults to 500. :type - n_sam: np.integer, optional :param - x0: Initial guess for optimization-based methods. Defaults to None. :type - x0: np.ndarray, optional :param - method: Specifies the uncertainty propagation method. Defaults to None, which triggers automatic selection. :type - method: str, optional :param - n_disc: Number of discretization points. Defaults to 10. :type - n_disc: Union[int, np.ndarray], optional :param - condensation: Parameter for reducing output complexity. Defaults to None. :type - condensation: int, optional :param - tOp: Upper threshold or bound. Defaults to 0.999. :type - tOp: Union[float, np.ndarray], optional :param - bOt: Lower threshold or bound. Defaults to 0.001. :type - bOt: Union[float, np.ndarray], optional :param - save_raw_data: Whether to save intermediate results ('yes' or 'no'). Defaults to 'no'. :type - save_raw_data: str, optional :param - base_path: Path for saving data. Defaults to np.nan. :type - base_path: str, optional :param - tol_loc: Tolerance for local optimization. Defaults to None. :type - tol_loc: np.ndarray, optional :param - options_loc: Options for local optimization. Defaults to None. :type - options_loc: dict, optional :param - method_loc: Method for local optimization. Defaults to 'Nelder-Mead'. :type - method_loc: str, optional :param - pop_size: Population size for genetic algorithms. Defaults to 1000. :type - pop_size: int, optional :param - n_gen: Number of generations for genetic algorithms. Defaults to 100. :type - n_gen: int, optional :param - tol: Tolerance for genetic algorithms. Defaults to 1e-3. :type - tol: float, optional :param - n_gen_last: Number of last generations for genetic algorithms. Defaults to 10. :type - n_gen_last: int, optional :param - algorithm_type: Type of genetic algorithm. Defaults to 'NSGA2'. :type - algorithm_type: str, optional :param \*\*kwargs: Additional keyword arguments passed to the underlying propagation methods. signature: - Propagation(vars: list, func: Callable, results: Propagation_results = None, ...) -> Propagation_results :returns: A `Propagation_results` object including: - 'un': A list of UncertainNumber objects, each representing the output(s) of the function. - 'raw_data': depending on the method selected. :rtype: - Propagation_results .. rubric:: Example >>> a = Propagation(vars= [ y, L, I, F, E], func= cantilever_beam_func, method= 'extremepoints', n_disc=8, save_raw_data= "no" ) .. py:function:: plotPbox(xL, xR, p=None) Plots a p-box (probability box) using matplotlib. :param xL: A 1D NumPy array of lower bounds. :type xL: np.ndarray :param xR: A 1D NumPy array of upper bounds. :type xR: np.ndarray :param p: A 1D NumPy array of probabilities corresponding to the intervals. Defaults to None, which generates equally spaced probabilities. :type p: np.ndarray, optional :param color: The color of the plot. Defaults to 'k' (black). :type color: str, optional .. py:function:: main() implementation of any method for epistemic uncertainty on the cantilever beam example