uncertain
Uncertain numbers: probability distributions, uncertainty propagation and more.
- class uncertain.UncertainValue(nominal_value, lower_bound=None, upper_bound=None, prob_distribution='uniform', distribution_param=None, n_samples=100000, samples=None)
Uncertain values.
Class used to define uncertain real numbers. Each uncertain number is described with a nominal value, upper and lower bounds as well as a probability distribution between these bounds. To keep track of the uncertainties, random samples are taking according to the defined probability distribution. Uncertainty propagation is calculted using Monte-Carlo methods.
- nominal_value
Value you’d assign to your variable if no uncertainty would to be considered
- Type
float or int
- lower_bound
smallest possible value. Default value is nominal_value. If the uncertain number has no lower bound, set this variable to -inf.
- Type
float or int
- upper_bound
largest possible value. Default value is nominal value. If the uncertain number has no upper bound, set this variable to inf.
- Type
float or int
- prob_distribution
probability distribution type f the uncertainty. Possible input values are ‘normal’, ‘discrete’ and ‘uniform’ (default value). Other ossible values are ‘constant’ (if the number is a fixed number with lower_bound = nominal_value = upper_bound) and ‘custom’ (results from doing calculations with other types of distribution).
- Type
string
- distribution_param
parameters needed to describe the given probability distribution type. For the ‘normal’ distribution type, the parameters are ‘[mean, standard deviation]’. For ‘uniform’, no parameters are needed. For a ‘discrete’ distribution, the parameters are either a list of possible values [val1, val2, …] or a list of lists with possible values and the probability of each value [[val1, prob1], [val2, prob2], …].
- Type
list
- n_samples
number of samples to be used for the calculation of the probability distribution. Default value is 100 000. For constants, only 1 value is used as a default.
- Type
int
- samples
List/array with samples.
- Type
list or numpy.ndarray
- cos()
Calculate the cosine of the uncertain value.
Function is used as well when calling numpy.cos().
- describe()
This function is used to display the information describing an uncertain value: nominal value, lower bound, upper bound, probability distribution type and number of samples.
- plot_distribution(label=None, new_figure=False, title=None, plot_type='pdf', alpha=1, density=True, save=False, fname='dist.png')
Plot the (cumulative) probability distribution.
Plots the probability distribution (PDF) or cumulative probability distribution (CDF) of an uncertain number.
- Parameters
label (string) – String used to label the histogram. Default value is None (probability distribution is not labeled).
new_figure (bool) – If True, the value is plotted in a new window. Defaut value is False.
title (string) – Plot title. Default value is None.
plot_type (string) – Type of plot. Can be either ‘pdf’ (probability distribution, default value) or ‘cdf’ (cumulative distribution)
alpha (int) – TODO. Default value is 1.
density (bool) – TODO. Default value is True.
save (bool) – If True, the figure is saved as a file. Default value is False.
fname (str) – Name of the file in which the figure is saved. Default name is ‘dist.png’.
- Raises
ValueError – With unknown plot type.
- sin()
Calculate the sine of the uncertain value.
Function is used as well when calling numpy.sin().
- statistical_parameter()
Computes statistical parameters (mean, variance,…) of the uncertain number using the given samples.
- tan()
Calculate the tangens of the uncertain value.
Function is used as well when calling numpy.tan().
- uncertain.from_data(data_list)
Generates an UncertainValue object from a list with numbers.
A normal distribution is assumed.
- Parameters
data_list (list or numpy.ndarray) – List with real numbers.
- Returns
- Uncertain number with the same mean and standard
deviation as the input data_list.
- Return type
- uncertain.probability_in_interval(uncertain_value, interval)
Calculates the probability of an uncertain value to be in an interval.
- Parameters
uncertain_value (UncertainValue) – Uncertain value for which the probability is calculated.
interval (array) – Interval U defined by a lower and upper bound [u_min, u_max].
- Returns
Probability.
- Return type
float