Exemple #1
0
    def train_xor(self, learning_rate=0.1):
        """Trains XOR with a neural net"""
        X = np.array([[0.0, 0.0], [0, 1], [1, 0], [1, 1]])
        y = np.array([0, 1, 1, 0])
        net = PyBrainNN(learning_rate=learning_rate,
                        maxiterations=10000,
                        lam=0.0,
                        args=(2, 3, 1),
                        kwargs={
                            'fast': True,
                            'bias': True
                        })
        net.fit(X, y)

        return net, X, y
Exemple #2
0
    def test_load_save_model(self):
        import tempfile

        net, X, y = self.train_xor()

        # save the model
        tfile = tempfile.TemporaryFile()
        net.save_model(tfile)

        # load in the model
        tfile.seek(0)

        model = json.load(tfile)

        netloaded = PyBrainNN.load_model(model)

        self.assertTrue(np.allclose(net.predict(X), netloaded.predict(X)))