We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Reading from a grid
Page Index Toggle Pages: 1
Reading from a grid (Read 735 times)
Reading from a grid
Sep 17th, 2005, 1:31pm
 
I'm having a crack at making a neural net again.

I'm feeding the dendrites of each Cell with the outputs of four axons below.

Basically each layer of Cells feeds a grid layer above it that measures half the width and half the height. So In order to feed the next layer I need a method for the section of brain (I've dubbed the class Lobe) to pass the info to the next layer.

The layer[i][j] array is simply a multi-dimensional array whose second dimension can be calculated as sq(2^i) (layer 0 = 1, layer 2 = 4, layer 3 = 16, etc.).

So far so good. I even managed to write in an equation to derive the layers from the logarithm of the base layer.

When it came to feeding the dendrites however I came a little unstuck. Each cell has the properties of id and layerSize - so I can determine rows and columns. But my final solution is really clunky:

Code:

void synapse(int i){
//read axons from layer i+1 and enter values into dendrites of layer i
for(int j = 0; j < layer[i].length; j++){
for(int k = 0; k < layer[i][j].dendrite.length; k++){
int r = layer[i][j].row();
int c = layer[i][j].column();
int nextLayerSize = int(sqrt(layer[i+1].length));
//int pos0 = (r*2)+((c*2)*nextLayerSize);
switch(k){
case 0:
layer[i][j].dendrite[k] = layer[i+1][(r*2)+((c*2)*nextLayerSize)].axon;
break;
case 1:
layer[i][j].dendrite[k] = layer[i+1][(r*2)+1+((c*2)*nextLayerSize)].axon;
break;
case 2:
layer[i][j].dendrite[k] = layer[i+1][(r*2)+((c*2)+1*nextLayerSize)].axon;
break;
case 3:
layer[i][j].dendrite[k] = layer[i+1][(r*2)+1+((c*2)+1*nextLayerSize)].axon;
break;
}
}
}
}

-update: whoops - shoulda tested the syntax - it works now

I'm pretty sure there's a shorthand equation for referencing those axons in the layer below with out having to do the longhand version of doubling up the rows and columns and using a switch to access each bit. I'm fine for testing of course - I'd just like some smooth equations instead of this booger code.

Anybody with a math education capable of helping me please?
Re: Reading from a grid
Reply #1 - Sep 18th, 2005, 4:39pm
 
Nevermind:
Code:

int baseUnit = 4;
int [][] grid;
PFont font;
void setup(){
size(550,400,P3D);
font = loadFont("BitstreamVeraSans-Roman-48.vlw");
textFont(font,12);
grid = new int[2][];
grid[0] = new int[int(pow(baseUnit,2))];
grid[1] = new int[int(pow(baseUnit,4))];
for(int j = 0; j < grid[0].length; j++){
grid[0][j] = 0;
}
for(int j = 0; j < grid[1].length; j++){
grid[1][j] = int(random(4));
}

}
void draw(){
background(50);
drawGrid(0,50,50,100,100);
drawGrid(1,200,50,300,300);
}
void mousePressed(){
upload(0);
}
void upload(int i){
int baseLength = int(sqrt(grid[i].length));
int sourceLength = int(sqrt(grid[i+1].length));
for (int j = 0; j < grid[i].length; j++){
int sourceStart = ((j % baseLength) * baseLength) + (((j / baseLength) * baseLength) * sourceLength);
int sourceEnd = sourceStart+(sourceLength*baseLength);
for (int k = sourceStart; k < sourceEnd; k += sourceLength){
for (int m = 0; m < baseLength; m++){
println(k+m);
grid[i][j] += grid[i+1][k+m];
}
}
println("coda");
}
}
void drawGrid(int gridNumber, float x, float y, float w, float h){
int sideLength = int(sqrt(grid[gridNumber].length));
float xStep = w/sideLength;
float yStep = h/sideLength;
for(int i = 0; i < sideLength; i++){
for(int j = 0; j < sideLength; j++){
text(grid[gridNumber][i+j*sideLength],x+(xStep*i),y+(yStep*j));
}
}
}

Took me two and half A4 pages to figure it out.

Someone could adapt this for Sudoku I guess Tongue
Page Index Toggle Pages: 1