코딩에 익숙하지 않아 간단한 문제가 발생했습니다. 내가 10 번의 반복을 실행할 때, 시작점 활성화를 노드 목록의 각 해당 노드에 1.0, 1.0 및 0.0으로 설정 했는데도 맨 아래에 활성화와 0.0의 동일한 숫자가 있습니다.Python 신경 회로망 : 10 반복을 실행하지만 동일한 출력을 얻었습니다
초기 상태를 설정하여 생각했습니다. 그들은 다른 노드에 입력을 보낸다. 이것은 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()
오 덕분 I 내가 지금 잘못한 것을 보아라. 나는 그것을 다른 방법으로 덮어 쓸 것이라고 생각했다. 하지만 활성화 값을 1.0, 1.0 및 0.0으로 설정하더라도 값은 모두 같습니다. 왜 3 가지 값이 모두 같은지 모르겠습니다. – Averruncus
아 - 그것은'update_activation'을 즉시 호출하기 때문에,'self.net_input'가 모든 노드에 대해 0.0의 기본값을 가졌을 때 (아직 초기화하지 않았기 때문에) 모든 활성화가 -0.5로 설정됩니다. 먼저'net_input'을 먼저 초기화해야합니다 ('update_input'으로 가정)?'update_activation' 만 호출하십시오. – Roberto
스크립트에'net_input'의 초기화를 추가했습니다. 이것이 예상 된 동작인지 확인하십시오! – Roberto