def test_three_hiddenlayer_three_input_two_output(self): net = FeedforwardNetwork(ninput=3, noutput=2, nhidden=[2, 3, 4], activ_func=[ Logistic(), HyperbolicTangent(), Identity(), Logistic() ]) for i in range(5): params = np.random.normal(size=(net.nparams, )) x = np.random.normal(size=(net.ninput, )) def call_x(y): return net(y, params) def call_params(theta): return net(x, theta) dx_numeric = nd.Jacobian(call_x)(x) dparams_numeric = nd.Jacobian(call_params)(params) dx, dparams = net.derivatives(x, params) assert_array_almost_equal(dx, dx_numeric) assert_array_almost_equal(dparams, dparams_numeric)
def test_two_hiddenlayer_three_input_two_output(self): net = FeedforwardNetwork(ninput=3, noutput=2, nhidden=[2, 3], activ_func=Logistic()) params = np.array([ 1.111, 1.112, 11.13, 1.121, 0.1122, 1123, 1.21, 1.22, 0.2111, 0.2112, 2.121, 2.122, 0.2131, 0.2132, 2.21, 2.22, 0.223, 3.111, 0.3112, 3.113, 0.3121, 0.3122, 0.3123, 0.321, 3.22 ]) x = [0.1, 2.2, 0.34] def call_x(y): return net(y, params) def call_params(theta): return net(x, theta) dx_numeric = nd.Jacobian(call_x)(x) dparams_numeric = nd.Jacobian(call_params)(params) dx, dparams = net.derivatives(x, params) assert_array_almost_equal(dx, dx_numeric) assert_array_almost_equal(dparams, dparams_numeric)