}
@Override
public synchronized void build() {
Connections c = Connections.getInstance();
Stack<IHiddenLayer> temp = new Stack<IHiddenLayer>();
while (!layers.empty()) {
temp.push(layers.pop());
}
for (int i = 0; i < numHidden; i++) {
IHiddenLayer h = new HiddenLayer(layerSizes[i]);
h.build();
layers.push(h);
}
while (!temp.empty()) {
layers.push(temp.pop());
}
inputLayer.build();
Iterator<IHiddenLayer> i = layers.iterator();
while (i.hasNext()) {
i.next().build();
}
outputLayer.build();
if (!layers.isEmpty()) {
//Connect input layer to first hidden layer.
c.create(inputLayer, layers.get(0));
//Connect each hidden layer to its child hidden layer.
if (layers.size() >= 2) {
i = layers.iterator();
while (i.hasNext()) {
IHiddenLayer layer = i.next();
if (i.hasNext()) {
c.create(layer, i.next());
}
}
}
//Connect the output layer to the last hidden layer.
c.create(outputLayer, layers.get(layers.size() - 1));
} else {
c.create(inputLayer, outputLayer);
}
}