pyuncertainnumber.propagation.utils

Classes

Propagation_results

Stores the results of uncertainty propagation with multiple outputs, sharing raw_data x and f.

Functions

process_alea_results(results)

process_results(results)

header_results(all_output, all_input[, method])

Determine generic header for output and input.

post_processing(all_input[, all_output, method, res_path])

Post-processes the results of an uncertainty propagation (UP) method.

create_folder(base_path, method)

Creates a folder named after the called UP method where the results files are stored

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

save_results(data, method, res_path[, fun])

condense_bounds(bounds, N)

Condenses lower and upper bounds of a probability distribution to a specified size.

Module Contents

class pyuncertainnumber.propagation.utils.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.

Parameters:
  • un (np.ndarray) – np.array of UncertainNumber objects (one for each output).

  • raw_data (dict) –

    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.

Notes

  • use foo.un to access the UncertainNumber objects.

add_raw_data(x=None, f=None, K=None, sign_x: numpy.ndarray = None)

Adds raw data to the results.

summary()

Prints the results in a formatted way, handling None values and multiple outputs.

pyuncertainnumber.propagation.utils.process_alea_results(results)
Parameters:

results (-) – A Propagation_results object containing raw epistemic propagation results. This object is modified in-place.

signature:
  • process_alea_results(results: Propagation_results) -> Propagation_results

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.

Return type:

  • Propagation_results

Raises:

- ValueError – If the shape of results.raw_data[‘f’] is invalid

Examples

>>> a = mixed_propagation(vars= [y, L, I, F, E],
>>>                 fun= cantilever_beam_func,
>>>                 method= 'monte_carlo',
>>>                 n_disc=8,
>>>                 save_raw_data= "no"
>>>             )
pyuncertainnumber.propagation.utils.process_results(results: Propagation_results)
Parameters:

results (-) – A Propagation_results object containing raw epistemic propagation results. This object is modified in-place.

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.

Return type:

  • Propagation_results

Raises:

- ValueError – If the shape of results.raw_data[‘bounds’] is invalid.

pyuncertainnumber.propagation.utils.header_results(all_output, all_input, method=None)

Determine generic header for output and input.

Parameters:
  • all_output (np.ndarray) – A NumPy array containing the output values.

  • all_input (np.ndarray) – A NumPy array containing the input values.

Returns:

A list of strings representing the header for the combined DataFrame.

Return type:

list

pyuncertainnumber.propagation.utils.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.

Parameters:
  • all_input (np.ndarray) – A NumPy array containing the input values used in the UP method.

  • all_output (np.ndarray, optional) – A NumPy array containing the corresponding output values from the UP method. Defaults to None.

  • res_path (str, optional) – The path to the directory where the results will be saved. Defaults to None.

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.

Return type:

pandas.DataFrame

pyuncertainnumber.propagation.utils.create_folder(base_path, method)

Creates a folder named after the called UP method where the results files are stored

Parameters:
  • base_path (-) – The base path

  • 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

Example

base_path = “C:/Users/DAWS2_code/UP” method = “vertex” y = create_folder(base_path, method)

pyuncertainnumber.propagation.utils.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

Parameters:
  • res_path (-) – A folder in a prespecified path named after the called UP method

  • filename (-) – the name of the file

  • 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

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)

pyuncertainnumber.propagation.utils.save_results(data, method, res_path, fun=None)
pyuncertainnumber.propagation.utils.condense_bounds(bounds, N)

Condenses lower and upper bounds of a probability distribution to a specified size.

Parameters:
  • 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.

  • 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.