def _classifier(self, n): """ Return true or false based on a vector :param n: vector to classify :return: """ result = dot_product(self._inputList, self._weights) #print ("DBG PERCEPTRON: " + str(self._weights)) #print ("DBG PERCEPTRON: " + str(result)) boolresult = result > self._threshold return boolresult
def _train(self): ## Undertrain as we are limiting the reps we are trianing for for goWeightTraining in range(self._trainForAtLeastThisManyReps): error_count = 0 #print ("DBG OptimusPERCEPTRON: _trainingset:" + str(self._training_set)) for input_vector, desired_output in self._training_set: # debug print("_train: weights") # debug print(weights) result = dot_product(self._inputList, self._weights) > self._threshold error = desired_output - result if error != 0: error_count += 1 for index, value in enumerate(self._inputList): self._weights[index] += self._learning_rate * error * value # debug print("_train: error_count:"+str(error_count)) # Don't overtrain if error_count == 0: break return True