Add activation method, fix printing
This commit is contained in:
parent
4edf73d674
commit
9e8d0d2906
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user