1

I'm trying to make a type of Neural Network. I am working in Java. I'm looking for speed, so I want to represent my network in a 3D array. The network can basically be represented as weights, so I have

double weights[][][]

where

weights[numberOfLayers][neuronsPerLayer][weightFromThisNeuronToTheOneInTheNextLayer]

So, the weights[numberOfLayers] is totally fine. I want 3 layers, so I'll initialize as weights[3][][], but the number of neurons per layer changes, and the number of connections (the third dimension) is equal to the number of neurons in the next layer.

I know I could initialize the array to the size that fits the largest one, and has lots of extra room for some of them.. however, I really want to be able to use nested for loops and count until the end of an array has been reached.

jonbon
  • 1,142
  • 3
  • 12
  • 37
  • What you described needs to be represented using a tree structure. But you could use this array list implementation. You can ask if are having trouble visualizing this. ArrayList>> neurons = new ArrayList>>(); – Marcin D May 27 '15 at 17:13
  • Won't that significantly decrease the speed, using ArrayList – jonbon May 27 '15 at 17:14
  • Because of speed, I was trying to avoid array list – jonbon May 27 '15 at 17:14
  • Use a tree structure then, http://stackoverflow.com/questions/3522454/java-tree-data-structure. – Marcin D May 27 '15 at 17:15
  • Are trees as fast as arrays? – jonbon May 27 '15 at 17:16
  • Yes, this would be the proper way. But you could still use an arraylist if you know the size of your structure. ArrayLists are only inefficient if you change the array size. – Marcin D May 27 '15 at 17:19
  • Okay, I will know the exact size, the number of layers and nodes within each layer, and the number of connections – jonbon May 27 '15 at 17:21

0 Answers0