예제 #1
0
        private void Initialize() {
            population = new Chromosome[Settings.Instance.PopulationSize];

            for (int i = 0; i < population.Length; i++) {
                population[i] = new Chromosome();
                population[i].Initialize(random);
            }
        }
예제 #2
0
        private void Crossover() {
            Chromosome[] newPopulation = new Chromosome[population.Length];
            int i = 0;

            foreach (Chromosome a in parents)
                foreach (Chromosome b in parents)
                    newPopulation[i++] = a.Crossover(b);

            population = newPopulation;
        }
예제 #3
0
        public Chromosome Crossover(Chromosome other) {
            int[] newLayersSizes = new int[(LayersSizes.Length + other.LayersSizes.Length) / 2];

            for (int i = 0; i < newLayersSizes.Length; i++) {
                double f = newLayersSizes.Length > 1 ? (double)i / (newLayersSizes.Length - 1) : 0.5;

                int? a = Interpolate(LayersSizes, f);
                int? b = Interpolate(other.LayersSizes, f);

                if (a == null)
                    a = b;
                else if (b == null)
                    b = a;

                newLayersSizes[i] = (int)(a + b) / 2;
            }

            return new Chromosome(newLayersSizes, (LearningRate + other.LearningRate) / 2);
        }