Skip to content
class

StickBreakingTransform

extendsTransform
StickBreakingTransform()

Logistic stick-breaking bijection RK−1→ΔK−1\mathbb{R}^{K-1} \to \Delta^{K-1}.

A true bijection between unconstrained (K−1)(K-1)-vectors and the KK-simplex (i.e. one extra dimension is broken off as the residual stick). Unlike SoftmaxTransform it has the correct dimensionality and a tractable log-Jacobian determinant, making it the preferred choice for normalising flows over probability vectors and for unconstrained reparameterisations of lucid.distributions.Dirichlet priors. event_dim = 1.

Notes

Forward "stick breaking" (with zk=σ(xk−log⁡(K−k))z_k = \sigma(x_k - \log(K-k))):

yk=zk∏j<k(1−zj),yK−1=∏j=0K−2(1−zj)y_k = z_k \prod_{j < k}(1 - z_j), \quad y_{K-1} = \prod_{j=0}^{K-2}(1 - z_j)

The last component is the residual stick remaining after the first K−1K - 1 breaks. Each yk>0y_k > 0 and ∑kyk=1\sum_k y_k = 1 by construction.

Inverse (back-solve the stick lengths):

zk=yk1−∑j<kyj,xk=logit(zk)+log⁡(K−k)z_k = \frac{y_k}{1 - \sum_{j < k} y_j}, \qquad x_k = \mathrm{logit}(z_k) + \log(K - k)

Log Jacobian determinant:

log⁡∣det⁡J∣=∑k=0K−2[log⁡yk+log⁡(1−∑j<kyj)+log⁡(1−zk)]\log|\det J| = \sum_{k=0}^{K-2} \bigl[\log y_k + \log(1 - \textstyle\sum_{j < k} y_j) + \log(1 - z_k)\bigr]

where the −log⁡(K−k)-\log(K-k) shifts ensure the uniform Dirichlet corresponds to x=0\mathbf{x} = \mathbf{0}.

Examples

>>> import lucid
>>> from lucid.distributions.transforms import StickBreakingTransform
>>> T = StickBreakingTransform()
>>> y = T(lucid.tensor([0.0, 0.0]))  # maps to a Dirichlet(1,1,1) sample
>>> y.sum()
tensor(1.)

Used by 3

Instance methods

3
fn

forward_shape

→tuple[int, ...]
forward_shape(shape: tuple[int, ...])

Extend the trailing axis by 1 for the residual stick.

fn

inverse_shape

→tuple[int, ...]
inverse_shape(shape: tuple[int, ...])

Drop the residual stick axis by 1.

fn

log_abs_det_jacobian

→Tensor
log_abs_det_jacobian(x: Tensor, y: Tensor)

Standard simplex-to-RK−1\mathbb{R}^{K-1} log-Jacobian.

log⁡∣det⁡J∣=∑k[log⁡yk+log⁡ ⁣(1−zk)]\log|\det J| = \sum_k \bigl[\log y_k + \log\!\bigl(1 - z_k\bigr)\bigr].

Parameters

Unconstrained (K−1)(K-1)-vectors.
Corresponding KK-simplex points (output of the forward map).

Returns

Tensor

Per-sample log-Jacobian.