NumpyProbabilityBernoulliDistribution

class probly.representation.distribution.numpy_bernoulli.NumpyProbabilityBernoulliDistribution(array: ndarray)[source]

Bases: NumpyBernoulliDistribution[NumpyProbabilityBernoulliDistribution], NumpyProbabilityCategoricalDistribution[NumpyProbabilityBernoulliDistribution]

A Bernoulli distribution represented by the probability of class 1.

property T: ShapeResultT

The transposed version of the underlying array.

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

Cast each protected field using ndarray.astype’s casting and layout options.

copy(order: Order = 'C') → OwnerT[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.

property log_probabilities: ndarray

Get the log probabilities of the categorical distribution.

property logits: ndarray

Get logits of the categorical distribution.

property mT: ShapeResultT

The transposed version of the underlying array.

property ndim: int

Number of dimensions.

property num_classes: int

Get the fixed number of Bernoulli classes.

permitted_functions = {<function average>, <function mean>}
permitted_ufuncs = {}
primary_protected_name = 'array'
property probabilities: ndarray

Get the probabilities of the categorical distribution.

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

Protected trailing shape of the primary field.

protected_value() → NumpyProtectedValue[source]

Return the primary protected value.

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

Read effective values, with optional NumPy function or ufunc permissions.

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

Return a copy with reshaped protected values.

sample(num_samples: int = 1, rng: Generator | None = None) → NumpySample[ndarray][source]

Sample from the categorical distribution (NumPy backend).

property shape: tuple[int, ...]

Read the logical shape without collecting fields unless all broadcast.

property size: int

Number of elements in the array.

to_categorical() → NumpyProbabilityCategoricalDistribution[source]

Convert to a two-class categorical distribution.

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

Move the array to a device.

transpose(*axes: int | Sequence[int] | None) → ShapeResultT[source]

Return a transposed version of the NumpySample.

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 NumpySample.

type = 'bernoulli'
property unnormalized_probabilities: ndarray

Get unnormalized probabilities of the categorical distribution.

validate() → None[source]

Raise if effective fields have insufficient rank or incompatible batches.

Call explicitly, or from __post_init__ to check dataclass construction. Fields owned by initialization (init=False) are excluded.

with_protected_values(values: dict[str, Any], func: Callable | None = None) → OwnerT | NumpyCategoricalDistribution | np.ndarray[source]

Return a copy with a replaced primary protected value.