private static IWeightMutationStrategy <double> CreateCardinalGaussianDeltaStrategy( int selectCount, double stdDev) { var selectStrategy = new CardinalSubsetSelectionStrategy(selectCount); return(DeltaWeightMutationStrategy.CreateGaussianDeltaStrategy(selectStrategy, stdDev)); }
public void TestUniformDelta() { double weightScale = 5.0; var strategy = DeltaWeightMutationStrategy.CreateUniformDeltaStrategy( new SelectAllStrategy(), weightScale, RandomDefaults.CreateRandomSource(0)); int iters = 10000; double[] weightArr = new double[iters]; for (int i = 0; i < iters; i++) { weightArr[i] = 1000.0; } strategy.Invoke(weightArr); // Construct a histogram on the array of weights. HistogramData hist = NumericsUtils.BuildHistogramData(weightArr, 8); // We expect samples to be approximately evenly distributed over the histogram buckets. for (int i = 0; i < hist.FrequencyArray.Length; i++) { Assert.IsTrue(hist.FrequencyArray[i] > (iters / 8) * 0.8); } // We expect min and max to be close to 1000-weightScale and 1000+weightScale respectively. Assert.IsTrue(hist.Max <= (1000 + weightScale) && hist.Max > (1000 + weightScale) - 0.1); Assert.IsTrue(hist.Min >= (1000 - weightScale) && hist.Min < (1000 - weightScale) + 0.1); }
public void TestGaussianDelta() { var strategy = DeltaWeightMutationStrategy.CreateGaussianDeltaStrategy( new SelectAllStrategy(), 1.0, RandomDefaults.CreateRandomSource(0)); int iters = 100000; double[] weightArr = new double[iters]; for (int i = 0; i < iters; i++) { weightArr[i] = 1000.0; } strategy.Invoke(weightArr); // Construct a histogram on the array of weights. HistogramData hist = NumericsUtils.BuildHistogramData(weightArr, 8); // We expect min and max to be close to be about -995.5 and +1004.5 respectively // (but they could be further from the mean of 1000, with no bound). Assert.IsTrue(hist.Max >= 1002.0); Assert.IsTrue(hist.Min <= 998.0); TestMean(weightArr, 1000.0); }
private static IWeightMutationStrategy <double> CreateCardinalGaussianDeltaStrategy( int selectCount, double stdDev, IRandomSourceBuilder rngBuilder) { var selectStrategy = new CardinalSubsetSelectionStrategy(selectCount, rngBuilder.Create()); return(DeltaWeightMutationStrategy.CreateGaussianDeltaStrategy(selectStrategy, stdDev, rngBuilder.Create())); }