Ejemplo n.º 1
0
 def test_train_twice(self):
     input_dimension = 3
     sample_size = 500
     X = np.random.rand(sample_size, input_dimension)
     Y = np.random.randint(0, high=2, size=sample_size)
     base_label = 'test_train_'
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     for i in range(2):
         model.fit(X, Y, base_label + str(i))
Ejemplo n.º 2
0
 def test_get_weight_correct_dimension(self):
     input_dimension = 4
     sample_size = 500
     X = np.random.rand(sample_size, input_dimension)
     Y = np.random.randint(0, high=2, size=sample_size)
     label = 'weight_check'
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     model.fit(X, Y, label)
     weights = model.get_weights()
     self.assertTrue(weights.flatten().shape[0], input_dimension)
Ejemplo n.º 3
0
 def test_identity_learn_perfect(self):
     input_dimension = 1
     sample_size = 500
     Y = np.random.randint(0, high=2, size=sample_size)
     X = Y.reshape([-1, 1])
     label = 'identity'
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     model.fit(X, Y, label)
     score = model.score(X, Y, label=label)
     self.assertEqual(1, score)
 def test_train_xor_score_succeed_with_pre_requisite(self):
     input_dimension = 2
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     and_score = binary.Binary.teach_and(model)
     self.assertEqual(1, and_score)
     or_score = binary.Binary.teach_or(model)
     self.assertEqual(1, or_score)
     xor_score = binary.Binary.teach_xor(model)
     self.assertEqual(1, xor_score)
Ejemplo n.º 5
0
 def test_new_node_name(self):
     label = 'hi'
     expected_new_nod_name = 'hi' + utilities.node_version_separator + '0'
     model = LayeredNeuralNetwork(2)
     new_node_name = model.get_new_node_name(label)
     self.assertEqual(expected_new_nod_name, new_node_name)
     model.labels = [label]
     model.label_to_node_name[label] = expected_new_nod_name
     expected_new_nod_name2 = 'hi' + utilities.node_version_separator + '1'
     new_node_name2 = model.get_new_node_name(label)
     self.assertEqual(expected_new_nod_name2, new_node_name2)
 def test_train_and_score(self):
     input_dimension = 9
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     score = binary.Binary.teach_and(model)
     self.assertEqual(1, score)
 def test_frequency_all(self):
     input_dimension = 20
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     score = frequency.Frequency.teach_all_frequency(model)
     self.assertEqual(1, score)
 def test_train_xor_score_fail_without_pre_requisite(self):
     input_dimension = 9
     model = LayeredNeuralNetwork(input_dimension=input_dimension)
     score = binary.Binary.teach_xor(model)
     self.assertLess(score, 0.7)