def test_rff_feature_map_third_order_tensor_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_third_order_tensor_theano(x, omega[:, i], u[i])
def test_rff_feature_map_third_order_tensor_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_third_order_tensor_theano(x, omega[:, i], u[i])
def third_order_derivative_tensor(self, x): """ Computes the third order derivative tensor of the learned log-density function. WARNING: This implementation is slow, so don't call repeatedly. """ assert_array_shape(x, ndim=1, dims={0: self.D}) G3 = np.zeros((self.D, self.D, self.D)) for i, theta_i in enumerate(self.theta): G3 += theta_i * rff_feature_map_comp_third_order_tensor_theano(x, self.omega[:, i], self.u[i]) # RFF is a monte carlo average, so have to normalise by np.sqrt(m) here return G3 / np.sqrt(self.m)
def third_order_derivative_tensor(self, x): """ Computes the third order derivative tensor of the learned log-density function. WARNING: This implementation is slow, so don't call repeatedly. """ assert_array_shape(x, ndim=1, dims={0: self.D}) G3 = np.zeros((self.D, self.D, self.D)) for i, theta_i in enumerate(self.theta): G3 += theta_i * rff_feature_map_comp_third_order_tensor_theano( x, self.omega[:, i], self.u[i]) # RFF is a monte carlo average, so have to normalise by np.sqrt(m) here return G3 / np.sqrt(self.m)