probly.representation.credal_set.array

Classes representing credal sets.

Classes

ArrayCategoricalCredalSet()

A credal set of predictions stored in a numpy array.

ArrayConvexCredalSet(array)

A convex credal set defined by the convex hull of distributions stored in a numpy array.

ArrayDiscreteCredalSet(array)

A discrete credal set over a finite set of distributions stored in a numpy array.

ArrayDistanceBasedCredalSet(nominal, radius)

A credal set defined by a nominal distribution and a distance radius (L1/Total Variation).

ArrayProbabilityIntervals(lower_bounds, ...)

A credal set defined by probability intervals over outcomes.

ArraySingletonCredalSet(array)

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:

Self

classmethod from_sample(sample, distribution_axis=-1)[source]
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

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:
Return type:

Self

classmethod from_sample(sample, distribution_axis=-1)
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

copy()[source]

Create a copy of the credal set.

Return type:

Self

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:

ndarray

to_device(device)[source]

Move the underlying array to the specified device.

Parameters:

device (Literal['cpu'])

Return type:

Self

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:

ndarray

array: np.ndarray
property device: str

Return the device of the credal set array.

property dtype: dtype

Return the data type of the credal set array.

property ndim: int

Return the number of dimensions of the credal set array.

property shape: tuple[int, ...]

Return the shape of the credal set array.

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:
Return type:

Self

classmethod from_sample(sample, distribution_axis=-1)
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

copy()[source]

Create a copy of the ArraySample.

Returns:

A copy of the ArraySample.

Return type:

Self

lower()[source]

Compute the lower envelope of the credal set.

Return type:

ndarray

to_device(device)[source]

Move the underlying array to the specified device.

Parameters:

device (Literal['cpu']) – The target device.

Returns:

A new ArrayDiscreteCredalSet on the specified device.

Return type:

Self

upper()[source]

Compute the upper envelope of the credal set.

Return type:

ndarray

array: np.ndarray
property device: str

Return the device of the credal set array.

property dtype: dtype

Return the data type of the credal set array.

property ndim: int

Return the number of dimensions of the credal set array.

property shape: tuple[int, ...]

Return the shape of the credal set array.

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:
Return type:

Self

classmethod from_sample(sample, distribution_axis=-1)
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

copy()[source]

Create a copy of the ArrayDistanceBasedCredalSet.

Return type:

Self

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:

ndarray

to_device(device)[source]

Move the underlying array to the specified device.

Parameters:

device (Literal['cpu'])

Return type:

Self

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:

ndarray

property device: str

Return the device of the nominal array.

property dtype: dtype

Return the data type of the nominal array.

property ndim: int

Return the number of dimensions of the credal set array.

nominal: np.ndarray
radius: float | np.ndarray
property shape: tuple[int, ...]

Return the shape of the credal set array (batch dimensions).

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:

Self

classmethod from_sample(sample, distribution_axis=-1)
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

contains(probabilities)[source]

Check if given probabilities fall within the intervals.

Parameters:

probabilities (ndarray) – Probability distributions to check, shape (…, num_classes).

Returns:

Boolean array indicating whether each probability is contained.

Return type:

ndarray

copy()[source]

Create a copy of the intervals.

Returns:

A new ArrayProbabilityIntervals with copied data.

Return type:

Self

lower()[source]

Get the lower probability bounds for each class.

Return type:

ndarray

to_device(device)[source]

Move the intervals to a specified device.

Parameters:

device (Literal['cpu']) – Target device.

Returns:

A new ArrayProbabilityIntervals on the specified device.

Return type:

Self

upper()[source]

Get the upper probability bounds for each class.

Return type:

ndarray

width()[source]

Compute the width of each probability interval.

Returns:

Array of interval widths for each class.

Return type:

ndarray

property device: str

Return the device where the bounds are stored.

property dtype: dtype

Return the data type of the bounds.

lower_bounds: np.ndarray
property ndim: int

Return the number of dimensions (excluding the class dimensions).

property num_classes: int

Return the number of classes.

property shape: tuple[int, ...]

Return the shape (excluding the class dimensions).

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:
Return type:

Self

classmethod from_sample(sample, distribution_axis=-1)
Parameters:
  • sample (Sample[np.ndarray])

  • distribution_axis (int)

Return type:

Self

copy()[source]

Create a copy of the ArraySingletonCredalSet.

Return type:

Self

lower()[source]

Compute the lower envelope of the credal set.

For a singleton set {P}, lower(P) = P.

Return type:

ndarray

to_device(device)[source]

Move the underlying array to the specified device.

Parameters:

device (Literal['cpu'])

Return type:

Self

upper()[source]

Compute the upper envelope of the credal set.

For a singleton set {P}, upper(P) = P.

Return type:

ndarray

array: np.ndarray
property device: str

Return the device of the credal set array.

property dtype: dtype

Return the data type of the credal set array.

property ndim: int

Return the number of dimensions of the credal set array.

property shape: tuple[int, ...]

Return the shape of the credal set array (batch dimensions).

type: CredalSetType = 'categorical'