정수값을 변량으로 균일하게 이산 분포를 합니다.. 이 분포는 상하한 값을 포함합니다. Wikipedia - Discrete uniform distribution.

The distribution will use the System.Random by default. Users can set the random number generator by using the RandomSource property.

The statistics classes will check all the incoming parameters whether they are in the allowed range. This might involve heavy computation. Optionally, by setting Control.CheckDistributionParameters to false, all parameter checks can be turned off.

Inheritance: IDiscreteDistribution
        public void CreateDiscreteUniformTest([Values(-10, 0, 10, 20)] int lower,
                                              [Values(10, 4, 20, 20)] int upper) {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.LowerBound.Should().Be(lower);
            uniform.UpperBound.Should().Be(upper);
        }
        public void SamplesDistributionTest()
        {
            var source =
                DiscreteUniform.Samples(MathTool.GetRandomFactory()(), 0, 10).AsParallel().Take(99999).Select(x => (double)x).ToList();
            var histogram = new Histogram(source, 11, 0, 11);

            DisplayDistribution("DiscreteUniform", histogram);
        }
        public void StaticSampleUniform()
        {
            DiscreteUniform.Sample(new Random(), 0, 10).Should().Be.GreaterThanOrEqualTo(0).And.Be.LessThanOrEqualTo(10);
            DiscreteUniform.Samples(new Random(), 0, 10).Take(10).Where(x => x >= 0 && x <= 10).Count().Should().Be(10);

            Assert.Throws <InvalidOperationException>(() => DiscreteUniform.Sample(new Random(), 10, 0));
            Assert.Throws <InvalidOperationException>(() => DiscreteUniform.Samples(new Random(), 10, 0).First());
        }
        public void CreateDiscreteUniformTest([Values(-10, 0, 10, 20)] int lower,
                                              [Values(10, 4, 20, 20)] int upper)
        {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.LowerBound.Should().Be(lower);
            uniform.UpperBound.Should().Be(upper);
        }
        public void ProbabilityTest([Values(-10, -10, -10, -10, -10)] int lower,
                                    [Values(10, 10, 10, -10, -10)] int upper,
                                    [Values(-5, 1, 10, 0, -10)] int x,
                                    [Values(1 / 21.0, 1 / 21.0, 1 / 21.0, 0.0, 1.0)] double p) {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Probability(x).Should().Be(p);
        }
        public void ProbabilityTest([Values(-10, -10, -10, -10, -10)] int lower,
                                    [Values(10, 10, 10, -10, -10)] int upper,
                                    [Values(-5, 1, 10, 0, -10)] int x,
                                    [Values(1 / 21.0, 1 / 21.0, 1 / 21.0, 0.0, 1.0)] double p)
        {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Probability(x).Should().Be(p);
        }
        public void CumulativeDistributionTest([Values(-10, -10, -10, -10, -10, -10)] int lower,
                                               [Values(10, 10, 10, -10, -10, -10)] int upper,
                                               [Values(-5, 1, 10, 0, -10, -11)] double x,
                                               [Values(6.0 / 21.0, 12.0 / 21.0, 1.0, 1.0, 1.0, 0.0)] double cdf)
        {
            var b = new DiscreteUniform(lower, upper);

            Assert.AreEqual(cdf, b.CumulativeDistribution(x));
        }
        public void SampleTest([Values(-10, 0, 10, 20)] int lower,
                               [Values(10, 4, 20, 20)] int upper) {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Sample().Should()
                .Be.GreaterThanOrEqualTo(lower)
                .And
                .Be.LessThanOrEqualTo(upper);
        }
        public void SampleTest([Values(-10, 0, 10, 20)] int lower,
                               [Values(10, 4, 20, 20)] int upper)
        {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Sample().Should()
            .Be.GreaterThanOrEqualTo(lower)
            .And
            .Be.LessThanOrEqualTo(upper);
        }
示例#10
0
        public void ValidateDistributionProperties([Range(-10, 10, 2)] int lower, [Range(100, 110, 2)] int upper) {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Entropy.Should().Be(Math.Log(upper - lower + 1.0));
            uniform.Skewness.Should().Be(0);
            uniform.Kurtosis.Should().Be(0);
            uniform.Mode.Should().Be((lower + upper) / 2);
            uniform.Median.Should().Be(uniform.Mode);

            uniform.Minumum.Should().Be(lower);
            uniform.Maximum.Should().Be(upper);
        }
        public void ValidateDistributionProperties([Range(-10, 10, 2)] int lower, [Range(100, 110, 2)] int upper)
        {
            var uniform = new DiscreteUniform(lower, upper);

            uniform.Entropy.Should().Be(Math.Log(upper - lower + 1.0));
            uniform.Skewness.Should().Be(0);
            uniform.Kurtosis.Should().Be(0);
            uniform.Mode.Should().Be((lower + upper) / 2);
            uniform.Median.Should().Be(uniform.Mode);

            uniform.Minumum.Should().Be(lower);
            uniform.Maximum.Should().Be(upper);
        }
        public void SetUpperBoundWithInvalidParameters([Values(-1, -2)] int upper)
        {
            var uniform = new DiscreteUniform(0, 10);

            Assert.Throws <InvalidOperationException>(() => uniform.UpperBound = upper);
        }
        public void SetLowerBoundWithInvalidParameters([Values(11, 20)] int lower)
        {
            var uniform = new DiscreteUniform(0, 10);

            Assert.Throws <InvalidOperationException>(() => uniform.LowerBound = lower);
        }
示例#14
0
 public void SetUpperBoundWithInvalidParameters([Values(-1, -2)] int upper) {
     var uniform = new DiscreteUniform(0, 10);
     Assert.Throws<InvalidOperationException>(() => uniform.UpperBound = upper);
 }
示例#15
0
 public void SetLowerBoundWithInvalidParameters([Values(11, 20)] int lower) {
     var uniform = new DiscreteUniform(0, 10);
     Assert.Throws<InvalidOperationException>(() => uniform.LowerBound = lower);
 }
示例#16
0
 public void CumulativeDistributionTest([Values(-10, -10, -10, -10, -10, -10)] int lower,
                                        [Values(10, 10, 10, -10, -10, -10)] int upper,
                                        [Values(-5, 1, 10, 0, -10, -11)] double x,
                                        [Values(6.0 / 21.0, 12.0 / 21.0, 1.0, 1.0, 1.0, 0.0)] double cdf) {
     var b = new DiscreteUniform(lower, upper);
     Assert.AreEqual(cdf, b.CumulativeDistribution(x));
 }