public void MutationDistributionDoesNotDepartFromNormalDistributionInLogSpace() { // Build up unbounded domain. var domain = new LogDomain(1.0 / double.MaxValue, double.MaxValue); // Fix the value to mutate and the variance percentage. Allele <double> valueToMutate = new Allele <double>(3.4); double variancePercentage = 0.000001; // Collect results in log space for a lot of mutations. int numberRuns = 1000; double[] mutationsInLogSpace = new double[numberRuns]; for (int i = 0; i < numberRuns; i++) { mutationsInLogSpace[i] = Math.Log((double)domain.MutateGeneValue(valueToMutate, variancePercentage).GetValue()); } // Apply the Kolmogorov-Smirnov test. double stdDev = Math.Sqrt(variancePercentage * (Math.Log(domain.Maximum) - Math.Log(domain.Minimum))); KolmogorovSmirnovTest normalityTest = new KolmogorovSmirnovTest( sample: mutationsInLogSpace, hypothesizedDistribution: new NormalDistribution(mean: Math.Log(valueToMutate.GetValue()), stdDev: stdDev)); Assert.False( double.IsNaN(normalityTest.PValue) || normalityTest.Significant, $"Mutation was found to be not normal by the Kolmogorov-Smirnov test with significance level of {normalityTest.Size}."); }
public void MutationStaysInDomain() { // Initialize bounded domain. var domain = new LogDomain(LogDomainTest.minimum, LogDomainTest.maximum); // Fix the value to mutate and the variance percentage. Allele <double> valueToMutate = new Allele <double>(LogDomainTest.maximum - 1); double variancePercentage = 1.0; // For a lot of tries: int numberRuns = 1000; for (int i = 0; i < numberRuns; i++) { // Mutate and check that the mutated value is in the domain. IAllele mutatedGeneValue = domain.MutateGeneValue(valueToMutate, variancePercentage); Assert.True( domain.ContainsGeneValue(mutatedGeneValue), $"Value {mutatedGeneValue} was generated by mutation and is not contained in {domain}"); } }