AsSimplex#

class bayesflow.adapters.transforms.AsSimplex(*, axis: int = -1, method: str = 'default')[source]#

Bases: ElementwiseTransform

Constrains neural network predictions of a data variable to a unit simplex, so that the constrained representation is non-negative and sums to one along the given axis.

Parameters:
axisint, optional

The axis of the simplex-constrained data along which values sum to one over all K elements. The corresponding unconstrained representation has a size of K-1 along this axis.

methodstr, optional

Method by which to transform between the K dimensional simplex space and the K-1 dimensional unconstrained space. - “default” / “simplex”: sum-to-zero (orthogonal basis) transform followed by a softmax transform. Plain softmax is not invertible (shifting all values by a constant results in the same inverse). The sum-to-zero removes this issue. - “stick”: an invertible stick-breaking logistic transform.

Examples

>>> adapter = bf.Adapter().as_simplex("probs")
get_config() → dict[source]#
forward(data: Tensor, **kwargs) → Tensor[source]#
inverse(data: Tensor, **kwargs) → Tensor[source]#
log_det_jac(data: Tensor, inverse: bool = False, **kwargs) → Tensor[source]#
__call__(data: Tensor, inverse: bool = False, **kwargs) → Tensor#

Call self as a function.

classmethod from_config(config: dict, custom_objects=None)#