예제 #1
0
def test_tanh_derivative(transformer_factory):
    inputs = np.array([0, 1, -2], dtype=np.float).reshape((3, 1))

    # bprop is on the output
    outputs = np.array([1 - true_tanh(0) ** 2,
                        1 - true_tanh(1) ** 2,
                        1 - true_tanh(-2) ** 2]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, deriv=True, tol=1e-6)
예제 #2
0
파일: test_tanh.py 프로젝트: AI-Cdrone/neon
def test_tanh_cc2tensor():
    tntest = Tanh()
    from neon.backends.cc2 import GPU, GPUTensor
    inputs = np.array([0, 1, -2]).reshape((3, 1))
    outputs = GPUTensor([true_tanh(0), true_tanh(1), true_tanh(-2)])
    be = GPU(rng_seed=0)
    temp = be.zeros((3, 1))
    tntest.apply_function(be, GPUTensor(inputs), temp)
    assert_tensor_near_equal(outputs, temp)
예제 #3
0
파일: test_tanh.py 프로젝트: AI-Cdrone/neon
def test_tanh_cputensor():
    tntest = Tanh()
    be = CPU(rng_seed=0)
    CPUTensor([0, 1, -2])
    inputs = np.array([0, 1, -2])
    temp = be.zeros(inputs.shape)
    outputs = np.array([true_tanh(0), true_tanh(1), true_tanh(-2)])
    tntest.apply_function(be, CPUTensor(inputs), temp)
    assert_tensor_near_equal(CPUTensor(outputs), temp)
예제 #4
0
파일: test_tanh.py 프로젝트: zz119/neon
def test_tanh_derivative_cputensor():
    tntest = Tanh()
    inputs = np.array([0, 1, -2])
    be = CPU(rng_seed=0)
    outputs = np.array(
        [1 - true_tanh(0)**2, 1 - true_tanh(1)**2, 1 - true_tanh(-2)**2])
    temp = be.zeros(inputs.shape)
    tntest.apply_derivative(be, CPUTensor(inputs), temp)
    assert_tensor_near_equal(CPUTensor(outputs), temp)
예제 #5
0
파일: test_tanh.py 프로젝트: zz119/neon
def test_tanh_cc2tensor():
    tntest = Tanh()
    from neon.backends.cc2 import GPU, GPUTensor
    inputs = np.array([0, 1, -2]).reshape((3, 1))
    outputs = GPUTensor([true_tanh(0), true_tanh(1), true_tanh(-2)])
    be = GPU(rng_seed=0)
    temp = be.zeros((3, 1))
    tntest.apply_function(be, GPUTensor(inputs), temp)
    assert_tensor_near_equal(outputs, temp)
예제 #6
0
파일: test_tanh.py 프로젝트: zz119/neon
def test_tanh_cputensor():
    tntest = Tanh()
    be = CPU(rng_seed=0)
    CPUTensor([0, 1, -2])
    inputs = np.array([0, 1, -2])
    temp = be.zeros(inputs.shape)
    outputs = np.array([true_tanh(0), true_tanh(1), true_tanh(-2)])
    tntest.apply_function(be, CPUTensor(inputs), temp)
    assert_tensor_near_equal(CPUTensor(outputs), temp)
예제 #7
0
파일: test_tanh.py 프로젝트: AI-Cdrone/neon
def test_tanh_derivative_cputensor():
    tntest = Tanh()
    inputs = np.array([0, 1, -2])
    be = CPU(rng_seed=0)
    outputs = np.array([1 - true_tanh(0) ** 2,
                        1 - true_tanh(1) ** 2,
                        1 - true_tanh(-2) ** 2])
    temp = be.zeros(inputs.shape)
    tntest.apply_derivative(be, CPUTensor(inputs), temp)
    assert_tensor_near_equal(CPUTensor(outputs), temp)
예제 #8
0
파일: test_tanh.py 프로젝트: zz119/neon
def test_tanh_derivative_cc2tensor():
    tntest = Tanh()
    from neon.backends.cc2 import GPU, GPUTensor
    inputs = np.array([0, 1, -2], dtype='float32').reshape((3, 1))
    be = GPU(rng_seed=0)
    outputs = GPUTensor(
        [1 - true_tanh(0)**2, 1 - true_tanh(1)**2, 1 - true_tanh(-2)**2])
    temp = be.zeros(inputs.shape)
    tntest.apply_derivative(be, GPUTensor(inputs, dtype='float32'), temp)
    assert_tensor_near_equal(outputs, temp, tolerance=1e-5)
예제 #9
0
파일: test_tanh.py 프로젝트: AI-Cdrone/neon
def test_tanh_derivative_cc2tensor():
    tntest = Tanh()
    from neon.backends.cc2 import GPU, GPUTensor
    inputs = np.array([0, 1, -2], dtype='float32').reshape((3, 1))
    be = GPU(rng_seed=0)
    outputs = GPUTensor([1 - true_tanh(0) ** 2,
                         1 - true_tanh(1) ** 2,
                         1 - true_tanh(-2) ** 2])
    temp = be.zeros(inputs.shape)
    tntest.apply_derivative(be, GPUTensor(inputs, dtype='float32'), temp)
    assert_tensor_near_equal(outputs, temp, tolerance=1e-5)
예제 #10
0
def test_tanh_derivative(backend):
    inputs = np.array(
        [true_tanh(0), true_tanh(1), true_tanh(-2)]).reshape((3, 1))
    # bprop is on the output
    outputs = np.array([1 - true_tanh(0) ** 2,
                        1 - true_tanh(1) ** 2,
                        1 - true_tanh(-2) ** 2]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, deriv=True, tol=1e-7)
예제 #11
0
def test_tanh_derivative(backend):
    inputs = np.array([true_tanh(0), true_tanh(1),
                       true_tanh(-2)]).reshape((3, 1))
    # bprop is on the output
    outputs = np.array(
        [1 - true_tanh(0)**2, 1 - true_tanh(1)**2,
         1 - true_tanh(-2)**2]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, deriv=True, tol=1e-7)
예제 #12
0
def test_tanh(backend):
    inputs = np.array([0, 1, -2]).reshape((3, 1))
    outputs = np.array(
        [true_tanh(0), true_tanh(1), true_tanh(-2)]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, tol=1e-7)
예제 #13
0
def test_tanh(transformer_factory):
    inputs = np.array([0, 1, -2]).reshape((3, 1))
    outputs = np.array(
        [true_tanh(0), true_tanh(1), true_tanh(-2)]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, tol=1e-7)
예제 #14
0
def test_tanh(backend):
    inputs = np.array([0, 1, -2]).reshape((3, 1))
    outputs = np.array([true_tanh(0),
                        true_tanh(1),
                        true_tanh(-2)]).reshape((3, 1))
    compare_tensors(Tanh(), inputs, outputs, tol=1e-7)