0
나는 코딩에 익숙하지 않으며이 "간단한"프로그램에 많은 문제가 있습니다.파이썬 신경망 : 노드를 함께 연결
그래서 나는 함께 만든 "노드"목록에서 3 개의 노드를 연결하려고합니다. Node 클래스에서 추가 연결을 정의하고 이들을 모두 바인딩하는 Connection 클래스를 만들었습니다.
하지만 "Node.addconnection"을 시도하면 "언 바운드 방식"이됩니다. 그리고 "Node.addconnection (Node(), Node())"하면 두 개의 노드를 함께 연결한다고 생각했습니다. 그러나 그것은 나에게 무한 루프의 오류를 준다.
#
# Preparations
#
nodes=[]
NUMNODES=3
#
# Node Class
#
class Node(object):
def __init__(self,name=None):
self.name=name
self.activation_threshold=0.0
self.net_input=0.0
self.outgoing_connections=[]
self.incoming_connections=[]
self.activation=None
def addconnection(self,sender,weight=0.0):
self.connections.append(Connection(self,sender,weight))
for i in xrange(NUMNODES):#go thru all the nodes calling them i
for j in xrange(NUMNODES):#go thru all the nodes calling them j
if i!=j:#as long as i and j are not the same
nodes[i].AddConnection(nodes[j])#connects the nodes together
def update_input(self):
self.net_input=0.0
for conn in self.connections:
self.net_input += conn.wt * conn.sender.activation
print 'Updated Input is', self.net_input
def update_activation(self):
self.activation = self.net_input - 0.5
print 'Updated Activation is', self.activation
#
# Connection Class
#
class Connection(object):
def __init__(self, sender, reciever, weight=1.0):
self.weight=weight
self.sender=sender
self.reciever=reciever
sender.outgoing_connections.append(self)
reciever.incoming_connections.append(self)
#
# Other Programs
#
def set_activations(act_vector):
"""Activation vector must be same length as nodes list"""
for i in xrange(len(act_vector)):
nodes[i].activation = act_vector[i]
for i in xrange(NUMNODES):
nodes.append(Node())
for i in xrange(10):
for thing in nodes:
thing.update_activation
thing.update_input
아, 그 자체에 노드를 연결했기 때문에, 그냥 주위에 반복 유지했다. 감사! – Averruncus