当前位置: 首页>>代码示例>>C#>>正文


C# Histogram.Add方法代码示例

本文整理汇总了C#中Histogram.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Histogram.Add方法的具体用法?C# Histogram.Add怎么用?C# Histogram.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Histogram的用法示例。


在下文中一共展示了Histogram.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MinMeanMax

        public void MinMeanMax()
        {
            var metric = new Metric();
            metric.Add(10);
            metric.Add(20);
            Assert.That(metric.Count, Is.EqualTo(2));
            Assert.That(metric.Min, Is.EqualTo(10));
            Assert.That(metric.Max, Is.EqualTo(20));
            Assert.That(metric.Mean, Is.EqualTo(15.0d));

            metric.Add(60);

            Assert.That(metric.Count, Is.EqualTo(3));
            Assert.That(metric.Min, Is.EqualTo(10));
            Assert.That(metric.Max, Is.EqualTo(60));
            Assert.That(metric.Mean, Is.EqualTo(30.0d));

            Histogram other = new Histogram();
            other.Add(10);
            other.Add(20);
            other.Add(60);
            CollectionAssert.AreEqual(metric.Histogram.Get(), other.Get());
        }
开发者ID:lovewitty,项目名称:OstrichNet,代码行数:23,代码来源:MetricTests.cs

示例2: HistogramOperations

        public void HistogramOperations()
        {
            Histogram h = new Histogram(new double[] { 1.0, 3.0, 5.0, 7.0 });

            Assert.IsTrue(h.Bins.Count == 3);
            Assert.IsTrue(h.Range == Interval.FromEndpoints(1.0, 7.0));

            Assert.IsTrue(h.BelowRangeBin.Range == Interval.FromEndpoints(Double.NegativeInfinity, 1.0));
            Assert.IsTrue(h.Bins[0].Range == Interval.FromEndpoints(1.0, 3.0));
            Assert.IsTrue(h.Bins[1].Range == Interval.FromEndpoints(3.0, 5.0));
            Assert.IsTrue(h.Bins[2].Range == Interval.FromEndpoints(5.0, 7.0));
            Assert.IsTrue(h.AboveRangeBin.Range == Interval.FromEndpoints(7.0, Double.PositiveInfinity));

            AssertBinCounts(h, new int[] { 0, 0, 0, 0, 0 });

            h.Add(-1.0);
            AssertBinCounts(h, new int[] { 1, 0, 0, 0, 0 });

            h.Add(0.0);
            AssertBinCounts(h, new int[] { 2, 0, 0, 0, 0 });

            h.Add(1.0);
            AssertBinCounts(h, new int[] { 2, 1, 0, 0, 0 });

            h.Add(2.0);
            AssertBinCounts(h, new int[] { 2, 2, 0, 0, 0 });

            h.Add(3.0);
            AssertBinCounts(h, new int[] { 2, 2, 1, 0, 0 });

            h.Add(4.0);
            AssertBinCounts(h, new int[] { 2, 2, 2, 0, 0 });

            h.Add(5.0);
            AssertBinCounts(h, new int[] { 2, 2, 2, 1, 0 });

            h.Add(6.0);
            AssertBinCounts(h, new int[] { 2, 2, 2, 2, 0 });

            h.Add(7.0);
            AssertBinCounts(h, new int[] { 2, 2, 2, 2, 1 });

            h.Add(8.0);
            AssertBinCounts(h, new int[] { 2, 2, 2, 2, 2 });

            Assert.IsTrue(h.TotalCounts == 10);
            //Assert.IsTrue(h.OutOfRangeCounts == 4);

            h.Clear();
            AssertBinCounts(h, new int[] { 0, 0, 0, 0, 0 });
            Assert.IsTrue(h.TotalCounts == 0);

            foreach (HistogramBin bin in h.Bins) {
                bin.Increment();
            }
            AssertBinCounts(h, new int[] { 0, 1, 1, 1, 0 });

            foreach (HistogramBin bin in h.Bins) {
                bin.Deincrement();
            }
            AssertBinCounts(h, new int[] { 0, 0, 0, 0, 0 });

            //Assert.IsTrue(h.OutOfRangeCounts == 0);
        }
开发者ID:JackDetrick,项目名称:metanumerics,代码行数:64,代码来源:HistogramTest.cs

示例3: ChiSquareDistribution

        public void ChiSquareDistribution()
        {
            int B = 8;
            Random rng = new Random(0);
            //BinomialDistribution d = new BinomialDistribution(0.25, 6);
            //DiscreteUniformDistribution d = new DiscreteUniformDistribution(0, 4);
            //BernoulliDistribution d = new BernoulliDistribution(0.25);
            DiscreteDistribution d = new PoissonDistribution(2.0);

            Sample s = new Sample();
            ChiSquaredDistribution nullDistribution = null;
            for (int i = 0; i < 512; i++) {

                Histogram h = new Histogram(B);
                for (int j = 0; j < 1024; j++) {
                    int k = d.GetRandomValue(rng);
                    h.Add(k);
                    //if (k < h.Count) h[k].Increment();
                    //h[d.GetRandomValue(rng)].Increment();
                }
                TestResult cr = h.ChiSquaredTest(d);
                nullDistribution = (ChiSquaredDistribution) cr.Distribution;
                //Console.WriteLine(((ChiSquaredDistribution) cr.Distribution).DegreesOfFreedom);
                s.Add(cr.Statistic);

            }

            Console.WriteLine(nullDistribution.DegreesOfFreedom);
            TestResult kr = s.KuiperTest(nullDistribution);
            Console.WriteLine(kr.LeftProbability);
        }
开发者ID:JackDetrick,项目名称:metanumerics,代码行数:31,代码来源:FutureTest.cs

示例4: DiscreteDistributionRandomValues

        public void DiscreteDistributionRandomValues()
        {
            foreach (DiscreteDistribution distribution in distributions) {

                int max;
                if (distribution.Maximum < 128) {
                    max = distribution.Maximum + 1;
                } else {
                    max = (int) Math.Round(distribution.Mean + 2.0 * distribution.StandardDeviation);
                }
                Console.WriteLine("{0} {1}", distribution.GetType().Name, max);

                Histogram h = new Histogram(max);

                Random rng = new Random(314159265);
                for (int i = 0; i < 1024; i++) h.Add(distribution.GetRandomValue(rng));
                TestResult result = h.ChiSquaredTest(distribution);
                Console.WriteLine("{0} {1}", result.Statistic, result.RightProbability);
                Assert.IsTrue(result.RightProbability > 0.05);

            }
        }
开发者ID:JackDetrick,项目名称:metanumerics,代码行数:22,代码来源:DiscreteDistributionTest.cs


注:本文中的Histogram.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。