probly.representation.distribution.array_dirichlet.ArrayDirichletDistribution

class probly.representation.distribution.array_dirichlet.ArrayDirichletDistribution(alphas: ndarray = <property object>)[source]

Bases: ArrayAxisProtected[ndarray], DirichletDistribution[ArrayCategoricalDistribution]

A Dirichlet distribution stored as a numpy array.

Shape: (…, num_classes) The last axis represents the category dimension.

property T: Self

The transposed version of the underlying array.

alphas: np.ndarray
astype(dtype: DTypeLike, order: Order = 'K', casting: Literal['no', 'equiv', 'safe', 'same_kind', 'unsafe'] = 'unsafe', subok: bool = True, copy: bool = True) Self[source]

Copy of the array, cast to a specified type.

copy(order: Order = 'C') Self[source]

Return a copy of the array.

property device: str

Device of the array.

property dtype: dtype

Data type of the array.

entropy() ArrayLike[source]

Compute entropy.

property flags: ArrayFlagsLike

The flags of the array.

classmethod from_array(alphas: np.ndarray | list, dtype: DTypeLike | None = None) Self[source]

Create a Dirichlet distribution from an array or list.

property mT: Self

The transposed version of the underlying array.

property mean: ArrayCategoricalDistribution

Return the mean of the Dirichlet distribution.

property ndim: int

Number of dimensions.

permitted_functions: ClassVar[set[Callable]] = {<function average>, <function mean>, <function sum>}
permitted_ufuncs: ClassVar[dict[np.ufunc, list[str]]] = {<ufunc 'add'>: ['__call__'], <ufunc 'subtract'>: ['__call__']}
classmethod primary_protected_name() str[source]

Return the first protected field (dict order).

protected_axes: ClassVar[dict[str, int]] = {'alphas': 1}
property protected_shape: tuple[int, ...]

Protected trailing shape of the primary field.

protected_value() ArrayProtectedValue[source]

Return the primary protected value.

protected_values(func: Callable | None = None, method: str | None = None) dict[str, ArrayProtectedValue] | None[source]

Return all protected field values.

The values are preserved as-is and are not coerced to np.ndarray. Optionally takes the function that triggered the call for context. This can be used to conditionally modify the returned values or prevent them from being accessed.

reshape(*shape: int | tuple[int, ...], order: str = 'C', copy: bool | None = None) Self[source]

Return a copy with reshaped protected values.

sample(num_samples: int = 1, rng: Generator | None = None) ArraySample[ArrayCategoricalDistribution][source]

Sample from the Dirichlet distribution (NumPy backend).

property shape: tuple[int, ...]

Shape of the array.

property size: int

Number of elements in the array.

to_device(device: Any, /, *, stream: Any = None) Self[source]

Move the array to a device.

transpose(*axes: int | None) Self[source]

Return a transposed version of the ArraySample.

This method implicitly also provides full axis tracking support for - np.moveaxis - np.rollaxis Those functions call out to transpose methods for custom array types.

Parameters:

axes – The axes to transpose.

Returns:

A transposed version of the ArraySample.

type = 'dirichlet'
with_protected_value(value: ArrayProtectedValue) Self[source]

Return a copy with a replaced primary protected value.

with_protected_values(values: dict[str, ArrayProtectedValue]) Self[source]

Return a copy with updated protected field values.