Inheritance: ICloneable
Beispiel #1
0
 public void HistogramConstructorTest()
 {
     Histogram target = new Histogram();
     Assert.IsNotNull(target.Bins);
     Assert.IsNotNull(target.Values);
     Assert.AreEqual(0, target.Bins.Count);
 }
Beispiel #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);
        }
Beispiel #3
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));

        }
Beispiel #4
0
        /// <summary>
        ///   Creates a new object that is a copy of the current instance.
        /// </summary>
        /// 
        /// <returns>
        ///   A new object that is a copy of this instance.
        /// </returns>
        /// 
        public object Clone()
        {
            Histogram clone = new Histogram();
            clone.initialize(this.values.Length);

            for (int i = 0; i < clone.ranges.Length; i++)
                clone.ranges[i] = this.ranges[i];

            for (int i = 0; i < clone.values.Length; i++)
                clone.values[i] = this.values[i];

            clone.cumulative = this.cumulative;
            clone.inclusiveUpperBound = this.inclusiveUpperBound;
            clone.rule = this.rule;

            return clone;
        }
Beispiel #5
0
 /// <summary>
 ///   Adds one histogram from the other, storing
 ///   results in a new histogram, without changing the
 ///   current instance.
 /// </summary>
 /// 
 /// <param name="histogram">The histogram whose bin values will be added.</param>
 /// 
 /// <returns>A new <see cref="Histogram"/> containing the result of this operation.</returns>
 /// 
 public Histogram Add(Histogram histogram)
 {
     return Add(histogram.Values);
 }
Beispiel #6
0
 /// <summary>
 ///   Subtracts one histogram from the other, storing
 ///   results in a new histogram, without changing the
 ///   current instance.
 /// </summary>
 /// 
 /// <param name="histogram">The histogram whose bin values will be subtracted.</param>
 /// 
 /// <returns>A new <see cref="Histogram"/> containing the result of this operation.</returns>
 /// 
 public Histogram Subtract(Histogram histogram)
 {
     return Subtract(histogram.Values);
 }
Beispiel #7
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;
 }
Beispiel #8
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);
        }
Beispiel #9
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]);

        }
Beispiel #10
0
 internal HistogramBin(Histogram histogram, int index)
 {
     this.index = index;
     this.histogram = histogram;
 }
Beispiel #11
0
 internal HistogramBin(Histogram histogram, int index)
 {
     this.index     = index;
     this.histogram = histogram;
 }
Beispiel #12
0
 /// <summary>
 ///   Adds one histogram from the other, storing
 ///   results in a new histogram, without changing the
 ///   current instance.
 /// </summary>
 ///
 /// <param name="histogram">The histogram whose bin values will be added.</param>
 ///
 /// <returns>A new <see cref="Histogram"/> containing the result of this operation.</returns>
 ///
 public Histogram Add(Histogram histogram)
 {
     return(Add(histogram.Values));
 }
Beispiel #13
0
 /// <summary>
 ///   Subtracts one histogram from the other, storing
 ///   results in a new histogram, without changing the
 ///   current instance.
 /// </summary>
 ///
 /// <param name="histogram">The histogram whose bin values will be subtracted.</param>
 ///
 /// <returns>A new <see cref="Histogram"/> containing the result of this operation.</returns>
 ///
 public Histogram Subtract(Histogram histogram)
 {
     return(Subtract(histogram.Values));
 }