-def result(inputs):
- s = 0
- perceptron['inputs'] = inputs[:]
- for i in range(len(inputs)):
- s += inputs[i] * perceptron['weights'][i]
- return step(s + perceptron['bias'])
+ def __init__(self, size):
+ self.n_inputs = size
+ self.weights = [0] * self.n_inputs
+ self.bias = 0
+
+ def output(self, inputs):
+ step = 0 # If 0.5, we need no bias for AND and OR; if 0, none for NOT.
+ # With learning, the bias will slowly balance any choice.
+ weighted_inputs_sum = 0
+ for i in range(self.n_inputs):
+ weighted_inputs_sum += inputs[i] * self.weights[i]
+ if weighted_inputs_sum + self.bias >= step:
+ return 1
+ else:
+ return 0
+
+class TrainingUnit:
+
+ def __init__(self, inputs, target):
+ self.inputs = inputs
+ self.target = target