def test_rff_feature_map_comp_grad_theano_execute(): if not theano_available: raise SkipTest("Theano not available.") D = 2 x = np.random.randn(D) m = 10 sigma = 1. omega, u = rff_sample_basis(D, m, sigma) for i in range(m): rff_feature_map_comp_grad_theano(x, omega[:, i], u[i])
def test_rff_feature_map_comp_grad_theano_execute(): if not theano_available: raise SkipTest("Theano not available.") D = 2 x = np.random.randn(D) m = 10 sigma = 1. omega, u = rff_sample_basis(D, m, sigma) for i in range(m): rff_feature_map_comp_grad_theano(x, omega[:, i], u[i])
def test_rff_feature_map_grad_theano_result_equals_manual(): if not theano_available: raise SkipTest("Theano not available.") D = 2 x = np.random.randn(D) X = x[np.newaxis, :] m = 10 sigma = 1. omega, u = rff_sample_basis(D, m, sigma) grad_manual = rff_feature_map_grad(X, omega, u)[:, 0, :] for i in range(m): # phi_manual is a monte carlo average, so have to normalise by np.sqrt(m) here grad = rff_feature_map_comp_grad_theano(x, omega[:, i], u[i]) / np.sqrt(m) assert_close(grad, grad_manual[:, i])
def test_rff_feature_map_grad_theano_result_equals_manual(): if not theano_available: raise SkipTest("Theano not available.") D = 2 x = np.random.randn(D) X = x[np.newaxis, :] m = 10 sigma = 1. omega, u = rff_sample_basis(D, m, sigma) grad_manual = rff_feature_map_grad(X, omega, u)[:, 0, :] for i in range(m): # phi_manual is a monte carlo average, so have to normalise by np.sqrt(m) here grad = rff_feature_map_comp_grad_theano(x, omega[:, i], u[i]) / np.sqrt(m) assert_close(grad, grad_manual[:, i])