networking - Python Backpropagation - How to Initialize the starting activation? -


i having troubles implementing backprop network. i'm not understanding how start off because in network first layer has 8 nodes. prompt gives me 10 in training set.

in first group example, have

[0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0]  

but 8 nodes can assign starting activation each node or have 2 left over.

####################################################################################### #  #                               preparations  #  #######################################################################################  import random import math import pygame import sys network1 = [] network2 = [] layer1 = [] layer2 = [] layer3 = [] set1 = [] set2 = [] set3 = [] mu = .5 eta = .1  ####################################################################################### #  #                                   node class #  #######################################################################################  class node(object):       def __init__(self,name=none):          self.name = name         self.error = none         self.activation_threshold = 0.0         self.net_input = 0.0         self.net_output = 0.0         self.outgoing_connections = []          self.incoming_connections = []         self.activation = none      def __str__(self):         return self.name      def addin(self,sender,weight=random.random):         self.incoming_connections.append(connection(sender,self,weight=random.random))     def addout(self,sender,weight=random.random):         self.outgoing_connections.append(connection(sender,self,weight=random.random))       def update_input(self):          self.net_input=0.0         conn in self.incoming_connections:             self.net_input += conn.weight * conn.sender.activation      def update_output(self):          self.net_output=0.0         conn in self.outgoing_connections:              self.net_output += conn.weight * self.activation      def update_activation(self):         self.activation = 1 / (1 + math.exp(-self.net_input))      def update_weight(self):         in self.incoming_connections:             i.weight = (2*i.reciever.activation - 1)*(2*i.sender.activation-1)         in self.outgoing_connections:             i.weight = (2*i.reciever.activation - 1)*(2*i.sender.activation-1)      def update_error(self):         pass  ####################################################################################### #  #                                   connection class #  #######################################################################################  class connection(object):      def __init__(self, sender, reciever, weight=random.random):          self.weight=weight          self.sender=sender          self.reciever=reciever      def __str__(self):         string = "connection " + str(self.sender) + " " + str(self.reciever) + ", weight = " + str(self.weight)         return string  ####################################################################################### #  #                                     creating nodes & connections  #  #######################################################################################  in xrange(8):      layer1.append(node(str(i))) network1.append(layer1) in xrange(3):     layer2.append(node(str(i))) network1.append(layer2) in xrange(8):      layer3.append(node(str(i))) network1.append(layer3)  in xrange(8):     j in xrange(3):         layer1[i].addin(layer2[j]) in xrange(3):     j in xrange(8):         layer2[i].addin(layer3[j])  ####################################################################################### # #                                         training patterns # #######################################################################################  """non-overlapping categories""" cata11=[0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0] set1.append(cata11) cata12=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0] set1.append(cata12) catb11=[0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0] set1.append(catb11) catb12=[0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0] set1.append(catb12) catc11=[0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0] set1.append(catc11) catc12=[0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0] set1.append(catc12) catd11=[0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0] set1.append(catd11) catd12=[1.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0] set1.append(catd12)  """linearly independent instances , linearly separable categories""" cata21=[1.0,1.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0] set2.append(cata21) cata22=[1.0,1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0] set2.append(cata22) catb21=[1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,1.0,0.0] set2.append(catb21) catb22=[1.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0] set2.append(catb22) catc21=[1.0,0.0,1.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0] set2.append(catc21) catc22=[1.0,0.0,1.0,0.0,1.0,0.0,0.0,1.0,0.0,0.0] set2.append(catc22) catd21=[1.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,0.0] set2.append(catd21) catd22=[1.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0] set2.append(catd22)  """not linearly separable categories""" cata31=[1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0] set3.append(cata31) cata32=[0.0,0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0,1.0] set3.append(cata32) catb31=[1.0,1.0,0.0,1.0,1.0,0.0,0.0,1.0,0.0,0.0] set3.append(catb31) catb32=[0.0,0.0,1.0,0.0,0.0,1.0,1.0,0.0,1.0,1.0] set3.append(catb32)  ##set_activations(cata11) in network1:     i.update_weight() ##for thing in node1: ##    thing.update_weight() ##set_activations(cata12) ##for thing in node1: ##    thing.update_weight() ##set_activations(catb11) ##for thing in node1: ##    thing.update_weight() ##set_activations(catb12) ##for thing in node1: ##    thing.update_weight() ##set_activations(catc11) ##for thing in node1: ##    thing.update_weight() ##set_activations(catc12) ##for thing in node1: ##    thing.update_weight() ##set_activations(catd11) ##for thing in node1: ##    thing.update_weight() ##set_activations(catd12) ##for thing in node1: ##    thing.update_weight()  ####################################################################################### # #                                        updating network # #######################################################################################  in layer1:     i.update_input()     print 'node', str(i), 'input : ', i.net_input in layer1:     i.update_activation()     print 'act:', i.activation in layer1:     i.update_output()     print 'output', i.net_output in layer2:     i.update_input()     print 'node', str(i), 'input : ', i.net_input in layer2:     i.update_activation()     print 'act:', i.activation 

neural network structure

i believe you've misunderstood how neural network structure build up. of input values should sent neurons in subsequent layer. of 10 input signals should sent 8 of neurons. please see appended graphics. i've included connections few of neurons make drawing easier understand.

graphical representation

enter image description here


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -