def test_disassemble_params(self): net = FeedforwardNetwork(ninput=3, noutput=2, nhidden=[2, 3], activ_func=Logistic()) params = [ 1111, 1112, 1113, 1121, 1122, 1123, 121, 122, 2111, 2112, 2121, 2122, 2131, 2132, 221, 222, 223, 3111, 3112, 3113, 3121, 3122, 3123, 321, 322 ] w, b = net.disassemble_params(params) W0 = [[1111, 1112, 1113], [1121, 1122, 1123]] W1 = [[2111, 2112], [2121, 2122], [2131, 2132]] W2 = [[3111, 3112, 3113], [3121, 3122, 3123]] B0 = [[121], [122]] B1 = [[221], [222], [223]] B2 = [[321], [322]] assert_array_almost_equal(w[0], W0) assert_array_almost_equal(w[1], W1) assert_array_almost_equal(w[2], W2) assert_array_almost_equal(b[0], B0) assert_array_almost_equal(b[1], B1) assert_array_almost_equal(b[2], B2)
def test_two_hiddenlayer_three_input_two_output(self): l = Logistic() i = Identity() net = FeedforwardNetwork(ninput=3, noutput=2, nhidden=[2, 3], activ_func=Logistic()) params = np.array([ 1.111, 1.112, 11.13, 112.1, 0.1122, 1123, 12.1, 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 ]) w, b = net.disassemble_params(params) innet = np.asarray([1, 2, 3]).reshape(3, 1) expected = i( np.dot(w[2], l(np.dot(w[1], l(np.dot(w[0], innet) + b[0])) + b[1])) + b[2]).flatten() assert_array_almost_equal(net(innet, params), expected, decimal=3) innet = np.asarray([1.78, -2, 3]).reshape(3, 1) expected = i( np.dot(w[2], l(np.dot(w[1], l(np.dot(w[0], innet) + b[0])) + b[1])) + b[2]).flatten() assert_array_almost_equal(net(innet, params), expected, decimal=3) innet = np.asarray([1, 25, 3]).reshape(3, 1) expected = i( np.dot(w[2], l(np.dot(w[1], l(np.dot(w[0], innet) + b[0])) + b[1])) + b[2]).flatten() assert_array_almost_equal(net(innet, params), expected, decimal=3)