@@ -442,14 +442,40 @@ def compactspace(scale, n):
442442
443443def to_simplex (y ):
444444 r"""
445- Interprets the last dimension of ``y`` as stick breaking lengths
446- in inverse-logit space and returns a non-negative array of
447- the same shape where the last dimension always sums to unity;
448- simplices.
449-
450- Inverse to ``from_simplex``.
451-
452- :param np.ndarray: Array of inverse-logit space stick breaking
445+ Interprets the last index of ``y`` as stick breaking fractions
446+ in logit space and returns a non-negative array of
447+ the same shape where the last dimension always sums to unity.
448+
449+ A unit simplex is a list of non-negative numbers :math:`(x_1,...,x_K)`
450+ that sum to one, :math:`\sum_{k=1}^K x_k=1`, for example, the
451+ probabilities of an K-sided die.
452+ It is sometimes desireable to parameterize this object with variables
453+ that are unconstrained and "decorrelated".
454+ To this end, we imagine :math:`\vec{x}` as a partition of the unit
455+ stick :math:`[0,1]` with :math:`K-1` break points between
456+ :math:`K` successive intervals of respective lengths :math:`(x_1,...,x_K)`.
457+ Instead of storing the interval lengths, we start from the left-most break
458+ point and iteratively store the breaking fractions, :math:`z_k`,
459+ of the remaining stick.
460+ This gives the formula
461+ :math:`z_k=x_k / (1-\sum_{k'=1}^{k-1}x_k)` with the convention
462+ :math:`x_0:=0`,
463+ which has an inverse formula :math:`x_k = z_k(1-z_{k-1})\cdots(1-z_1)`.
464+ Note that :math:`z_K=1` since the last stick is not broken; this is the
465+ result of the redundant information imposed by :math:`\sum_{k=1}^K x_k=1`.
466+ To unbound the parameters :math:`z_k` into the real line,
467+ we pass through the logit function,
468+ :math:`\operatorname{logit}(p)=\log\frac{p}{1-p}`,
469+ to end up with the parameterization
470+ :math:`y_k=\operatorname{logit}(z_k)+\log(K-k)`, with the convention
471+ :math:`y_K=0`.
472+ The shift by :math:`\log(K-k)` is largely asthetic and causes the
473+ uniform simplex :math:`\vec{x}=(1/K,1/K,...,1/K)` to be mapped to
474+ :math:`\vec{x}=(0,0,...,0)`.
475+
476+ Inverse to :func:`from_simplex`.
477+
478+ :param np.ndarray: Array of logit space stick breaking
453479 fractions along the last index.
454480
455481 :rtype: ``np.ndarray``
@@ -464,11 +490,10 @@ def to_simplex(y):
464490
465491def from_simplex (x ):
466492 r"""
467- The last dimension of x should be unit simplices and this
468- function turns them into stick breaking fractions in
469- inverse-logit space.
493+ Inteprets the last index of x as unit simplices and returns a
494+ real array of the sampe shape in logit space.
470495
471- Inverse to `` to_simplex`` .
496+ Inverse to :func:` to_simplex` ; see that function for more details .
472497
473498 :param np.ndarray: Array of unit simplices along the last index.
474499
0 commit comments