As the header suggests, I need some help with my program. The problem is included in the code snippet and I think I've included enough to make it runable by itself so you may be able to run it and see what is going on.
If you can't, the problem is after I generate my mass of random numbers. I can print them just fine using my getWeight(index) function if this is done immediately after generating them and storing them. When I attempt to print them after appending that list to a list of lists, i only retrieve the first number (which somehow does not exists in any of the lists) and then get the typical index out of bound exception. The code is as follows:
import wx
import random
from AIUnit import AIUnit
class finalProject(wx.Frame):
global inputUnit
inputUnit = []
#Defines and draws the GIU
def __init__(self, parent, id):
#Defines the frame which contains all GIU panels
wx.Frame.__init__(self, parent, id, "Final Project", size=(800, 600))
#Defines the panel which hold all componants
global panel
panel = wx.Panel(self)
#defines the "exit" button
self.Bind(wx.EVT_CLOSE, self.haltProg)
#defines the new net button
initNetworkButton = wx.Button(panel, label='New Network', pos=(50, 230), size=(80,50))
self.Bind(wx.EVT_BUTTON, self.initialize, initNetworkButton)
#action carried out when clicking "X" on window
def haltProg(self, event):
self.Destroy()
#initializes the network with random weights and proper connections
def initialize(self, event):
global inputUnit
inputUnit = []
#INITIALIZES AND CONSTRUCTS LOWER NETWORKS
#initializes and constructs input layer
for i in range(0, 16, 1): #Number of input blocks
tempUnit = []
for j in range(0, 16, 1): #number of individual input units per block
tempUnit.append(AIUnit())
for k in range(0, 8, 1): #number of connections per input unit
tempUnit[j].setWeight(random.random(), -1)
#print tempUnit[j].getWeight(k) #Print here works
#print str(i) + '-' + str(j) + '-' + str(k) #Counting through all indices works
inputUnit.append(tempUnit)
print inputUnit[i][j].getWeight(7) #print here works
print ''
for i in range(0, 16, 1):
for j in range(0, 16, 1):
for k in range(0, 8, 1):
print str(i) + '-' + str(j) + '-' + str(k) #count breaks at 0-0-1
print inputUnit[i][j].getWeight(k) #printing only returns 1'st number (which isn't actual first number) then breaks
#Auto update/refresh and draw frame
if __name__=='__main__':
app=wx.PySimpleApp()
frame=finalProject(parent=None,id=-1)
frame.Show()
app.MainLoop()
Here is the AIUnit code in its entirety:
#This class acts to track information regarding a node used
# in AI infrastructure (mainly backpropagation networks)
# This was written by Samuel H. Kemp to aid with "Final Project"
class AIUnit:
global output, delta, weight
#This tracks this units most recent output
output = 0
#This tracks this units most recent delta
delta = 0
#This tracks the weights of this units various connections
weight = []
#Initialized the object
def __init__(self):
global output, delta, weight
output = 0
delta = 0
weight = []
#The following set this units various attributes
def setOutput(self, nOutput):
global output
output = nOutput
def setDelta(self, nDelta):
global delta
delta = nDelta
#If index is -1, append a new one to the list
def setWeight(self, nWeight, index):
global weight
if index == -1:
weight.append(nWeight)
else:
weight[index] = nWeight
#The following retieve this units various attributes
def getOutput(self):
global output
return output
def getDelta(self):
global delta
return delta
def getWeight(self, index):
global weight
return weight[index]
Any help would be greatly appreciated.