public MultiLayerNeuralNet(MultiLayerNeuralNet pattern) { // Copy input layer wages. this.wagesBetweenInputAndFirstHiddenLayer = new float [pattern.wagesBetweenInputAndFirstHiddenLayer.GetLength(0), pattern.wagesBetweenInputAndFirstHiddenLayer.GetLength(1)]; Array.Copy( pattern.wagesBetweenInputAndFirstHiddenLayer, this.wagesBetweenInputAndFirstHiddenLayer, pattern.wagesBetweenInputAndFirstHiddenLayer.GetLength(0) * pattern.wagesBetweenInputAndFirstHiddenLayer.GetLength(1)); //Copy hidden layers wages and biases. this.wagesBetweenHiddenLayers = new float[pattern.wagesBetweenHiddenLayers.GetLength(0)][, ]; for (int i = 0; i < this.wagesBetweenHiddenLayers.Length; i++) { this.wagesBetweenHiddenLayers[i] = new float[pattern.wagesBetweenHiddenLayers[i].GetLength(0), pattern.wagesBetweenHiddenLayers[i].GetLength(1)]; Array.Copy( pattern.wagesBetweenHiddenLayers[i], this.wagesBetweenHiddenLayers[i], pattern.wagesBetweenHiddenLayers[i].GetLength(0) * pattern.wagesBetweenHiddenLayers[i].GetLength(1)); } this.biasesInHiddenLayers = new float[pattern.biasesInHiddenLayers.Length][]; for (int i = 0; i < this.biasesInHiddenLayers.Length; i++) { this.biasesInHiddenLayers[i] = new float[pattern.biasesInHiddenLayers[i].Length]; Array.Copy( pattern.biasesInHiddenLayers[i], this.biasesInHiddenLayers[i], pattern.biasesInHiddenLayers[i].Length); } // Copy output layer wages and biases. this.wagesBetweenLastHiddenAndOutputLayer = new float [pattern.wagesBetweenLastHiddenAndOutputLayer.GetLength(0), pattern.wagesBetweenLastHiddenAndOutputLayer.GetLength(1)]; Array.Copy( pattern.wagesBetweenLastHiddenAndOutputLayer, this.wagesBetweenLastHiddenAndOutputLayer, pattern.wagesBetweenLastHiddenAndOutputLayer.GetLength(0) * pattern.wagesBetweenLastHiddenAndOutputLayer.GetLength(1)); this.biasesInOutputLayer = new float[pattern.biasesInOutputLayer.Length]; Array.Copy( pattern.biasesInOutputLayer, this.biasesInOutputLayer, pattern.biasesInOutputLayer.Length); // Copy activation function this.activationFunction = pattern.activationFunction; }
public INeuralNet Crossover(INeuralNet other) { if (other is MultiLayerNeuralNet == false) { throw new ApplicationException("'other' should be of type COneLayerNeuralNet to be able to crossover with COneLayerNeuralNet."); } var child = new MultiLayerNeuralNet( this.wagesBetweenInputAndFirstHiddenLayer.GetLength(0), this.wagesBetweenLastHiddenAndOutputLayer.GetLength(1), this.wagesBetweenInputAndFirstHiddenLayer.GetLength(1), this.wagesBetweenHiddenLayers.Length + 1); var castedOther = other as MultiLayerNeuralNet; child.wagesBetweenInputAndFirstHiddenLayer = CrossoverHelper.Crossover(this.wagesBetweenInputAndFirstHiddenLayer, castedOther.wagesBetweenInputAndFirstHiddenLayer); for (int i = 0; i < this.wagesBetweenHiddenLayers.Length; i++) { child.wagesBetweenHiddenLayers[i] = CrossoverHelper.Crossover(this.wagesBetweenHiddenLayers[i], castedOther.wagesBetweenHiddenLayers[i]); } for (int i = 0; i < this.biasesInHiddenLayers.Length; i++) { child.biasesInHiddenLayers[i] = CrossoverHelper.Crossover(this.biasesInHiddenLayers[i], castedOther.biasesInHiddenLayers[i]); } child.wagesBetweenLastHiddenAndOutputLayer = CrossoverHelper.Crossover(this.wagesBetweenLastHiddenAndOutputLayer, castedOther.wagesBetweenLastHiddenAndOutputLayer); child.biasesInOutputLayer = CrossoverHelper.Crossover(this.biasesInOutputLayer, castedOther.biasesInOutputLayer); return(child); }