def _get_cascade(self, net): net._output_connections[0][0] = 2.24107584 net._output_connections[0][1] = -0.00060484 net._output_connections[0][2] = -2.24107583 net._output_connections[0][3] = -2.24107584 print_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) return net._generate_candidate(DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS)
def test_correlation_maximize(self): net = self.CLASS(2, 1) net.use_quick_prop = True net._output_connections[0][0] = -1.7 net._output_connections[0][1] = 1.7 net._output_connections[0][2] = -1.7 print_results(net, XOR_INPUTS, XOR_TARGETS) # the error will be large for -1.0, 1.0 but small for everything else winner = net._generate_candidate(XOR_INPUTS, XOR_TARGETS) print(winner.activations) self.assertAlmostEqual(winner.activations[2], max(winner.activations), delta=0.1)
def test_double_xor_cascading(self): net = self.CLASS(3, 1, num_candidate_nodes=8) net.learn_rate = 0.15 error = net.get_error(DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) final_error = net.train(DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS, mini_batch_size=3, max_hidden_nodes=10, stop_error_threshold=1.0, max_iterations_per_epoch=100) print(len(net._cascade_connections)) print_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) self.assert_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS)
def test_xor_cascading(self): net = self.CLASS(2, 1) net.momentum_coefficent = 0.7 net.learn_rate = 0.2 error = net.get_error(XOR_INPUTS, XOR_TARGETS) final_error = net.train(XOR_INPUTS, XOR_TARGETS, mini_batch_size=1, max_hidden_nodes=10, stop_error_threshold=0.5, max_iterations_per_epoch=50) print_results(net, XOR_INPUTS, XOR_TARGETS) self.assert_results(net, XOR_INPUTS, XOR_TARGETS) self.assertGreater(error, final_error)
def test_double_xor_cascading(self): net = self.CLASS(3, 1, num_candidate_nodes=8) net.learn_rate = 0.15 error = net.get_error(DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) final_error = net.train( DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS, mini_batch_size=3, max_hidden_nodes=10, stop_error_threshold=1.0, max_iterations_per_epoch=100, ) print(len(net._cascade_connections)) print_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) self.assert_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS)
def test_xor_cascading(self): net = self.CLASS(2, 1) net.momentum_coefficent = 0.7 net.learn_rate = 0.2 error = net.get_error(XOR_INPUTS, XOR_TARGETS) final_error = net.train( XOR_INPUTS, XOR_TARGETS, mini_batch_size=1, max_hidden_nodes=10, stop_error_threshold=0.5, max_iterations_per_epoch=50, ) print_results(net, XOR_INPUTS, XOR_TARGETS) self.assert_results(net, XOR_INPUTS, XOR_TARGETS) self.assertGreater(error, final_error)
def test_generate_candidate(self): net = self.CLASS(3, 1) # this test keeps failing unless I set candidates to a very high number # But I can't see a bug in the code... net.num_candidate_nodes = 20 net._output_connections[0][0] = 2.24107584 net._output_connections[0][1] = -0.00060484 net._output_connections[0][2] = -2.24107583 net._output_connections[0][3] = -2.24107584 print_results(net, DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) winner = net._generate_candidate(DOUBLE_XOR_INPUTS, DOUBLE_XOR_TARGETS) print(winner.activations) print(winner.weights) # This does not always hold true... self.assertAlmostEqual(winner.activations[4], max(winner.activations), delta=0.1)