def test_update_b_single_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) b = compute_b(X, omega, u) b = update_b_single(x, b, n=N, omega=omega, u=u) b_batch = compute_b(np.vstack((X, x)), omega, u) assert_allclose(b, b_batch)
def test_update_b_single_equals_compute_b_when_initialised_correctly(): sigma = 1. 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 b_update = np.zeros(m) n_update = m for x in X: b_update = update_b_single(x, b_update, n_update, omega, u) n_update += 1 # initial fit and batch (average of "fake" b and new observations b_fake = np.zeros(m) n_fake = m b_batch = (b_fake * n_fake + compute_b(X, omega, u) * N) / (n_fake + N) assert_allclose(b_update, b_batch)