Esempio n. 1
0
def test_basis2():
    # test orthonormality in Aitchison inner product
    b = basis(4)
    for i in range(len(b)):
        ii = inner(b[i], b[i])
        assert ii == pytest.approx(1.0)
        for j in range(i + 1, len(b)):
            ij = inner(b[i], b[j])
            assert ij == pytest.approx(0.0)
Esempio n. 2
0
def test_basis2():
    # test orthonormality in Aitchison inner product
    b = basis(4)
    for i in range(len(b)):
        ii = inner(b[i], b[i])
        assert_almost_equal(ii, 1.0)
        for j in range(i + 1, len(b)):
            ij = inner(b[i], b[j])
            assert_almost_equal(ij, 0.0)
Esempio n. 3
0
def test_basis2():
    # test orthonormality in Aitchison inner product
    b = basis(4)
    for i in range(len(b)):
        ii = inner(b[i], b[i])
        assert_almost_equal(ii, 1.0)
        for j in range(i+1, len(b)):
            ij = inner(b[i], b[j])
            assert_almost_equal(ij, 0.0)
Esempio n. 4
0
def test_inner():
    # 1D
    x = np.array([1 / 3.0, 2 / 3.0])
    y = np.array([1 / 4.0, 3 / 4.0])
    z = np.array([2 / 5.0, 3 / 5.0])

    xy_ = 0.79248125036057804
    xy = inner(x, y)
    yx = inner(y, x)
    assert xy_ == pytest.approx(xy)
    assert xy_ == pytest.approx(yx)

    yz_ = 0.46357181398555231
    yz = inner(y, z)
    zy = inner(z, y)
    assert yz_ == pytest.approx(yz)
    assert yz_ == pytest.approx(zy)

    xz_ = 0.29248125036057804
    xz = inner(x, z)
    zx = inner(z, x)
    assert xz_ == pytest.approx(xz)
    assert xz_ == pytest.approx(zx)

    # 2D with multiple rows
    xx = np.array([x, y, z])
    yy = np.array([y, z, x])
    xxyy = inner(xx, yy)
    xxyy_ = np.array([xy_, yz_, xz_])
    assert np.allclose(xxyy_, xxyy)

    # 2D with multiple rows in x and single row in y
    yy_ = 1.2560530643461303
    xx = np.array([x, y, z])
    yy = np.array([y])
    xxyy = inner(xx, yy)
    xxyy_ = np.array([xy_, yy_, yz_])
    assert np.allclose(xxyy_, xxyy)
    yyxx = inner(yy, xx)
    assert np.allclose(xxyy_, yyxx)

    # 2D with single rows
    x2d = np.atleast_2d(x)
    y2d = np.atleast_2d(y)
    xy2d = inner(x2d, y2d)
    xy2d_ = np.array([xy_])
    assert np.allclose(xy2d_, xy2d)
Esempio n. 5
0
def test_inner():
    # 1D
    x = np.array([1/3.0, 2/3.0])
    y = np.array([1/4.0, 3/4.0])
    z = np.array([2/5.0, 3/5.0])

    xy_ = 0.79248125036057804
    xy = inner(x, y)
    yx = inner(y, x)
    assert_almost_equal(xy_, xy)
    assert_almost_equal(xy_, yx)

    yz_ = 0.46357181398555231
    yz = inner(y, z)
    zy = inner(z, y)
    assert_almost_equal(yz_, yz)
    assert_almost_equal(yz_, zy)

    xz_ = 0.29248125036057804
    xz = inner(x, z)
    zx = inner(z, x)
    assert_almost_equal(xz_, xz)
    assert_almost_equal(xz_, zx)

    # 2D with multiple rows
    xx = np.array([x, y, z])
    yy = np.array([y, z, x])
    xxyy = inner(xx, yy)
    xxyy_ = np.array([xy_, yz_, xz_])
    assert_true(allclose(xxyy_, xxyy))

    # 2D with multiple rows in x and single row in y
    yy_ = 1.2560530643461303
    xx = np.array([x, y, z])
    yy = np.array([y])
    xxyy = inner(xx, yy)
    xxyy_ = np.array([xy_, yy_, yz_])
    assert_true(allclose(xxyy_, xxyy))
    yyxx = inner(yy, xx)
    assert_true(allclose(xxyy_, yyxx))

    # 2D with single rows
    x2d = np.atleast_2d(x)
    y2d = np.atleast_2d(y)
    xy2d = inner(x2d, y2d)
    xy2d_ = np.array([xy_])
    assert_true(allclose(xy2d_, xy2d))
Esempio n. 6
0
def test_equiv_inner2():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    clrx = clr(x)
    clry = clr(y)
    D = len(x)
    M = -1 * np.ones((D, D))
    M.flat[::D + 1] = D - 1

    z1 = inner(x, y)
    z2 = 1 / D * np.dot(np.dot(clrx, M), clry[:, np.newaxis])
    assert z1 == pytest.approx(z2[0])
Esempio n. 7
0
def test_equiv_inner2():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    clrx = clr(x)
    clry = clr(y)
    D = len(x)
    M = -1 * np.ones((D, D))
    M.flat[::D+1] = D - 1

    z1 = inner(x, y)
    z2 = 1/D * np.dot(np.dot(clrx, M), clry[:, np.newaxis])
    assert_almost_equal(z1, z2)
Esempio n. 8
0
def test_equiv_inner1():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_inner = inner(x, y)
    euclidean_inner = np.inner(ilr(x), ilr(y))
    assert aitchison_inner == pytest.approx(euclidean_inner)
Esempio n. 9
0
def test_equiv_inner1():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_inner = inner(x, y)
    euclidean_inner = np.inner(ilr(x), ilr(y))
    assert_almost_equal(aitchison_inner, euclidean_inner)
Esempio n. 10
0
def test_equiv_inner1():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_inner = inner(x, y)
    euclidean_inner = np.inner(ilr(x), ilr(y))
    assert_almost_equal(aitchison_inner, euclidean_inner)