From 9e8d0d290677cd33c8fd8077d2cc07cf554318f5 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Thu, 9 Feb 2017 19:06:01 +0000 Subject: [PATCH] Add activation method, fix printing --- Perceptron.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Perceptron.py b/Perceptron.py index 820a11f..327d17e 100644 --- a/Perceptron.py +++ b/Perceptron.py @@ -1,18 +1,32 @@ from Input import Input - class Perceptron(object): def __init__(self): self.inputs = {} def print(self): - for key, value in self.inputs: - print("%s - )") % key - value.print() + for key in self.inputs: + print(key + ":") + self.inputs[key].print() - def addinput(self, p_name, p_value, p_weight): + def add_input(self, p_name, p_value, p_weight): self.inputs[p_name] = Input(p_value, p_weight) - def setweight(self, p_input, p_weight): + def set_weight(self, p_input, p_weight): self.inputs[p_input].weight = p_weight + + def _sum_inputs(self): + total = 0 + for key, value in self.inputs.items(): + total += value.output() + return total + + def activation(self): + input = self._sum_inputs() + print("Total = %f" % input) + + if input > 0: + return True + else: + return False