-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperceptron.py
More file actions
35 lines (33 loc) · 942 Bytes
/
Copy pathperceptron.py
File metadata and controls
35 lines (33 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
""" This is a class to implement the perceptron artificial nueron """
class Perceptron:
""" Constructor """
def __init__(self, w_v=[0]):
self.weight_vector = w_v
""" Geter for weight vector """
def getWeightVector(self):
return self.weight_vector
""" Seter for weight vector """
def setWeightVector(self,w_v):
self.weight_vector = w_v
"""
The step function is the function that will decide.
There are other functions more interesting for implementation.
"""
def step_fnc(self,suma):
if suma > 0:
return 1
else:
return -1
"""
This function implements the matrix product W^T * X
Where X and W are collumn vectors
"""
def fire_fnc(self,input_vector):
suma = 0
for index in range(len(input_vector)):
#print input_vector[index]
#raw_input()
suma += self.weight_vector[index]*float(input_vector[index])
return self.step_fnc(suma)
def fire(self,input_vector):
return self.fire_fnc(input_vector)