我是新的编码,我有很多麻烦,这个“简单”的程序。你知道吗
因此,我试图连接“节点”列表中的3个节点,我已经创建在一起。在Node类中,我定义了一个add连接,并创建了一个连接类来将这些连接绑定在一起。你知道吗
但当我试图节点.addconnection它给了我“未绑定方法”。如果我想”节点.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
您的问题是,在调用“addconnection”时,您试图通过调用…addconnection将所有节点连接在一起。因此,递归。你知道吗
如果尝试连接“其他程序”部分中的所有节点,则效果会更好:
相关问题 更多 >
编程相关推荐