Esempio n. 1
0
    def test_XOR_operation(self):
        network = Perceptron(input=2, hidden=[20], output=1)
        trainer = Trainer(network)
        error, epoch = trainer.XOR()
        self.assertTrue(error < 0.1)

        self.assertTrue(abs(sum(network.activate([0, 0])) - 0) < 0.1)
        self.assertTrue(abs(sum(network.activate([0, 1])) - 1) < 0.1)
        self.assertTrue(abs(sum(network.activate([1, 0])) - 1) < 0.1)
        self.assertTrue(abs(sum(network.activate([1, 1])) - 0) < 0.1)
Esempio n. 2
0
 def test_from_json(self):
     return
     fn = os.path.join(os.path.dirname(__file__), './test_network.json')
     settings = {
         'momentum': 0.99,
         'epoch': 5000,
         'log': 100,
         'error': 0.1,
         'rate': 0.2,
         'cost': Cost.SE
     }
     with open(fn) as data_file:
         network_json = json.load(data_file)
         network = Network.from_json(network_json)
         trainer = Trainer(network)
         start = time.time()
         error, epoch = trainer.XOR(settings)
         stop = time.time()
         print(stop - start)