probly.representation.credal_set.array¶
Classes representing credal sets.
Classes
A credal set of predictions stored in a numpy array. |
|
|
A convex credal set defined by the convex hull of distributions stored in a numpy array. |
|
A discrete credal set over a finite set of distributions stored in a numpy array. |
|
A credal set defined by a nominal distribution and a distance radius (L1/Total Variation). |
|
A credal set defined by probability intervals over outcomes. |
|
A singleton credal set containing exactly one distribution stored in a numpy array. |
- class probly.representation.credal_set.array.ArrayCategoricalCredalSet[source]¶
Bases:
CategoricalCredalSet[ndarray]A credal set of predictions stored in a numpy array.
- abstractmethod classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
Create a credal set from an ArraySample.
- Parameters:
sample (ArraySample[ndarray]) – The sample to create the credal set from.
distribution_axis (int) – The axis in each sample containing the categorical probabilities.
- Returns:
The created credal set.
- Return type:
- lower()¶
Compute the lower envelope of the credal set.
- Return type:
T
- upper()¶
Compute the upper envelope of the credal set.
- Return type:
T
- type: CredalSetType = 'categorical'¶
- class probly.representation.credal_set.array.ArrayConvexCredalSet(array)[source]¶
Bases:
ArrayCategoricalCredalSet,ConvexCredalSet[ndarray]A convex credal set defined by the convex hull of distributions stored in a numpy array.
Internally, this is represented exactly like a discrete credal set: an array of shape (…, num_vertices, num_classes), where the distributions are the extreme points (vertices) of the polytope.
- Parameters:
array (np.ndarray)
- classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
- Parameters:
sample (ArraySample[ndarray])
distribution_axis (int)
- Return type:
- classmethod from_sample(sample, distribution_axis=-1)¶
- lower()[source]¶
Compute the lower envelope of the convex credal set.
For a convex hull, the lower envelope is the element-wise minimum of its vertices.
- Return type:
- upper()[source]¶
Compute the upper envelope of the convex credal set.
For a convex hull, the upper envelope is the element-wise maximum of its vertices.
- Return type:
- array: np.ndarray¶
- type: CredalSetType = 'categorical'¶
- class probly.representation.credal_set.array.ArrayDiscreteCredalSet(array)[source]¶
Bases:
ArrayCategoricalCredalSet,DiscreteCredalSet[ndarray]A discrete credal set over a finite set of distributions stored in a numpy array.
Internall, a discrete credal set is represented as a numpy array of shape (…, num_members, num_classes)
- Parameters:
array (np.ndarray)
- classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
- Parameters:
sample (ArraySample[ndarray])
distribution_axis (int)
- Return type:
- classmethod from_sample(sample, distribution_axis=-1)¶
- array: np.ndarray¶
- type: CredalSetType = 'categorical'¶
- class probly.representation.credal_set.array.ArrayDistanceBasedCredalSet(nominal, radius)[source]¶
Bases:
ArrayCategoricalCredalSet,DistanceBasedCredalSet[ndarray]A credal set defined by a nominal distribution and a distance radius (L1/Total Variation).
The set contains all distributions P such that distance(P, nominal) <= radius. Internally, the nominal distribution is stored as a numpy array of shape (…, num_classes). The radius is stored as a float or numpy array.
- Parameters:
nominal (np.ndarray)
radius (float | np.ndarray)
- classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
Create a DistanceBasedCredalSet from an ArraySample.
This calculates the mean of the samples as the nominal distribution. The radius is set to the maximum Total Variation distance between any sample and the mean, ensuring the credal set covers all observed samples.
- Parameters:
sample (ArraySample[ndarray])
distribution_axis (int)
- Return type:
- classmethod from_sample(sample, distribution_axis=-1)¶
- lower()[source]¶
Compute the lower envelope of the credal set.
For L1/TV distance, the tightest element-wise lower bound is max(0, nominal - radius).
- Return type:
- upper()[source]¶
Compute the upper envelope of the credal set.
For L1/TV distance, the tightest element-wise upper bound is min(1, nominal + radius).
- Return type:
- nominal: np.ndarray¶
- type: CredalSetType = 'categorical'¶
- class probly.representation.credal_set.array.ArrayProbabilityIntervals(lower_bounds, upper_bounds)[source]¶
Bases:
ArrayCategoricalCredalSet,ProbabilityIntervalsCredalSet[ndarray]A credal set defined by probability intervals over outcomes.
This represents uncertainty through lower and upper probability bounds for each class. Each bound is stored as a seperate numpy array of shape (…, num_classes).
- Parameters:
lower_bounds (np.ndarray)
upper_bounds (np.ndarray)
- classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
Create probability intervals from a sample by computing min/max bounds.
- Parameters:
sample (ArraySample[ndarray]) – The sample to extract intervals from.
distribution_axis (int) – Which axis contains the categorical probabilities.
- Returns:
A new ArrayProbabilityIntervals instance.
- Return type:
- classmethod from_sample(sample, distribution_axis=-1)¶
- copy()[source]¶
Create a copy of the intervals.
- Returns:
A new ArrayProbabilityIntervals with copied data.
- Return type:
- width()[source]¶
Compute the width of each probability interval.
- Returns:
Array of interval widths for each class.
- Return type:
- lower_bounds: np.ndarray¶
- type: CredalSetType = 'categorical'¶
- upper_bounds: np.ndarray¶
- class probly.representation.credal_set.array.ArraySingletonCredalSet(array)[source]¶
Bases:
ArrayCategoricalCredalSet,SingletonCredalSet[ndarray]A singleton credal set containing exactly one distribution stored in a numpy array.
Internally, this is represented as a numpy array of shape (…, num_classes). Unlike DiscreteCredalSet, it does not have a ‘members’ dimension.
- Parameters:
array (np.ndarray)
- classmethod from_array_sample(sample, distribution_axis=-1)[source]¶
Create a SingletonCredalSet from an ArraySample by averaging the samples.
This method calculates the mean of the samples to produce a single precise distribution (singleton).
- Parameters:
sample (ArraySample[ndarray])
distribution_axis (int)
- Return type:
- classmethod from_sample(sample, distribution_axis=-1)¶
- lower()[source]¶
Compute the lower envelope of the credal set.
For a singleton set {P}, lower(P) = P.
- Return type:
- upper()[source]¶
Compute the upper envelope of the credal set.
For a singleton set {P}, upper(P) = P.
- Return type:
- array: np.ndarray¶
- type: CredalSetType = 'categorical'¶