public void ValueIsStoredCorrectly() { int a = 4; var allele = new Allele <int>(a); Assert.Equal(a, allele.GetValue()); }
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 MutationDistributionDoesNotDepartFromNormalDistribution() { // Build up unbounded domain. this._continuousDomain = new ContinuousDomain(); // Fix the value to mutate and the variance percentage. Allele <double> valueToMutate = new Allele <double>(3.4); // Divide by 2 to prevent overflows. Want: 0.5 / (max - min) double variancePercentage = (0.5 / 2) / ((this._continuousDomain.Maximum / 2) - (this._continuousDomain.Minimum / 2)); // Collect results of a lot of mutations. double[] mutations = new double[ContinuousDomainTest.TriesForRandomTests]; for (int i = 0; i < ContinuousDomainTest.TriesForRandomTests; i++) { mutations[i] = (double)this._continuousDomain.MutateGeneValue(valueToMutate, variancePercentage).GetValue(); } // Apply the Kolmogorov-Smirnov test. double stdDev = Math.Sqrt(0.5); KolmogorovSmirnovTest normalityTest = new KolmogorovSmirnovTest( sample: mutations, hypothesizedDistribution: new NormalDistribution(mean: 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 GenerateRandomGeneValueDoesNotDepartFromUniformDistributionInLogSpace() { // Build up logarithmically spaced domain from e to e^10. double minimumExponent = 1; double maximumExponent = 10; var domain = new LogDomain(Math.Exp(minimumExponent), Math.Exp(maximumExponent)); // Collect results of value generation. int numberRuns = 10000; double[] generatedValues = new double[numberRuns]; for (int i = 0; i < numberRuns; i++) { Allele <double> generated = domain.GenerateRandomGeneValue(); generatedValues[i] = Math.Log(generated.GetValue()); } // Apply the Anderson-Darling test. AndersonDarlingTest uniformTest = new AndersonDarlingTest( generatedValues, new UniformContinuousDistribution(minimumExponent, maximumExponent)); Assert.False( uniformTest.Significant, $"Random generation was found to be not uniform in log space by the Anderson-Darling test with significance level of {uniformTest.Size}."); }
public void GenerateRandomGeneValueDoesNotDepartFromUniformDistribution() { // Create domain. ContinuousDomain domain = new ContinuousDomain(ContinuousDomainTest.minimum, ContinuousDomainTest.maximum); // Collect results of value generation. double[] generatedValues = new double[ContinuousDomainTest.TriesForRandomTests]; for (int i = 0; i < ContinuousDomainTest.TriesForRandomTests; i++) { Allele <double> generated = domain.GenerateRandomGeneValue(); generatedValues[i] = generated.GetValue(); } // Apply the Anderson-Darling test. AndersonDarlingTest uniformTest = new AndersonDarlingTest(generatedValues, new UniformContinuousDistribution(ContinuousDomainTest.minimum, ContinuousDomainTest.maximum)); Assert.False( uniformTest.Significant, $"Random generation was found to be not uniform by the Anderson-Darling test with significance level of {uniformTest.Size}."); }