Compute() public method

Computes (populates) an Histogram mapping with values from a sample.
public Compute ( double values ) : void
values double The values to be binned in the histogram.
return void
Ejemplo n.º 1
0
        /// <summary>
        ///   Creates a histogram of values from a sample.
        /// </summary>
        ///
        /// <param name="values">The values to be binned in the histogram.</param>
        ///
        /// <returns>A histogram reflecting the distribution of values in the sample.</returns>
        ///
        public Histogram FromData(double[] values)
        {
            var hist = new Histogram();

            hist.Compute(values);
            return(hist);
        }
Ejemplo n.º 2
0
        public void ComputeTest2()
        {
            Histogram target = new Histogram();
            double[] data = new double[] { };

            target.Compute(data);

            Assert.AreEqual(0, target.Bins.Count);
            Assert.AreEqual(0.0, target.Range.Min);
            Assert.AreEqual(0.0, target.Range.Max);
        }
Ejemplo n.º 3
0
        public void ComputeTest2()
        {
            HistogramView target = new HistogramView();

            Histogram histogram = new Histogram();
            histogram.Compute(new double[] { 200.0, 200.0, 200.0 });

            target.DataSource = null;

            target.DataSource = histogram;
            target.TrackBar.Maximum = 30;
            target.TrackBar.Minimum = 0;
            target.TrackBar.Value = 21;

            target.DataSource = null;
        }
Ejemplo n.º 4
0
        public void ComputeTest1()
        {
            Histogram target = new Histogram();
            double[] data = new double[] { 200.0, 200.0, 200.0 };

            target.AutoAdjustmentRule = BinAdjustmentRule.Scott;

            target.Compute(data);

            Assert.AreEqual(1, target.Bins.Count);
            Assert.AreEqual(3, target.Bins[0].Value);
            Assert.AreEqual(0.0, target.Bins[0].Width);

            Assert.IsTrue(target.Bins[0].Contains(200));
            Assert.IsFalse(target.Bins[0].Contains(201));

            Assert.AreEqual(target.Bins[0], target.Bins.Search(200));

        }
Ejemplo n.º 5
0
 /// <summary>
 ///   Creates a histogram of values from a sample.
 /// </summary>
 /// 
 /// <param name="values">The values to be binned in the histogram.</param>
 /// 
 /// <returns>A histogram reflecting the distribution of values in the sample.</returns>
 /// 
 public Histogram FromData(double[] values)
 {
     var hist = new Histogram();
     hist.Compute(values);
     return hist;
 }
Ejemplo n.º 6
0
        public void ComputeTest3()
        {
            Histogram target;
            HistogramBin bin;

            double[] values = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 };

            target = new Histogram();
            target.Compute(values, 5);

            Assert.AreEqual(1, target.Range.Min);
            Assert.AreEqual(6, target.Range.Max);

            Assert.AreEqual(5, target.Bins.Count);

            bin = target.Bins[0];
            Assert.AreEqual(1, bin.Value);
            Assert.AreEqual(1.0, bin.Width);
            Assert.IsTrue(bin.Range.Min <= 1 && 1 < bin.Range.Max);
            Assert.IsTrue(bin.Contains(1));
            Assert.IsFalse(bin.Contains(2));
            Assert.AreEqual(bin, target.Bins.Search(1));
            Assert.AreEqual(0, target.Bins.SearchIndex(1));

            bin = target.Bins[1];
            Assert.AreEqual(2.0, bin.Value);
            Assert.AreEqual(1.0, bin.Width);
            Assert.IsTrue(bin.Range.Min <= 2 && 2 < bin.Range.Max);
            Assert.IsTrue(bin.Contains(2));
            Assert.IsFalse(bin.Contains(3));
            Assert.AreEqual(bin, target.Bins.Search(2));
            Assert.AreEqual(1, target.Bins.SearchIndex(2));

            bin = target.Bins[2];
            Assert.AreEqual(4.0, bin.Value);
            Assert.AreEqual(1.0, bin.Width);
            Assert.IsTrue(bin.Range.Min <= 3 && 3 < bin.Range.Max);
            Assert.IsTrue(bin.Contains(3));
            Assert.IsFalse(bin.Contains(4));
            Assert.AreEqual(bin, target.Bins.Search(3));
            Assert.AreEqual(2, target.Bins.SearchIndex(3));

            bin = target.Bins[3];
            Assert.AreEqual(2.0, bin.Value);
            Assert.AreEqual(1.0, bin.Width);
            Assert.IsTrue(bin.Range.Min <= 4 && 4 < bin.Range.Max);
            Assert.IsTrue(bin.Contains(4));
            Assert.IsFalse(bin.Contains(5));
            Assert.AreEqual(bin, target.Bins.Search(4));
            Assert.AreEqual(3, target.Bins.SearchIndex(4));

            bin = target.Bins[4];
            Assert.AreEqual(2.0, bin.Value);
            Assert.AreEqual(1.0, bin.Width);
            Assert.IsTrue(bin.Range.Min <= 5 && 5 < bin.Range.Max);
            Assert.IsTrue(bin.Contains(5));
            Assert.IsTrue(bin.Contains(6));
            Assert.IsFalse(bin.Contains(4));
            Assert.AreEqual(bin, target.Bins.Search(5));
            Assert.AreEqual(4, target.Bins.SearchIndex(5));

            int sum = 0;
            for (int i = 0; i < target.Values.Length; i++)
                sum += target.Values[i];

            Assert.AreEqual(values.Length, sum);
        }
Ejemplo n.º 7
0
        public void ComputeTest6()
        {
            Histogram target = new Histogram();

            double[] data = { 0.0, 0.005, 0.124, 0.0, 0.004, 0.0, 0.111, 0.112 };

            target.Compute(data, 4);

            Assert.AreEqual(5, target.Edges.Length);
            Assert.AreEqual(0.000, target.Edges[0]);
            Assert.AreEqual(0.031, target.Edges[1]);
            Assert.AreEqual(0.062, target.Edges[2]);
            Assert.AreEqual(0.093, target.Edges[3]);
            Assert.AreEqual(0.124, target.Edges[4]);

        }
Ejemplo n.º 8
0
 /// <summary>
 ///   Displays a histogram with the specified data.
 /// </summary>
 /// 
 /// <param name="title">The title for the histogram window.</param>
 /// <param name="values">The histogram values.</param>
 /// 
 public static HistogramBox Show(string title, double[] values)
 {
     Histogram histogram = new Histogram(title);
     histogram.Compute(values);
     return show(histogram);
 }