Page 1 of 2
Love crashing when flattening nested tables
Posted: Sat Feb 20, 2010 10:59 pm
by DustinEwan
I'm trying to flatten some nested tables. Well, I'm actually not flatting nested tables, just extracting the data from the innermost nested table into a flat table.
The code in question is:
Code: Select all
function NeuralNetwork:GetWeights()
-- Initialize Empty Weights Table
Weights = {}
-- Iterate Layers, Then Neurons, Then Weights
for i,layer in ipairs(self.Layers) do
for j,neuron in ipairs(layer.Neurons) do
for k,weight in ipairs(neuron.InputWeights) do
-- Add each weight to our Weights table
table.insert(Weights, weight)
end
end
end
return Weights
end
This causes Love to hard crash, no error.
Can anybody help?
Re: Love crashing when flattening nested tables
Posted: Sat Feb 20, 2010 11:32 pm
by kikito
Hi there!
The code looks good. If you get no error, how do you know that the error is there, and not somewhere else?
Have you tried "printing" everything already? (i.e. print('entering layer ' .. i) ... print('entering neuron ' .. j) etc. This will tell you where it is failing.
Finally, how many objects are we talking about? Maybe it is just a problem of memory overflowing.
Re: Love crashing when flattening nested tables
Posted: Sat Feb 20, 2010 11:38 pm
by DustinEwan
I tried printing, but Love doesn't return to the draw function until that function has finished executing, so I get no output. I tested that this function was what was causing the crash by commenting everything else and having love.update only call this function. No function call, no crash.
As for memory overflow, I wouldn't imagine that would be the case. For the size of the network I'm using (very small) there should only be 96 weights in the table once it has finished flattening (4 weights per neuron, 8 neurons per layer, 3 layers of neurons). That seems like a small number to me.. way too small for a memory overflow.
Re: Love crashing when flattening nested tables
Posted: Sat Feb 20, 2010 11:54 pm
by kikito
I tried printing, but Love doesn't return to the draw function until that function has finished executing, so I get no output. I tested that this function was what was causing the crash by commenting everything else and having love.update only call this function. No function call, no crash.
I meant the *other* print. On the console, not on the canvas. Just "print", not "love.graphics.print".
If you are on windows, you might have to activate the console in the
config file in order to see its output.
Re: Love crashing when flattening nested tables
Posted: Sat Feb 20, 2010 11:56 pm
by DustinEwan
hehe... oopsie. I see
Well, lemme give that a try. I was just using default config. Could you enable the console in 0.5?
Re: Love crashing when flattening nested tables
Posted: Sun Feb 21, 2010 12:03 am
by DustinEwan
Oh wow, that was quite revealing.
Each neuron was only supposed to have 4 weights... but apparently it had 4080 o.O
Wonder what the hell was causing that...
Well, time to debug that. Thanks for the trick!
Re: Love crashing when flattening nested tables
Posted: Sun Feb 21, 2010 12:08 am
by kikito
Glad I could help!
By the way, what are you up to? Neural networks? Are you programming Bartbes 2.0 ?
Re: Love crashing when flattening nested tables
Posted: Sun Feb 21, 2010 7:54 am
by Robin
kikito wrote:Are you programming Bartbes 2.0 ?
Another bartbes? Dear heavens, please, no! One is quite enough.
Re: Love crashing when flattening nested tables
Posted: Sun Feb 21, 2010 9:27 am
by bartbes
My Neural Networking attempts failed (well, they might have worked, they just didn't the way I wanted them to work), so he's not me...
Re: Love crashing when flattening nested tables
Posted: Sun Feb 21, 2010 5:54 pm
by DustinEwan
Well, I don't really know what Bartbes is, let alone 2.0, but I'm just going for a simple Neural Network and genetic algorithm.
I'll release the source code when I'm satisfied, but it's mostly just for learning/fun.