reemission.salib.distributions
- class reemission.salib.distributions.CategoricalConversionMixin[source]
Bases:
object
Mixin for categorical conversion methods.
- cat_to_num(cat_values: Sequence[str] | str) Sequence[int] | int [source]
Convert categorical values to numerical indices
- static is_iterable(value) bool [source]
Check if the value is an iterable. :param value: The value to check.
Returns: bool: True if the value is an iterable and not a scalar, False otherwise.
- num_to_cat(num_values: Sequence[int] | int) Sequence[str] | str [source]
Convert numerical indices to categorical values
- class reemission.salib.distributions.CategoricalHistogramDistribution(categories: ~typing.Tuple[str, ...] = <factory>, probabilities: ~typing.Tuple[float, ...] = <factory>, nominal_as_index: bool = True, nominal_category: str | None = None)[source]
Bases:
CategoricalConversionMixin
,Distribution
Categorical histogram distribution for categorical variables
- __post_init__() None [source]
Ensure categories and probabilities are valid for categorical histogram distribution
- categories: Tuple[str, ...]
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- nominal_as_index: bool = True
- nominal_category: str | None = None
- property nominal_value: str
Returns the category with the highest probability
- probabilities: Tuple[float, ...]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the categorical histogram distribution
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.CategoricalNormalDistribution(categories: ~typing.Tuple[str, ...] = <factory>, mean: float = 0.0, std_dev: float = 1.0, nominal_as_index: bool = True, nominal_category: str | None = None)[source]
Bases:
CategoricalConversionMixin
,Distribution
Normal distribution for categorical variables This distribution is defined by a mean and standard deviation, and samples are drawn from a normal distribution with respect to the categories. .. attribute:: categories
Categories for the categorical variable.
- type:
Tuple[str, …]
- mean
Mean of the normal distribution.
- Type:
float
- std_dev
Standard deviation of the normal distribution.
- Type:
float
- nominal_as_index
If True, nominal_value is the middle category index, else it’s the middle category itself.
- Type:
bool
- nominal_category
If provided, overrides nominal_as_index to use this category as the nominal value.
- Type:
Optional[str]
- __post_init__() None [source]
Ensure categories are valid for categorical normal distribution
- categories: Tuple[str, ...]
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- mean: float = 0.0
- nominal_as_index: bool = True
- nominal_category: str | None = None
- property nominal_value: str
Return the category whose index is closest to the mean or return the nominal catergory if provided as attribute.
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the normal distribution for categorical variables
- std_dev: float = 1.0
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.CategoricalUniformDistribution(categories: ~typing.Tuple[str, ...] = <factory>, nominal_as_index: bool = True, nominal_category: str | None = None)[source]
Bases:
CategoricalConversionMixin
,Distribution
Uniform distribution for categorical variables This distribution is defined by a set of categories and samples are drawn uniformly from these categories. .. attribute:: categories
Categories for the categorical variable.
- type:
Tuple[str, …]
- nominal_as_index
If True, nominal_value is the middle category index, else it’s the middle category itself.
- Type:
bool
- nominal_category
If provided, overrides nominal_as_index to use this category as the nominal value.
- Type:
Optional[str]
- categories: Tuple[str, ...]
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- nominal_as_index: bool = True
- nominal_category: str | None = None
- property nominal_value: str
Return the middle category as nominal value
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the discrete uniform distribution
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.DiscreteHistogramDistribution(values: ~typing.Tuple[int, ...] = <factory>, probabilities: ~typing.Tuple[float, ...] = <factory>)[source]
Bases:
Distribution
Discrete histogram distribution for numerical variables. .. attribute:: values
Values for the discrete histogram distribution.
- type:
Tuple[int, …]
- probabilities
Probabilities for each value in the discrete histogram distribution.
- Type:
Tuple[float, …]
- __post_init__() None [source]
Ensure that values and probabilities are valid for discrete histogram distribution
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- property nominal_value: int
Returns the category with the highest probability, or the middle category if all probabilities are equal.
- probabilities: Tuple[float, ...]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the discrete histogram distribution
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- values: Tuple[int, ...]
- class reemission.salib.distributions.DiscreteNormalDistribution(mean: int, std_dev: float)[source]
Bases:
Distribution
Discrete normal distribution for numerical variables .. attribute:: mean
Mean of the discrete normal distribution (must be an integer).
- type:
int
- std_dev
Standard deviation of the discrete normal distribution (must be positive).
- Type:
float
- __post_init__() None [source]
Ensure mean is an integer for discrete normal distribution
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- mean: int
- property nominal_value: int
Returns the nominal value of the distribution”
- Returns:
The nominal value or range of values for the distribution.
- Return type:
int | float | List[int]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the discrete normal distribution
- std_dev: float
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.DiscreteUniformDistribution(bounds: Tuple[int, int])[source]
Bases:
Distribution
Discrete uniform distribution for numerical variables .. attribute:: bounds
Lower and upper bounds of the discrete uniform distribution (must be integers).
- type:
Tuple[int, int]
- __post_init__() None [source]
Ensure bounds are integers for discrete uniform distribution
- bounds: Tuple[int, int]
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- property nominal_value: int
Returns the nominal value of the distribution”
- Returns:
The nominal value or range of values for the distribution.
- Return type:
int | float | List[int]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the discrete uniform distribution
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.Distribution[source]
Bases:
ABC
Abstract base for parameterizations (std-dev or min/max).
- cat_to_num(cat_values: Sequence[str]) Sequence[int] [source]
Default implementation for converting categories to numbers
- abstract collapse() Distribution [source]
Collapse the distribution to a fixed value, if applicable.
- Returns:
A fixed distribution with bounds set to the nominal value.
- Return type:
- has_bounds() bool [source]
Check if the distribution has bounds
- is_categorical() bool [source]
Check if the distribution is categorical
- is_discrete() bool [source]
Check if the distribution is discrete
- is_normal() bool [source]
Check if the distribution is normal
- is_uniform() bool [source]
Check if the distribution is uniform or discrete uniform
- abstract property nominal_value: int | float | None
Returns the nominal value of the distribution”
- Returns:
The nominal value or range of values for the distribution.
- Return type:
int | float | List[int]
- num_to_cat(num_values: Sequence[int]) Sequence[str] [source]
Default implementation for converting numbers to categories
- abstract sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the distribution
- Returns:
An array of samples drawn from the distribution.
- Return type:
NDArray
- abstract to_dict() dict [source]
Convert the distribution to a dictionary representation
- abstract property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.DistributionType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
Enum for distribution types
- CATEGORICALHISTOGRAM = 'categorical-histogram'
- CATEGORICALNORMAL = 'categorical-normal'
- CATEGORICALUNIFORM = 'categorical-uniform'
- DISCRETEHISTOGRAM = 'discrete-histogram'
- DISCRETENORMAL = 'discrete-normal'
- DISCRETEUNIFORM = 'discrete-uniform'
- NORMAL = 'real-normal'
- UNIFORM = 'real-uniform'
- class reemission.salib.distributions.NormalDistribution(mean: int | float, std_dev: int | float)[source]
Bases:
Distribution
Standard (Gaussian) distribution .. attribute:: mean
Mean of the normal distribution.
- type:
int | float
- std_dev
Standard deviation of the normal distribution.
- Type:
int | float
- __post_init__() None [source]
Ensure mean and std_dev are valid for normal distribution
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- mean: int | float
- property nominal_value: int | float
Returns the nominal value of the distribution”
- Returns:
The nominal value or range of values for the distribution.
- Return type:
int | float | List[int]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the normal distribution
- std_dev: int | float
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.UniformDistribution(bounds: Tuple[float, float])[source]
Bases:
Distribution
Uniform distribution supported by SALib and Sobol sampling .. attribute:: bounds
Lower and upper bounds of the uniform distribution.
- type:
Tuple[float, float]
- __post_init__() None [source]
Ensure bounds are valid for uniform distribution
- bounds: Tuple[float, float]
- collapse() Distribution [source]
Collapse the distribution to a fixed value
- property nominal_value: int | float
Returns the nominal value of the distribution”
- Returns:
The nominal value or range of values for the distribution.
- Return type:
int | float | List[int]
- sample(n_samples: int) ndarray[tuple[Any, ...], dtype[_ScalarT]] [source]
Generate N samples from the uniform distribution
- to_dict() dict [source]
Convert the distribution to a dictionary representation
- property type: str
Returns the type of the parameter as a string.
- Returns:
The type of the parameter.
- Return type:
str
- class reemission.salib.distributions.Variable(name: str, distribution: ~reemission.salib.distributions.Distribution, fixed: bool = False, group: str | None = None, metadata: dict[str, ~typing.Any] = <factory>)[source]
Bases:
object
Represents a variable with a distribution, name, and optional metadata. This class is used to define model parameters and input parameters used in sensitivity analysis.
- name
Unique name of the variable.
- Type:
str
- distribution
Probability distribution associated with the variable.
- Type:
- group
Optional logical group (e.g. “inputs”, “parameters”).
- Type:
Optional[str]
- metadata
Arbitrary extra metadata for downstream use.
- Type:
dict[str, Any]
- cat_to_num(cat_values: Sequence[str]) Sequence[int] [source]
Convert categories to numbers if supported by the distribution, else return input. Catches NotImplementedError if the distribution does not support this conversion.
- distribution: Distribution
- fixed: bool = False
- group: str | None = None
- is_categorical() bool [source]
Check if the variable is categorical based on its distribution
- is_discrete() bool [source]
Check if the variable’s distribution is discrete
- is_fixed() bool [source]
Check if the variable is fixed (not sampled)
- is_uniform() bool [source]
Check if the variable’s distribution is uniform or discrete uniform
- metadata: dict[str, Any]
- name: str
- num_to_cat(num_values: Sequence[int]) Sequence[str] [source]
Convert numbers to categories if supported by the distribution, else return input. Catches NotImplementedError if the distribution does not support this conversion.
- to_dict() dict [source]
Present the variable to a dictionary representation.
Classes
Mixin for categorical conversion methods. |
|
|
Categorical histogram distribution for categorical variables |
|
Normal distribution for categorical variables This distribution is defined by a mean and standard deviation, and samples are drawn from a normal distribution with respect to the categories. |
|
Uniform distribution for categorical variables This distribution is defined by a set of categories and samples are drawn uniformly from these categories. |
|
Discrete histogram distribution for numerical variables. |
|
Discrete normal distribution for numerical variables . |
|
Discrete uniform distribution for numerical variables . |
Abstract base for parameterizations (std-dev or min/max). |
|
|
Enum for distribution types |
|
Standard (Gaussian) distribution . |
|
Uniform distribution supported by SALib and Sobol sampling . |
|
Represents a variable with a distribution, name, and optional metadata. |