// Constructeurs public gene(int[] sizes) { this.sizes = sizes; this.layersNumber = sizes.Length - 1; this.inputSize = sizes[0]; this.outputSize = sizes[layersNumber]; this.layers = new geneLayer[layersNumber]; // On génère des couches aléatoires for (int i = 0; i < layersNumber; i++) { layers[i] = new geneLayer(sizes[i], sizes[i + 1]); } }
public static gene weightedAverage(gene[] genes, float[] weights) { // On moyenne toutes les couches // On considère que tous les gènes ont la même structure int layersNb = genes[0].layersNumber; int genesNb = genes.Length; geneLayer[] newLayers = new geneLayer[layersNb]; for (int iLayer = 0; iLayer < layersNb; iLayer++) { geneLayer[] toAverage = new geneLayer[genesNb]; for (int iGene = 0; iGene < genesNb; iGene++) { toAverage[iGene] = genes[iGene].layers[iLayer]; } newLayers[iLayer] = geneLayer.weightedAverage(toAverage, weights); } return(new gene(newLayers)); }