Beispiel #1
0
class ElmanSimpleRecurrentTest(unittest.TestCase):
    """
    Tests ElmanSimpleRecurrent

    """
    def setUp(self):

        self.net = NeuralNet()
        self.net.init_layers(2, [1], 1)

        self.rec_config = ElmanSimpleRecurrent()

    def test_class_init_(self):

        self.assertEqual('a', self.rec_config.source_type)
        self.assertEqual(1.0, self.rec_config.incoming_weight)
        self.assertEqual(0.0, self.rec_config.existing_weight)
        self.assertEqual('m', self.rec_config.connection_type)
        self.assertEqual(1, self.rec_config.copy_levels)
        self.assertEqual(0, self.rec_config.copy_nodes_layer)

    def test_get_source_nodes(self):

        nodes1 = self.net.layers[1].get_nodes(NODE_HIDDEN)
        nodes2 = self.rec_config.get_source_nodes(self.net)

        #   Should be the same
        self.assertEqual(len(nodes1), len(nodes2))
        self.assertEqual(self.net.layers[1].get_nodes(NODE_HIDDEN),
                         self.rec_config.get_source_nodes(self.net))
class ElmanSimpleRecurrentTest(unittest.TestCase):
    """
    Tests ElmanSimpleRecurrent

    """

    def setUp(self):

        self.net = NeuralNet()
        self.net.init_layers(2, [1], 1)

        self.rec_config = ElmanSimpleRecurrent()

    def test_class_init_(self):

        self.assertEqual('a', self.rec_config.source_type)
        self.assertEqual(1.0, self.rec_config.incoming_weight)
        self.assertEqual(0.0, self.rec_config.existing_weight)
        self.assertEqual('m', self.rec_config.connection_type)
        self.assertEqual(1, self.rec_config.copy_levels)
        self.assertEqual(0, self.rec_config.copy_nodes_layer)

    def test_get_source_nodes(self):

        nodes1 = self.net.layers[1].get_nodes(NODE_HIDDEN)
        nodes2 = self.rec_config.get_source_nodes(self.net)

        #   Should be the same
        self.assertEqual(len(nodes1), len(nodes2))
        self.assertEqual(
            self.net.layers[1].get_nodes(NODE_HIDDEN),
            self.rec_config.get_source_nodes(self.net))
Beispiel #3
0
    def setUp(self):

        self.net = NeuralNet()
        self.net.init_layers(2, [1], 1)

        self.rec_config = ElmanSimpleRecurrent()
Beispiel #4
0
 y_train = np.array(y_train).reshape((len(y_train), 1))
 y_test = np.array(y_test).reshape((len(y_test), 1))
 #transformando os dados para estar no intervalo de 0 a 1
 scaler_x = MinMaxScaler()
 x_train = scaler_x.fit_transform(x_train)
 x_test = scaler_x.transform(x_test)
 scaler_y = MinMaxScaler()
 y_train = scaler_y.fit_transform(y_train)
 y_test = scaler_y.transform(y_test)
 x_input = np.concatenate(
     (x_train, x_test, np.zeros((1, np.shape(x_train)[1]))))
 y_input = np.concatenate((y_train, y_test, np.zeros((1, 1))))
 #elaboracao do modelo de rede neural com os parametros definidos
 fit1 = NeuralNet()
 fit1.init_layers(input_nodes, [hidden_nodes], output_nodes,
                  ElmanSimpleRecurrent())
 fit1.randomize_network()
 fit1.layers[1].set_activation_type('sigmoid')
 fit1.set_learnrate(0.05)
 fit1.set_all_inputs(x_input)
 fit1.set_all_targets(y_input)
 fit1.set_learn_range(0, i)
 fit1.set_test_range(i, i + 1)
 fit1.learn(epochs=100, show_epoch_results=True, random_testing=False)
 mse = fit1.test()
 all_mse.append(mse)
 print("test set MSE = ", np.round(mse, 6))
 target = [item[0][0] for item in fit1.test_targets_activations]
 target = scaler_y.inverse_transform(
     np.array(target).reshape((len(target), 1)))
 pred = [item[1][0] for item in fit1.test_targets_activations]
    def setUp(self):

        self.net = NeuralNet()
        self.net.init_layers(2, [1], 1)

        self.rec_config = ElmanSimpleRecurrent()