Beispiel #1
0
def test_power():
    # 1D
    x = np.array([1 / 3.0, 2 / 3.0])
    y = 3
    px_ = np.array([1 / 9.0, 8 / 9.0])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)
    x = np.array([1 / 4.0, 3 / 4.0])
    y = 3
    px_ = np.array([1 / 28.0, 27 / 28.0])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)

    # 2D with multiple rows
    x = np.array([[1 / 3.0, 2 / 3.0], [1 / 4.0, 3 / 4.0]])
    y = [3, 3]
    px_ = np.array([[1 / 9.0, 8 / 9.0], [1 / 28.0, 27 / 28.0]])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)

    # 2D with one row
    x = np.array([[1 / 3.0, 2 / 3.0]])
    y = [3]
    px_ = np.array([[1 / 9.0, 8 / 9.0]])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)
Beispiel #2
0
def test_power():
    # 1D
    x = np.array([1/3.0, 2/3.0])
    y = 3
    px_ = np.array([1/9.0, 8/9.0])
    px = power(x, y)
    assert_true(px_.shape == px.shape)
    assert_true(allclose(px_, px))
    x = np.array([1/4.0, 3/4.0])
    y = 3
    px_ = np.array([1/28.0, 27/28.0])
    px = power(x, y)
    assert_true(px_.shape == px.shape)
    assert_true(allclose(px_, px))

    # 2D with multiple rows
    x = np.array([[1/3.0, 2/3.0], [1/4.0, 3/4.0]])
    y = [3, 3]
    px_ = np.array([[1/9.0, 8/9.0], [1/28.0, 27/28.0]])
    px = power(x, y)
    assert_true(px_.shape == px.shape)
    assert_true(allclose(px_, px))

    # 2D with one row
    x = np.array([[1/3.0, 2/3.0]])
    y = [3]
    px_ = np.array([[1/9.0, 8/9.0]])
    px = power(x, y)
    assert_true(px_.shape == px.shape)
    assert_true(allclose(px_, px))
Beispiel #3
0
def test_power():
    # 1D
    x = np.array([1 / 3, 2 / 3])
    y = 3
    px_ = np.array([1 / 9, 8 / 9])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)
    x = np.array([1 / 4, 3 / 4])
    y = 3
    px_ = np.array([1 / 28, 27 / 28])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)

    # 2D with multiple rows
    x = np.array([[1 / 3, 2 / 3], [1 / 4, 3 / 4]])
    y = [3, 3]
    px_ = np.array([[1 / 9, 8 / 9], [1 / 28, 27 / 28]])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)

    # 2D with one row
    x = np.array([[1 / 3, 2 / 3]])
    y = [3]
    px_ = np.array([[1 / 9, 8 / 9]])
    px = power(x, y)
    assert px_.shape == px.shape
    assert np.allclose(px_, px)
Beispiel #4
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)
Beispiel #5
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)