skbio.stats.composition.alr_inv#

skbio.stats.composition.alr_inv(mat, ref_idx=0, axis=-1)[source]#

Perform inverse additive log ratio (ALR) transform.

This function transforms compositions from the non-isometric real space of ALRs to Aitchison geometry.

\[alr^{-1}: \mathbb{R}^{D-1} \rightarrow S^D\]

The inverse ALR transformation is defined as follows:

\[alr^{-1}(x) = C[exp([y_1, y_2, ..., y_{D-1}, 0])]\]

where \(C[x]\) is the closure operation defined as

\[C[x] = \left[\frac{x_1}{\sum_{i=1}^{D} x_i},\ldots, \frac{x_D}{\sum_{i=1}^{D} x_i} \right]\]

for some \(D\) dimensional real vector \(x\) and \(D\) is the number of components for every composition.

Changed in version 0.7.0: The function now works on any dimension in arrays of any number of dimensions.

Parameters:
matarray_like of shape (…, n_components - 1, …)

A matrix of ALR-transformed data.

ref_idxint, optional

Index on the target axis where the reference composition (denominator) will be inserted. Default is 0 (the first position).

Changed in version 0.7.0: Renamed from denominator_idx. The old name is kept as an alias.

axisint, optional

Axis along which inverse ALR transformation will be performed. Each vector on this axis is considered as a CLR-transformed composition. Default is the last axis (-1).

Added in version 0.7.0.

Returns:
ndarray of shape (…, n_components, …)

Inverse ALR-transformed matrix or vector where rows sum to 1.

See also

alr

Notes

The output of alr_inv is guaranteed to have each composition sum to 1. But this property isn’t required for the input for alr. Therefore, alr_inv does not completely invert alr. Instead, alr_inv(clr(mat)) and closure(mat) are equal.

Examples

>>> import numpy as np
>>> from skbio.stats.composition import alr, alr_inv
>>> x = np.array([.1, .3, .4, .2])
>>> alr_inv(alr(x))
array([ 0.1,  0.3,  0.4,  0.2])