https://github.com/GPflow/GPflow
Raw File
Tip revision: 8aba58b41819b00c7db5d42326757e532802dd18 authored by st-- on 02 July 2018, 22:08:40 UTC
Merge branch 'master' into icouckuy-derivatives
Tip revision: 8aba58b
test_gradient.py
# Copyright 2018 the GPflow authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
import pytest
import tensorflow as tf
from numpy.testing import assert_allclose

import gpflow
from gpflow.test_util import session_tf

def test_columnwise_gradient(session_tf):
    X = tf.placeholder(gpflow.settings.float_type, [None, None])
    X_np = np.random.randn(6, 2)
    Y = tf.reduce_sum(X ** 2, axis=1)
    Y = tf.reshape(Y, [-1, 1])
    grads = gpflow.misc.columnwise_gradients(Y, X)
    grads = tf.reshape(grads, [6, 2])
    expected = 2 * X_np
    res = session_tf.run(grads, feed_dict={X: X_np})
    assert_allclose(res, expected, atol=1e-10)

back to top