示例#1
0
def test_ilr():
    # 1D
    x = np.array([1, 2, 3, 4])
    lg = log2([(x[0])**(1 / 1) / x[1], (x[0] * x[1])**(1 / 2) / x[2],
               (x[0] * x[1] * x[2])**(1 / 3) / x[3]])
    coeff = np.sqrt([1 / 2, 2 / 3, 3 / 4])
    ilrx_ = coeff * lg
    ilrx = ilr(x)

    assert ilrx.shape == ilrx_.shape
    for i, j in zip(ilrx, ilrx_):
        assert i == pytest.approx(j)

    # 2D with multiple rows
    x = np.array([1, 2, 3, 4])
    y = np.array([2, 3, 4, 5])
    ilrx_ = np.array([-0.70710678, -0.88586817, -0.98583641])
    ilry_ = np.array([-0.41363095, -0.57768664, -0.68728405])
    xy = np.array([x, y])
    ilrxy_ = np.array([ilrx_, ilry_])
    ilrxy = ilr(xy)

    assert ilrxy.shape == ilrxy_.shape
    for i, j in zip(ilrxy.ravel(), ilrxy_.ravel()):
        assert i == pytest.approx(j)

    # 2D with single rows
    xy = np.array([x])
    ilrxy_ = np.array([ilrx_])
    ilrxy = ilr(xy)

    assert ilrxy.shape == ilrxy_.shape
    for i, j in zip(ilrxy.ravel(), ilrxy_.ravel()):
        assert i == pytest.approx(j)
示例#2
0
def test_ilr():
    # 1D
    x = np.array([1, 2, 3, 4])
    lg = log2([(x[0]              )**(1/1) / x[1],
               (x[0] * x[1]       )**(1/2) / x[2],
               (x[0] * x[1] * x[2])**(1/3) / x[3]])
    coeff = np.sqrt([1/2, 2/3, 3/4])
    ilrx_ = coeff * lg
    ilrx = ilr(x)

    assert_equal(ilrx.shape, ilrx_.shape)
    for i, j in zip(ilrx, ilrx_):
        assert_almost_equal(i, j)

    # 2D with multiple rows
    x = np.array([1, 2, 3, 4])
    y = np.array([2, 3, 4, 5])
    ilrx_ = np.array([-0.70710678, -0.88586817, -0.98583641])
    ilry_ = np.array([-0.41363095, -0.57768664, -0.68728405])
    xy = np.array([x, y])
    ilrxy_ = np.array([ilrx_, ilry_])
    ilrxy = ilr(xy)

    assert_equal(ilrxy.shape, ilrxy_.shape)
    for i, j in zip(ilrxy.ravel(), ilrxy_.ravel()):
        assert_almost_equal(i, j)

    # 2D with single rows
    xy = np.array([x])
    ilrxy_ = np.array([ilrx_])
    ilrxy = ilr(xy)

    assert_equal(ilrxy.shape, ilrxy_.shape)
    for i, j in zip(ilrxy.ravel(), ilrxy_.ravel()):
        assert_almost_equal(i, j)
示例#3
0
def test_ilr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert x.shape == y.shape
    assert np.allclose(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert x.shape == y.shape
    assert np.allclose(x, y)
示例#4
0
def test_ilr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)
示例#5
0
def test_ilr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_ilr = ilr(x)
    y = ilr_inv(x_ilr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)
示例#6
0
def test_equiv_dist():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_dist = dist(x, y)
    euclidean_dist = np.linalg.norm(ilr(x) - ilr(y))
    assert aitchison_dist == pytest.approx(euclidean_dist)
示例#7
0
def test_equiv_norm():
    x = np.array([1, 2, 3, 4])
    aitchison_norm = norm(x)
    euclidean_norm = np.linalg.norm(ilr(x))
    assert aitchison_norm == pytest.approx(euclidean_norm)
示例#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)
示例#9
0
def test_equiv_dist():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_dist = dist(x, y)
    euclidean_dist = np.linalg.norm(ilr(x) - ilr(y))
    assert_almost_equal(aitchison_dist, euclidean_dist)
示例#10
0
def test_equiv_norm():
    x = np.array([1, 2, 3, 4])
    aitchison_norm = norm(x)
    euclidean_norm = np.linalg.norm(ilr(x))
    assert_almost_equal(aitchison_norm, euclidean_norm)
示例#11
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)
示例#12
0
def test_equiv_dist():
    x = np.array([1, 2, 3, 4])
    y = np.array([3, 5, 1, 1])
    aitchison_dist = dist(x, y)
    euclidean_dist = np.linalg.norm(ilr(x)-ilr(y))
    assert_almost_equal(aitchison_dist, euclidean_dist)
示例#13
0
def test_equiv_norm():
    x = np.array([1, 2, 3, 4])
    aitchison_norm = norm(x)
    euclidean_norm = np.linalg.norm(ilr(x))
    assert_almost_equal(aitchison_norm, euclidean_norm)
示例#14
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)