public INeuralNet Crossover(INeuralNet other) { if (other is OneLayerNeuralNet == false) { throw new ApplicationException("'other' should be of type COneLayerNeuralNet to be able to crossover with COneLayerNeuralNet."); } var child = new OneLayerNeuralNet(this.wages.GetLength(0), this.wages.GetLength(1)); child.wages = CrossoverHelper.Crossover(this.wages, (other as OneLayerNeuralNet).wages); child.biasesInOutputLayer = CrossoverHelper.Crossover(this.biasesInOutputLayer, (other as OneLayerNeuralNet).biasesInOutputLayer); return(child); }
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); }