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)
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)
def test_perturbation(): # 1D x = np.array([1 / 3.0, 2 / 3.0]) y = np.array([3 / 4.0, 1 / 4.0]) pxy_ = np.array([3 / 5.0, 2 / 5.0]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy) # 2D with multiple rows x = np.array([[1 / 3.0, 2 / 3.0], [3 / 4.0, 1 / 4.0]]) y = np.array([[3 / 4.0, 1 / 4.0], [1 / 6.0, 5 / 6.0]]) pxy_ = np.array([[3 / 5.0, 2 / 5.0], [3 / 8.0, 5 / 8.0]]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy) # 2D with one row x = np.array([[1 / 3.0, 2 / 3.0]]) y = np.array([[3 / 4.0, 1 / 4.0]]) pxy_ = np.array([[3 / 5.0, 2 / 5.0]]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy)
def test_perturbation(): # 1D x = np.array([1/3.0, 2/3.0]) y = np.array([3/4.0, 1/4.0]) pxy_ = np.array([3/5.0, 2/5.0]) pxy = perturbation(x, y) assert_true(x.shape == pxy.shape) assert_true(allclose(pxy_, pxy)) # 2D with multiple rows x = np.array([[1/3.0, 2/3.0], [3/4.0, 1/4.0]]) y = np.array([[3/4.0, 1/4.0], [1/6.0, 5/6.0]]) pxy_ = np.array([[3/5.0, 2/5.0], [3/8.0, 5/8.0]]) pxy = perturbation(x, y) assert_true(x.shape == pxy.shape) assert_true(allclose(pxy_, pxy)) # 2D with one row x = np.array([[1/3.0, 2/3.0]]) y = np.array([[3/4.0, 1/4.0]]) pxy_ = np.array([[3/5.0, 2/5.0]]) pxy = perturbation(x, y) assert_true(x.shape == pxy.shape) assert_true(allclose(pxy_, pxy))
def test_perturbation(): # 1D x = np.array([1 / 3, 2 / 3]) y = np.array([3 / 4, 1 / 4]) pxy_ = np.array([3 / 5, 2 / 5]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy) # 2D with multiple rows x = np.array([[1 / 3, 2 / 3], [3 / 4, 1 / 4]]) y = np.array([[3 / 4, 1 / 4], [1 / 6, 5 / 6]]) pxy_ = np.array([[3 / 5, 2 / 5], [3 / 8, 5 / 8]]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy) # 2D with one row x = np.array([[1 / 3, 2 / 3]]) y = np.array([[3 / 4, 1 / 4]]) pxy_ = np.array([[3 / 5, 2 / 5]]) pxy = perturbation(x, y) assert x.shape == pxy.shape assert np.allclose(pxy_, pxy)