public void GenerateTest()
        {
            UniformContinuousDistribution target = new UniformContinuousDistribution(2, 5);

            double[] samples = target.Generate(1000000);

            var actual = UniformContinuousDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(2, actual.Minimum, 1e-4);
            Assert.AreEqual(5, actual.Maximum, 1e-4);
        }
Пример #2
0
        public void RNGVentura_LillieforsTest_Has_Significant_Deviation_From_Normal_Distribution()
        {
            double[] sample = GenerateFloatingPointNumberArray();

            var distribution  = UniformContinuousDistribution.Estimate(sample);
            var ndistribution = NormalDistribution.Estimate(sample);

            var lillie  = new LillieforsTest(sample, distribution);
            var nlillie = new LillieforsTest(sample, ndistribution);

            // no significant deviation from a uniform continuous distribution estimate
            lillie.Significant.Should().BeFalse();
            // significant deviation from a normal distribution
            nlillie.Significant.Should().BeTrue();
        }
Пример #3
0
        public void KolmogorovSmirnovTestConstructorTest_with_reestimation()
        {
            #region doc_uniform
            // Test against a Uniform distribution fitted from the data

            // Make this example reproducible
            Accord.Math.Random.Generator.Seed = 1;

            // Suppose we got a new sample, and we would like to test whether this
            // sample seems to have originated from a uniform continuous distribution.
            //
            double[] sample =
            {
                0.021, 0.003, 0.203, 0.177, 0.910, 0.881, 0.929, 0.180, 0.854, 0.982
            };

            // First, we create the distribution we would like to test against:
            //
            var distribution = UniformContinuousDistribution.Estimate(sample);

            // Now we can define our hypothesis. The null hypothesis is that the sample
            // comes from a standard uniform distribution, while the alternate is that
            // the sample is not from a standard uniform distribution.
            //
            var lillie = new LillieforsTest(sample, distribution, iterations: 10 * 1000 * 1000);

            double statistic = lillie.Statistic;   // 0.36925
            double pvalue    = lillie.PValue;      // 0.09057

            bool significant = lillie.Significant; // false

            // Since the null hypothesis could not be rejected, then the sample
            // can perhaps be from a uniform distribution. However, please note
            // that this doesn't means that the sample *is* from the uniform, it
            // only means that we could not rule out the possibility.
            #endregion

            Assert.AreEqual(distribution, lillie.TheoreticalDistribution);
            Assert.AreEqual(KolmogorovSmirnovTestHypothesis.SampleIsDifferent, lillie.Hypothesis);
            Assert.AreEqual(DistributionTail.TwoTail, lillie.Tail);

            Assert.AreEqual(0.36925434116445355, statistic, 1e-16);
            Assert.AreEqual(0.090571500000000027, pvalue, 5e-3);

            Assert.IsFalse(lillie.Significant);
        }
        public void GenerateTest2()
        {
            UniformContinuousDistribution target = new UniformContinuousDistribution(-1, 4);

            double[] samples = new double[1000000];
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = target.Generate();
            }

            var actual = UniformContinuousDistribution.Estimate(samples);

            actual.Fit(samples);

            Assert.AreEqual(-1, actual.Minimum, 1e-4);
            Assert.AreEqual(4, actual.Maximum, 1e-4);
        }
        public void tf_random_uniform()
        {
            using (var K = new TensorFlowBackend())
            {
                #region doc_random_uniform
                var kvar = K.random_uniform(new int[] { 100, 2000 }, minval: -4, maxval: 2, dtype: DataType.Double, seed: 1337, name: "uni");
                var a    = K.dtype(kvar); // float64 (Double)
                var b    = kvar.eval();
                #endregion

                double[,] actual = (double[, ])b;
                Assert.AreEqual(100, actual.Rows());
                Assert.AreEqual(2000, actual.Columns());

                var u = UniformContinuousDistribution.Estimate(actual.Reshape());
                Assert.AreEqual(-4, u.Minimum, 1e-3);
                Assert.AreEqual(+2, u.Maximum, 1e-3);
                Assert.AreEqual(-1, u.Mean, 1e-2);
            }
        }