Esempio n. 1
0
        public void SetWithDoubleArrayChromosome(DoubleArrayChromosome daChromosome)
        {
            int count = 0;
            double[] chromosomeGenes = daChromosome.Value;
            // asign new weights and thresholds to network from the given chromosome
            for (int i = 0, layersCount = Layers.Length; i < layersCount; i++)
            {
                Layer layer = Layers[i];

                for (int j = 0; j < layer.Neurons.Length; j++)
                {
                    ActivationNeuron neuron = layer.Neurons[j] as ActivationNeuron;

                    for (int k = 0; k < neuron.Weights.Length; k++)
                    {
                        neuron.Weights[k] = chromosomeGenes[count++];
                    }
                    neuron.Threshold = chromosomeGenes[count++];
                }
            }
        }
Esempio n. 2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="DoubleArrayChromosome"/> class.
		/// </summary>
		/// 
		/// <param name="source">Source chromosome to copy.</param>
		/// 
		/// <remarks><para>This is a copy constructor, which creates the exact copy
		/// of specified chromosome.</para></remarks>
		/// 
		public DoubleArrayChromosome(DoubleArrayChromosome source)
		{
			this.chromosomeGenerator = source.chromosomeGenerator;
			this.mutationMultiplierGenerator = source.mutationMultiplierGenerator;
			this.mutationAdditionGenerator = source.mutationAdditionGenerator;
			this.length = source.length;
			this.fitness = source.fitness;
			this.mutationBalancer = source.mutationBalancer;
			this.crossoverBalancer = source.crossoverBalancer;

			// copy genes
			val = (double[])source.val.Clone();
		}