-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.py
65 lines (44 loc) · 1.31 KB
/
Node.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
from functools import total_ordering
@total_ordering
class Node:
x=-1
output =-1
connections = []
def __init__(self, nX):
self.connections = []
self.x = nX
def calculate(self):
s=0
for a in self.connections:
#print("a "+str(a.getOrigin()))
if(a.isEnabled()):
s += a.getWeight()*a.getTarget().getOutput()
self.output=self.activationFunction(s)
def activationFunction(self, foo):
return 1/(1+ np.exp(-foo))
############
def getX(self):
return self.x
def setX(self, nX):
self.x= nX
def setOutput(self, nOutput):
self.output = nOutput
def getOutput(self):
return self.output
def getConnections(self):
return self.connections
def setConnections(self, nConnections):
self.connections = nConnections
#I have no plans to learn how to properly implement comparables in python anytime soon
def compareTo(self, obj):
if(self.x > obj.x): return -1
if(self.x < obj.x): return 1
else: return 0
#NVM im gonna try
def __eq__(self, obj):
return (self.x==obj.x)
def __lt__(self, obj):
return (self.x< obj.x)
def __gt__(self, obj):
return (self.x > obj.x)