Add input method and implement learning constant
This commit is contained in:
parent
d00a8312cc
commit
79694344a5
|
@ -1,5 +1,6 @@
|
||||||
from Input import Input
|
from Input import Input
|
||||||
|
|
||||||
|
|
||||||
class Perceptron(object):
|
class Perceptron(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -10,6 +11,10 @@ class Perceptron(object):
|
||||||
print(key + ":")
|
print(key + ":")
|
||||||
self.inputs[key].print()
|
self.inputs[key].print()
|
||||||
|
|
||||||
|
def input(self, p_input1, p_input2):
|
||||||
|
self.inputs[0] = p_input1
|
||||||
|
self.inputs[1] = p_input2
|
||||||
|
|
||||||
def add_input(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)
|
self.inputs[p_name] = Input(p_value, p_weight)
|
||||||
|
|
||||||
|
@ -24,14 +29,16 @@ class Perceptron(object):
|
||||||
|
|
||||||
def activation(self):
|
def activation(self):
|
||||||
input = self._sum_inputs()
|
input = self._sum_inputs()
|
||||||
print("Total = %f" % input)
|
print("Sum of inputs = %f" % input)
|
||||||
|
|
||||||
if input > 0:
|
if input > 0:
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
def guess(self, p_desired):
|
def guess(self, p_desired, p_learning_constant):
|
||||||
prediction = float(self.activation())
|
prediction = float(self.activation())
|
||||||
return p_desired - prediction
|
error = p_desired - prediction
|
||||||
|
for key in self.inputs:
|
||||||
|
self.inputs[key].weight += error * self.inputs[key].value * p_learning_constant
|
||||||
|
return error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user