def test_update_L_C_single_equals_compute_L_C_when_initialised_correctly(): sigma = 1. lmbda = 2. N = 200 D = 2 m = 10 X = np.random.randn(N, D) # basis omega, u = rff_sample_basis(D, m, sigma) # initial fit and update L_C_update = np.eye(m) * np.sqrt(lmbda) n_update = m for x in X: L_C_update = update_L_C_single(x, L_C_update, n_update, omega, u) n_update += 1 # initial fit and batch (average of "fake" b and new observations L_C_fake = np.eye(m) * np.sqrt(lmbda) n_fake = m C_batch = (np.dot(L_C_fake, L_C_fake.T) * n_fake + compute_C(X, omega, u) * N) / (n_fake + N) L_C_batch = np.linalg.cholesky(C_batch) assert_allclose(L_C_update, L_C_batch)
def test_update_L_C_equals_batch(): N = 100 D = 3 m = 10 omega = np.random.randn(D, m) u = np.random.uniform(0, 2 * np.pi, m) X = np.random.randn(N, D) x = np.random.randn(D) L_C = np.linalg.cholesky(compute_C(X, omega, u)) L_C = update_L_C_single(x, L_C, N, omega, u) L_C_batch = np.linalg.cholesky(compute_C(np.vstack((X, x)), omega, u)) assert_allclose(L_C, L_C_batch)