【发布时间】:2014-03-28 12:35:30
【问题描述】:
我是编码新手,所以我遇到了一些简单的问题。当我运行 10 次迭代时,我得到相同的数字。-0.5 用于激活,0.0 用于输入,即使在底部我将节点列表中每个对应节点的起始激活设置为 1.0、1.0 和 0.0。
我想通过设置初始状态。他们向另一个节点发送一个输入:这是 sender.activation * 权重为 1。我应该得到一个新的输入值。然后将其应用于我的激活,然后我将能够 -0.5 并获得节点的新激活。
至少那是我尝试做的。不知何故,它只是吐出 0.0 和 -0.5。
#
# Preparations
#
nodes=[]
NUMNODES=3
#
# Defining Node Class
#
class Node(object):
def __init__(self,name=None):
self.name=name
self.activation_threshold=1.0
self.net_input=0.0
self.outgoing_connections=[]
self.incoming_connections=[]
self.connections=[]
self.activation=None
def addconnection(self,sender,weight=0.0):
self.connections.append(Connection(self,sender,weight))
def update_input(self):
self.net_input=0.0
for conn in self.connections:
self.net_input += conn.weight * 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
#
# Defining 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(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
#
# Setting Activations
#
set_activations([1.0,1.0,0.0])
#
# Running 10 Iterations
#
for i in xrange(10):
for thing in nodes:
thing.update_activation()
thing.update_input()
【问题讨论】:
标签: python input iteration neural-network activation