Esempio n. 1
0
def test_clr_prop():
    x1 = np.array([1, 2, 3, 4])
    x2 = np.array([3, 5, 1, 1])
    a1, a2 = 0.3, 0.9

    z1 = clr(perturbation(power(x1, a1), power(x2, a2)))
    z2 = a1 * clr(x1) + a2 * clr(x2)

    assert np.allclose(z1, z2)
Esempio n. 2
0
def test_clr_prop():
    x1 = np.array([1, 2, 3, 4])
    x2 = np.array([3, 5, 1, 1])
    a1, a2 = 0.3, 0.9

    z1 = clr(perturbation(power(x1, a1), power(x2, a2)))
    z2 = a1 * clr(x1) + a2 * clr(x2)

    assert_almost_equal_array(z1, z2)
Esempio n. 3
0
def test_clr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert x.shape == y.shape
    assert np.allclose(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert x.shape == y.shape
    assert np.allclose(x, y)
Esempio n. 4
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. 5
0
def test_clr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)
Esempio n. 6
0
def test_clr_inv():
    x = np.array([1, 2, 3, 4]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)

    x = np.array([[1, 2, 3, 4], [2, 2, 2, 4]]) / 10
    x_clr = clr(x)
    y = clr_inv(x_clr)
    assert_equal_shape(x, y)
    assert_almost_equal_array(x, y)
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_clr():
    x = np.array([1 / 3.0, 2 / 3.0])
    y = np.array([1 / 4.0, 3 / 4.0])

    x_clr = [-0.5, 0.5]
    y_clr = [-0.79248125036057782, 0.79248125036057815]

    # 1D
    x1d_clr = clr(x)
    x1d_clr_ = np.array(x_clr)
    assert x1d_clr.shape == x1d_clr_.shape
    assert np.allclose(x1d_clr, x1d_clr_)

    # 2D
    xy = np.array([x, y])
    xy_clr = clr(xy)
    xy_clr_ = np.array([x_clr, y_clr])
    assert xy_clr.shape == xy_clr_.shape
    assert np.allclose(xy_clr, xy_clr_)
Esempio n. 9
0
def test_clr():
    x = np.array([1/3.0, 2/3.0])
    y = np.array([1/4.0, 3/4.0])

    x_clr = [-0.5, 0.5]
    y_clr = [-0.79248125036057782, 0.79248125036057815]

    # 1D
    x1d_clr = clr(x)
    x1d_clr_ = np.array(x_clr)
    assert_equal(x1d_clr.shape, x1d_clr_.shape)
    assert_true(allclose(x1d_clr, x1d_clr_))

    # 2D
    xy = np.array([x, y])
    xy_clr = clr(xy)
    xy_clr_ = np.array([x_clr, y_clr])
    assert_equal(xy_clr.shape, xy_clr_.shape)
    assert_true(allclose(xy_clr, xy_clr_))