Exemple #1
0
        public virtual void AlterProbability(int ngenes, int nchromosomes, int npopulation, double p)
        {
            var population = TestUtils.NewPermutationDoubleGenePopulation(
                ngenes, nchromosomes, npopulation
                );

            // The mutator to test.
            var crossover = new PartiallyMatchedCrossover <double, double>(p);

            long nallgenes = ngenes * nchromosomes * npopulation;
            long N         = 100;
            var  mean      = crossover.Order * npopulation * p;

            const long min    = 0;
            var        max    = nallgenes;
            var        domain = new Range <long>(min, max);

            var histogram = Histogram.OfLong(min, max, 10);
            var variance  = new LongMomentStatistics();

            for (var i = 0; i < N; ++i)
            {
                long alterations = crossover.Alter(population, 1);
                histogram.Accept(alterations);
                variance.Accept(alterations);
            }

            // Normal distribution as approximation for binomial distribution.
            // TODO: Implement test
//		assertDistribution(
//			histogram,
//			new NormalDistribution<>(domain, mean, variance.getVariance())
//		);
        }
 protected static string P(LongMomentStatistics statistics)
 {
     return(string.Format("max={0}; mean={1:F6}; var={2:F6}", statistics.Max, statistics.Mean,
                          statistics.Variance));
 }