Exemplo n.º 1
0
 def train(self, test_type):
     print("Initial network:\n" + str(self))
     for time in range(constants.ITERATION_TRAIN):
         ind = random.randint(0, len(self.training_ind) - 1)
         file_no = self.training_ind[ind]
         target = self.assign_target_value(test_type, self.file_names[file_no])
         data = load_data.reduce_dimension(load_data.parse_file(self.file_names[file_no]))
         input_val = []
         for d in data:
             input_val.extend(d)
         # 255 is maximum gray-scale value
         input_val = [i/255.0 for i in input_val]
         self.train_example(input_val, target)
     print("Finished network:\n" + str(self))
Exemplo n.º 2
0
 def test(self, test_type):
     correct = 0
     for ind in range(len(self.test_ind)):
         file_no = self.test_ind[ind]
         target = self.assign_target_value(test_type, self.file_names[file_no])
         data = load_data.reduce_dimension(load_data.parse_file(self.file_names[file_no]))
         input_val = []
         for d in data:
             input_val.extend(d)
         # 255 is maximum gray-scale value
         input_val = [i/255.0 for i in input_val]
         output = self.calculate_output_output(self.calculate_hidden_output(input_val))
         if self.check_if_correct_output(test_type, target, output):
             correct += 1
     print("Correctly classified: " + str(correct) + "/" + str(len(self.test_ind)))