// Unit Tested public NeuralNetwork CreateNetwork(bool bestOfAll = false, bool leader = false) { //newPerceptronsObjects.Clear(); while (perceptrons.Count < newPerceptronsObjects.Count) { newPerceptronsObjects.RemoveAt(newPerceptronsObjects.Count - 1); } for (int i = 0; i < this.perceptrons.Count; i++) { if (i < newPerceptronsObjects.Count) { newPerceptronsObjects[i].SetPerceptron(perceptrons[i]); } else { Perceptron perceptron = new Perceptron(perceptrons[i]); newPerceptronsObjects.Add(perceptron); } } for (int i = 0; i < connections.Count; i++) { if (connections[i].enabled) { Perceptron from = null; Perceptron to = null; int index; index = GetElementPos(connections[i].from); from = newPerceptronsObjects[index]; index = GetElementPos(connections[i].to); to = newPerceptronsObjects[index]; from.AddOutLink(connections[i].weight, from, to, connections[i].recurrent); to.AddInLink(connections[i].weight, from, to, connections[i].recurrent); } } for (int i = 0; i < newPerceptronsObjects.Count; i++) { newPerceptronsObjects[i].Finish(); } if (network != null) { network.SetNeuralNetwork(ref newPerceptronsObjects, inputs, bestOfAll, leader); } else { network = new NeuralNetwork(ref newPerceptronsObjects, inputs, bestOfAll, leader); } return(network); }