def test_subspace(self):
     for n in range(2, 7):
         H_full = helmert(n, full=True)
         H_partial = helmert(n)
         for U in H_full[1:, :].T, H_partial.T:
             C = np.eye(n) - np.ones((n, n)) / n
             assert_allclose(U.dot(U.T), C)
             assert_allclose(U.T.dot(U), np.eye(n-1), atol=1e-12)
Example #2
0
 def test_subspace(self):
     for n in range(2, 7):
         H_full = helmert(n, full=True)
         H_partial = helmert(n)
         for U in H_full[1:, :].T, H_partial.T:
             C = np.eye(n) - np.full((n, n), 1 / n)
             assert_allclose(U.dot(U.T), C)
             assert_allclose(U.T.dot(U), np.eye(n - 1), atol=1e-12)
Example #3
0
def inverse_ilr_transformation(data):
    """Inverse isometric logratio transformation (not vectorized).

    Parameters
    ----------
    data : 2d numpy array, shape [n_samples, n_coordinates]
        Isometric log-ratio transformed coordinates in real space.

    Returns
    -------
    out : 2d numpy array, shape [n_samples, n_coordinates+1]
        Barycentric coordinates (closed) in simplex space.

    Reference
    ---------
    [1] Pawlowsky-Glahn, V., Egozcue, J. J., & Tolosana-Delgado, R.
        (2015). Modelling and Analysis of Compositional Data, pg. 37.
        Chichester, UK: John Wiley & Sons, Ltd.
        DOI: 10.1002/9781119003144

    """
    dims = data.shape
    out = np.zeros((dims[0], dims[1] + 1))
    helmertian = helmert(dims[1] + 1)
    for i in range(data.shape[0]):
        out[i, :] = np.exp(np.dot(data[i, :], helmertian))
    return closure(out)
Example #4
0
 def compositional_transform(self, add_pseudocount:bool=False):
     """calculated the three Aitchison geometry transforms for the Ab counts.
     - alr uses the IgG1 counts as universal reference
     - ilr contrasts are based on the SVD of clr
     
     if add_pseudocount is set to true add 1 to prevent zero division, otherwise
     cells with zero counts in the denominator create inf and have to be filtered
     before downstream analysis, e.g.:
         clr_filter = np.isfinite(clr).all(axis=1)
         clr = clr[clr_filter,:]"""
     if add_pseudocount:
         self.clr_data = np.log((1+self.andat_raw.X)/gmean(self.andat_raw.X+1, axis=1).reshape(-1,1))
         self.alr_data = np.log((1+self.andat_raw.X)/(self.andat_raw.X[:,-1]+1).reshape(-1,1))
         
         U,s,Vt = np.linalg.svd(self.clr_data, full_matrices=False)
         self.ilr_data = np.dot(U*s,helmert(len(s)).T)
     else:
         self.clr_data = np.log(self.andat_raw.X/gmean(self.andat_raw.X, axis=1).reshape(-1,1))
         self.alr_data = np.log(self.andat_raw.X/(self.andat_raw.X[:,-1].reshape(-1,1)))
         
         finite_clr = np.isfinite(self.clr_data).all(axis=1)
         U,s,Vt = np.linalg.svd(self.clr_data[finite_clr,:], full_matrices=False)
         self.ilr_data = np.dot(U*s,helmert(len(s)).T)
     return
Example #5
0
def inverse_ilr_transformation(data):
    """Inverse isometric logratio transformation (not vectorized).
    Adapted from https://github.com/ofgulban/compoda.

    Parameters
    ----------
    data : 2d numpy array, shape [n_samples, n_coordinates]
        Isometric log-ratio transformed coordinates in real space.

    Returns
    -------
    out : 2d numpy array, shape [n_samples, n_coordinates+1]
        Barycentric coordinates (closed) in simplex space.

    Reference
    ---------
    [1] Pawlowsky-Glahn, V., Egozcue, J. J., & Tolosana-Delgado, R.
        (2015). Modelling and Analysis of Compositional Data, pg. 37.
        Chichester, UK: John Wiley & Sons, Ltd.
        DOI: 10.1002/9781119003144
    """

    return closure(
        np.exp(np.einsum("ij,jk->ik", data, -helmert(data.shape[1] + 1))))
Example #6
0
 def time_helmert(self, size):
     sl.helmert(size)
Example #7
0
 def test_orthogonality(self):
     for n in range(1, 7):
         H = helmert(n, full=True)
         Id = np.eye(n)
         assert_allclose(H.dot(H.T), Id, atol=1e-12)
         assert_allclose(H.T.dot(H), Id, atol=1e-12)
 def test_orthogonality(self):
     for n in range(1, 7):
         H = helmert(n, full=True)
         Id = np.eye(n)
         assert_allclose(H.dot(H.T), Id, atol=1e-12)
         assert_allclose(H.T.dot(H), Id, atol=1e-12)
Example #9
0
 def time_helmert(self, size):
     sl.helmert(size)
Example #10
0
 def __init__(self, n):
     self.A = helmert(n, full=False)
     self.tA = theano.shared(self.A)