0

これは私の初めてのコーディングなので、いくつかの簡単なクエリがあります。そのため、コードの最後にある 4 つのパターンでネットワークを「トレーニング」しようとしているホップフィールド ネットワークでこの問題が発生しています。次に、何が起こるかを確認するために、それを 10 回実行する必要があります。

しかし、これを実行してみると、得られた出力値はすべて初期値と同じでした。だから私は何が間違っていたのか分かりません。それとも、これはネットワークが安定した状態に落ち着いたことを意味しますか?

# 
#                                       Preparations 
# 

nodes=[] 
NUMNODES=16
training=[]

# 
#                                   Defining 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.connections=[] 
        self.activation=None

    def __str__(self):
        return self.name

    def addconnection(self,sender,weight=1.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 for node', str(self), 'is', self.net_input 

    def update_activation(self):
        if self.net_input > self.activation_threshold:
            self.activation = 1.0
        elif self.net_input <= self.activation_threshold:
            self.activation = 0.0
        print 'Updated Activation for node', str(self), 'is', self.activation 

    def update_training(self):
        Node = random.choice(nodes)

# 
#                                   Defining Connection Class
# 

class Connection(object): 
    def __init__(self, sender, reciever, weight): 
        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(str(i)))

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

#
#                                         Training Pattern
#

set_activations([1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0])
set_activations([1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0])
set_activations([1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0])
set_activations([1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0])

#
#                                        Running 10 Iterations
#

for i in xrange(10):
    print '                     *********** Iteration', str(i+1), '***********'
    for thing in nodes:
        thing.update_training()
        thing.update_input()
        thing.update_activation()
4

1 に答える 1

0

ああ、気にしないでください。エラーに気づき、コードを修正しました。

于 2014-02-28T18:21:20.650 に答える