示例#1
0
        private static void MeanSquaredDelta_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            double[] a = new double[len];
            double[] b = new double[len];
            sampler.Sample(a);
            sampler.Sample(b);

            // Calc results and compare.
            double expected = PointwiseSumSquaredDelta(a, b) / a.Length;
            double actual   = MathSpan.MeanSquaredDelta(a, b);

            Assert.Equal(expected, actual, 10);
        }
示例#2
0
        private static void SumSquaredDelta_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            float[] a = new float[len];
            float[] b = new float[len];
            sampler.Sample(a);
            sampler.Sample(b);

            // Calc results and compare.
            float expected = PointwiseSumSquaredDelta(a, b);
            float actual   = MathSpan.SumSquaredDelta(a, b);

            Assert.Equal(expected, actual, 3);
        }
示例#3
0
        private static void SumSquaredDelta(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            double[] a = new double[len];
            double[] b = new double[len];
            sampler.Sample(a);
            sampler.Sample(b);

            // Calc results and compare.
            double expected = SumSquaredDelta(a, b);
            double actual   = MathArrayUtils.SumSquaredDelta(a, b);

            Assert.AreEqual(expected, actual, 1e-10);
        }
示例#4
0
        private static void Max_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            double[] a = new double[len];
            sampler.Sample(a);

            // Calc results and compare.
            double expected = PointwiseMax(a);
            double actual   = MathSpan.Max(a);

            Assert.Equal(expected, actual);
        }
示例#5
0
        private static void SumOfSquares_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc array and fill with uniform random noise.
            float[] x = new float[len];
            sampler.Sample(x);

            // Sum the array elements.
            float expected = PointwiseSumOfSquares(x);
            float actual   = MathSpan.SumOfSquares(x);

            // Compare expected and actual sum.
            Assert.Equal(expected, actual, 3);
        }
示例#6
0
        private static void MinMax_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            float[] a = new float[len];
            sampler.Sample(a);

            // Calc results and compare.
            PointwiseMinMax(a, out float expectedMin, out float expectedMax);
            MathSpan.MinMax(a, out float actualMin, out float actualMax);

            Assert.Equal(expectedMin, actualMin, 10);
            Assert.Equal(expectedMax, actualMax, 10);
        }
示例#7
0
        private static void Sum_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc array and fill with uniform random noise.
            double[] x = new double[len];
            sampler.Sample(x);

            // Sum the array elements.
            double expected = PointwiseSum(x);
            double actual   = MathSpan.Sum(x);

            // Compare expected and actual sum.
            Assert.Equal(expected, actual, 12);
        }
示例#8
0
        private static void MinMax(UniformDistributionSampler sampler, int len)
        {
            // Alloc arrays and fill with uniform random noise.
            double[] a = new double[len];
            sampler.Sample(a);

            // Calc results and compare.
            MinMax(a, out double expectedMin, out double expectedMax);
            MathArrayUtils.MinMax(a, out double actualMin, out double actualMax);

            Assert.AreEqual(expectedMin, actualMin, 1e-10);
            Assert.AreEqual(expectedMax, actualMax, 1e-10);
        }
示例#9
0
        private static void Clip_Inner(UniformDistributionSampler sampler, int len)
        {
            // Alloc array and fill with uniform random noise.
            float[] x = new float[len];
            sampler.Sample(x);

            // Clip the elements of the array with the safe routine.
            float[] expected = (float[])x.Clone();
            PointwiseClip(expected, -1.1f, 18.8f);

            // Clip the elements of the array.
            float[] actual = (float[])x.Clone();
            MathSpan.Clip(actual, -1.1f, 18.8f);

            // Compare expected with actual array.
            Assert.True(SpanUtils.Equal <float>(expected, actual));
        }
示例#10
0
        private static void Clip(UniformDistributionSampler sampler, int len)
        {
            // Alloc array and fill with uniform random noise.
            double[] x = new double[len];
            sampler.Sample(x);

            // Clip the elements of the array with the safe routine.
            double[] expected = (double[])x.Clone();
            Clip(expected, -1.1, 18.8);

            // Clip the elements of the array.
            double[] actual = (double[])x.Clone();
            MathArrayUtils.Clip(actual, -1.1, 18.8);

            // Compare expected with actual array.
            Assert.IsTrue(ArrayUtils.Equals(expected, actual));
        }
示例#11
0
        public void Sample()
        {
            int sampleCount = 10_000_000;
            UniformDistributionSampler sampler = new();
            var sampleArr = new double[sampleCount];

            for (int i = 0; i < sampleCount; i++)
            {
                sampleArr[i] = sampler.Sample();
            }

            UniformDistributionTest(sampleArr, 0.0, 1.0);

            // Configure a scale and a signed flag.
            sampler = new UniformDistributionSampler(100.0, true);

            for (int i = 0; i < sampleCount; i++)
            {
                sampleArr[i] = sampler.Sample();
            }

            UniformDistributionTest(sampleArr, -100.0, 100.0);
        }