pyuncertainnumber.propagation.utils =================================== .. py:module:: pyuncertainnumber.propagation.utils Classes ------- .. autoapisummary:: pyuncertainnumber.propagation.utils.Propagation_results Functions --------- .. autoapisummary:: pyuncertainnumber.propagation.utils.process_alea_results pyuncertainnumber.propagation.utils.process_results pyuncertainnumber.propagation.utils.header_results pyuncertainnumber.propagation.utils.post_processing pyuncertainnumber.propagation.utils.create_folder pyuncertainnumber.propagation.utils.create_csv pyuncertainnumber.propagation.utils.save_results pyuncertainnumber.propagation.utils.condense_bounds Module Contents --------------- .. py:class:: Propagation_results(un: numpy.ndarray = None, raw_data: dict = None) Stores the results of uncertainty propagation with multiple outputs, sharing raw_data x and f. :param un: np.array of UncertainNumber objects (one for each output). :type un: np.ndarray :param raw_data: Dictionary containing raw data shared across outputs: x (np.ndarray): Input values. f (np.ndarray): Output values. min (np.ndarray): Array of dictionaries, one for each output, containing 'x', 'f' for the minimum of that output. max (np.ndarray): Array of dictionaries, one for each output, containing 'x', 'f' for the maximum of that output. bounds (np.ndarray): 2D array of lower and upper bounds for each output. :type raw_data: dict .. rubric:: Notes - use `foo.un` to access the UncertainNumber objects. .. py:method:: add_raw_data(x=None, f=None, K=None, sign_x: numpy.ndarray = None) Adds raw data to the results. .. py:method:: summary() Prints the results in a formatted way, handling None values and multiple outputs. .. py:function:: process_alea_results(results) :param - results: A `Propagation_results` object containing raw epistemic propagation results. This object is modified in-place. :type - results: Propagation_results signature: - process_alea_results(results: Propagation_results) -> Propagation_results .. rubric:: Notes - Processes the results of aleatory uncertainty propagation. - This function takes a `Propagation_results` object containing raw aleatory propagation results and performs the following actions: 1. Creates `Distribution` objects: - If output data exists in `results.raw_data['f']`, it creates an 'UncertainNumber' object for each output dimension using the sample data. - These `UncertainNumber` objects are stored in `results.un`. - They have essense = 'distribution' 2. Saves raw data (optional): - If `save_raw_data` is set to 'yes', it saves the raw propagation data (input samples and corresponding output values) to a file. :returns: The modified `Propagation_results` object with `UncertainNumber` objects added to `results.un` and potentially with raw data saved to a file. :rtype: - Propagation_results :raises - ValueError: If the shape of `results.raw_data['f']` is invalid .. rubric:: Examples >>> a = mixed_propagation(vars= [y, L, I, F, E], >>> fun= cantilever_beam_func, >>> method= 'monte_carlo', >>> n_disc=8, >>> save_raw_data= "no" >>> ) .. py:function:: process_results(results: Propagation_results) :param - results: A `Propagation_results` object containing raw epistemic propagation results. This object is modified in-place. :type - results: Propagation_results .. rubric:: Notes - Processes the results of epistemic uncertainty propagation. - This function takes a `Propagation_results` object containing raw epistemic propagation results and performs the following actions: 1. Creates `UncertainNumber` objects: - If output bounds exist in `results.raw_data['bounds']`, it creates `UncertainNumber` objects with "interval" essence, representing the resulting interval uncertainty. - It handles both single-output (1D array of bounds) and multi-output (2D array of bounds) cases. - These `UncertainNumber` objects are stored in `results.un`. 2. Saves raw data (optional): - If `save_raw_data` is set to 'yes', it saves the raw propagation data to a file. signature: - process_results(results: Propagation_results) -> Propagation_results :returns: The modified `Propagation_results` object with `UncertainNumber` objects added to `results.un` and potentially with raw data saved to a file. :rtype: - Propagation_results :raises - ValueError: If the shape of `results.raw_data['bounds']` is invalid. .. py:function:: header_results(all_output, all_input, method=None) Determine generic header for output and input. :param all_output: A NumPy array containing the output values. :type all_output: np.ndarray :param all_input: A NumPy array containing the input values. :type all_input: np.ndarray :returns: A list of strings representing the header for the combined DataFrame. :rtype: list .. py:function:: post_processing(all_input: numpy.ndarray, all_output: numpy.ndarray = None, method=None, res_path=None) Post-processes the results of an uncertainty propagation (UP) method. This function takes the input and output values from a UP method, combines them into a pandas DataFrame, and optionally saves the raw data to a CSV file. It also checks for NaN values in the output and logs them with their corresponding input values if found. If all_output is None, it creates a DataFrame with only the input data. :param all_input: A NumPy array containing the input values used in the UP method. :type all_input: np.ndarray :param all_output: A NumPy array containing the corresponding output values from the UP method. Defaults to None. :type all_output: np.ndarray, optional :param res_path: The path to the directory where the results will be saved. Defaults to None. :type res_path: str, optional :returns: A pandas DataFrame containing the combined output and input data (if all_output is provided). If all_output is None, it returns a DataFrame with only the input data. :rtype: pandas.DataFrame .. py:function:: create_folder(base_path, method) Creates a folder named after the called UP method where the results files are stored :param - base_path: The base path :param - method: the name of the called method signature: create_folder(base_path: string, method: string ) -> path.folder .. note:: - the augument `base_path` will specify the location of the created results folder. - the argument `method` will provide the name for the results folder. :returns: - A folder in a prespecified path .. rubric:: Example base_path = "C:/Users/DAWS2_code/UP" method = "vertex" y = create_folder(base_path, method) .. py:function:: create_csv(res_path, filename, data) Creates a .csv file and sotres it in a pre-specified folder with results generated by a UP method :param - res_path: A folder in a prespecified path named after the called UP method :param - filename: the name of the file :param - data: a pandas.dataframe with results from UP method signature: create_csv(res_path = path, filename = filename, data = pandas.dataframe) -> path.filename .. note:: - the augument `res_path` will specify the folder where the .csv file will be created. - argument `file` will provide the name of hte .csv file. - argument `data` will provide data in terms of pandas.dataframe. :returns: - A .csv file in a prespecified folder .. rubric:: Example base_path = "C:/Users/DAWS2_code/UP/vertex" filename = 'min_max_values' df = pd.DataFrame( {"Name" : ["y0", "y0"], "fun" : ["min","max"] "y0" : [4, 6]}, index = [1, 2, 3]) header = ['Name', 'fun', 'values'] y = create_csv(res_path, filename, df) .. py:function:: save_results(data, method, res_path, fun=None) .. py:function:: condense_bounds(bounds, N) Condenses lower and upper bounds of a probability distribution to a specified size. :param bounds: A NumPy array of shape (num_outputs, 2, num_points) representing the lower and upper bounds of a probability distribution for potentially multiple outputs. The first dimension corresponds to different outputs of the function, the second dimension corresponds to lower and upper bounds (0 for lower, 1 for upper), and the third dimension corresponds to the original discretization points. :param N: The desired size of the condensed arrays. :returns: A NumPy array of shape (num_outputs, 2, N) containing the condensed lower and upper bounds.