probability
get_triangular_distribution(a, b, c)
Generate a triangular distribution given the mode and the range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
The lower bound of the distribution. |
required |
b
|
float
|
The upper bound of the distribution. |
required |
c
|
float
|
The mode of the distribution (must be between |
required |
Returns:
| Type | Description |
|---|---|
rv_continuous
|
A frozen |
Notes
The triangular distribution is defined by three parameters:
- a is the minimum value,
- b is the maximum value,
- c is the mode (the peak of the distribution).
Source code in darpi/quantitative/probability.py
get_samples(distribution, risk_probability)
Generate samples from a given distribution based on a risk probability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distribution
|
rv_continuous
|
A frozen |
required |
risk_probability
|
float
|
The probability of risk occurrence, determining the proportion of non-zero samples. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
An array of samples, where a portion of the samples is drawn from the distribution and the remainder are zeros, based on the risk probability. |
Notes
The number of samples is determined by a constant ITERATIONS.
Source code in darpi/quantitative/probability.py
sum_samples(sample_sets)
Sum multiple sets of samples element-wise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_sets
|
list of np.ndarray
|
A list of sample arrays to be summed. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
An array representing the element-wise sum of the input sample arrays. |
Notes
All arrays in sample_sets must have the same shape.
Source code in darpi/quantitative/probability.py
get_empirical_cdf(data)
Calculate the empirical cumulative distribution function (CDF) for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
The data array for which to compute the empirical CDF. |
required |
Returns:
| Type | Description |
|---|---|
CDFData
|
An object containing the sorted data and corresponding cumulative probabilities. |
Notes
The empirical CDF is the proportion of data points less than or equal to a given value.
Source code in darpi/quantitative/probability.py
get_empirical_ppf(samples)
Calculate the empirical percent-point function (PPF) for a dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
samples
|
ndarray
|
The data array for which to compute the empirical PPF. Use |
required |
Returns:
| Type | Description |
|---|---|
PPFData
|
An object containing the cost values at each percentile and the corresponding percentiles. |
Notes
The empirical PPF is the inverse of the empirical CDF, mapping percentiles to samples values.
Source code in darpi/quantitative/probability.py
get_histogram_data(data)
Calculate histogram data, excluding zero values and normalizing by total data points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
The data array for which to compute the histogram. |
required |
Returns:
| Type | Description |
|---|---|
HistogramData
|
An object containing the histogram bin edges and the normalized frequency. |
Notes
The histogram is computed excluding zero values in the data. Frequencies are normalized by the total number of data points.
Source code in darpi/quantitative/probability.py
get_aggregate_data(risks)
Generate aggregate sample data based on multiple risk scenarios.
This function processes a dictionary of risk scenarios where each scenario has associated costs and a probability of occurrence. It generates sample data for each risk using a triangular distribution and aggregates these samples into a single dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
risks
|
dict of str to dict of str to tuple or float
|
A dictionary where the keys are risk names (str), and the values are dictionaries containing: - "costs": A tuple of three integers representing the minimum cost, mode, and maximum cost. - "probability": A float representing the probability of the risk occurring. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
An array of aggregated samples from all the provided risks, where each risk's samples are generated based on its triangular distribution and probability. |
Notes
- The triangular distribution is generated using the costs provided for each risk, where:
ais the minimum cost,cis the mode (most likely cost),bis the maximum cost.- The number of samples generated for each risk is proportional to the risk's probability.
- The samples from all risks are summed element-wise to produce the final aggregated data.
Example
Example of risks dictionary structure:
risks = { "Risk 1": {"costs": (1000, 2000, 5000), "probability": 1}, "Risk 2": {"costs": (2000, 4000, 8000), "probability": 0.8}, "Risk 3": {"costs": (2800, 4000, 10000), "probability": 0.5}, } samples = get_aggregate_data(risks)