Skip to main content
`Ctrl`+`K`

# skbio.stats.composition.clr_inv

skbio.stats.composition.clr_inv(mat, axis=-1, validate=True)

  Perform inverse centre log ratio (CLR) transformation.

  This function transforms compositions from the real space to Aitchison geometry. The \(clr^{-1}\) transform is both an isometry, and an isomorphism defined on the following spaces:

  \[clr^{-1}: U \rightarrow S^D\]

  where \(U= \{x :\sum\limits_{i=1}^D x = 0 \; \forall x \in \mathbb{R}^D\}\)

  This transformation is defined as follows:

  \[clr^{-1}(x) = C[\exp( x_1, \ldots, x_D)]\]

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

  Parameters:
    mat array_like of shape (…, n_components, …)

      A matrix of CLR-transformed data.

    axis int, optional

      Axis along which inverse CLR 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.

    validate: bool, optional

      Check if the matrix has been centered at 0. Violation will result in a warning rather than an error, for backward compatibility. Defaults to True.

      Added in version 0.7.0.

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

      Inverse CLR-transformed matrix.

  See also

  `clr`

  Notes

  Note

  This function supports the Python array API standard. Compatible array backends:

  Backend | CPU | GPU
  --- | --- | ---
  NumPy | ✓ | n/a
  CuPy | n/a | ✓
  PyTorch | ✓ | ✓
  JAX | ✓ | ✓
  Dask | ✓ | n/a

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

  Examples

      >>> import numpy as np
      >>> from skbio.stats.composition import clr_inv
      >>> x = np.array([.1, .3, .4, .2])
      >>> clr_inv(x)
      array([ 0.21383822,  0.26118259,  0.28865141,  0.23632778])