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()); }
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); }
public static void Initialize(TestContext testContext) { histogram = new Histogram(); values = new byte[] { 16, 32, 64, 128, 16, 32, 128, 128, 64, 64 }; histogram.Add(values); }
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); }
protected void DrawChartWithSeriesInfoHist() { Steema.TeeChart.Axis axis = null; Steema.TeeChart.Styles.Histogram s; DataTable dt = null; this.AnalysisChart.Chart.Series.Clear(); this.AnalysisChart.SetXAxisRegularInterval(true); int iOldEnd = 0; for (int i = 0; i < _llstSortingKey.Count; i++) { int iEnd = 0; double min = 0; double max = 0; string strSortingValue = _llstSortingKey.GetKey(i).ToString(); string strSortingKey = _llstSortingKey.GetValue(i).ToString(); Color c = GetSeriesColor(i); s = new Histogram(); s.Color = c; s.Title = strSortingValue; s.XValues.Name = Definition.CHART_COLUMN.VALUE; this.AnalysisChart.Chart.Series.Add(s); foreach (DataRow dr in this.dtDataSource.Rows) { string sSortingKey = dr[strSortingKey].ToString(); int dCount = int.Parse(dr[Definition.CHART_COLUMN.SAMPLE_COUNT].ToString()); int iIndex = int.Parse(dr[CommonChart.COLUMN_NAME_SEQ_INDEX].ToString()); double dData = double.Parse(dr[Definition.CHART_COLUMN.VALUE].ToString()); if (sSortingKey.Equals(strSortingValue)) { if (dCount > iEnd) { iEnd = dCount; } s.Add(iIndex, dCount, c); if (dData > min) { max = dData; } else { min = dData; } } else { s.Add(iIndex, -999, c); } } for (int index = 0; index < this.dtDataSource.Rows.Count; index++) { s.Labels[index] = this.dtDataSource.Rows[index][Definition.CHART_COLUMN.VALUE].ToString(); } iOldEnd = iEnd; } this.AnalysisChart.Chart.Axes.Left.Maximum = iOldEnd; this.AnalysisChart.Chart.Axes.Left.Minimum = 0; this.AnalysisChart.Chart.Axes.Left.MinAxisIncrement = 1; this.AnalysisChart.Chart.Axes.Left.MinorTickCount = 0; this.AnalysisChart.Chart.Axes.Left.SetMinMax(0, iOldEnd); this.AnalysisChart.Chart.Axes.Left.MinimumOffset = 0; this.AnalysisChart.Chart.Axes.Left.MaximumOffset = iOldEnd + 1; this.AnalysisChart.Chart.Axes.Bottom.MinorTickCount = 0; }
/// <summary> /// Shows the Historigram Chart from Maximum Temperature forecast. /// </summary> /// <param name="weather"> Weather info</param> private void MaxTemperatureForecast(ActualWeather weather) { var tChart1 = new Chart(); tChart1.Aspect.View3D = false; tChart1.Legend.Visible = false; tChart1.Axes.Bottom.Labels.Angle = 90; tChart1.Axes.Bottom.Labels.DateTimeFormat = "dd/MMM"; tChart1.Header.Text = "Min/Max Temperature of " + App.Weather.Name; var maxTemp = new Histogram(tChart1.Chart); var highlow = new HighLow(tChart1.Chart); //maxTemp.LinesPen.Visible = false; maxTemp.Color = Color.FromRgb(27, 177, 255); maxTemp.LinePen.Color = Color.FromRgb(27, 177, 255); maxTemp.LinePen.Width = 20; maxTemp.LinesPen.Width = 20; maxTemp.LinesPen.Visible = true; maxTemp.LinePen.Visible = true; maxTemp.LinesPen.Color = Color.FromRgb(27, 177, 255); highlow.HighPen.Width = 4; highlow.LowPen.Width = 4; highlow.HighPen.DashCap = Steema.TeeChart.Drawing.PenLineCap.Round; highlow.HighPen.EndCap = Steema.TeeChart.Drawing.PenLineCap.Round; highlow.HighPen.Style = Steema.TeeChart.Drawing.DashStyle.Solid; highlow.LowPen.DashCap = Steema.TeeChart.Drawing.PenLineCap.Round; highlow.LowPen.EndCap = Steema.TeeChart.Drawing.PenLineCap.Round; highlow.LowPen.Style = Steema.TeeChart.Drawing.DashStyle.Solid; highlow.Marks.Visible = true; highlow.Marks.DrawEvery = 3; highlow.Marks.FollowSeriesColor = true; highlow.HighPen.Color = Color.FromRgb(223, 5, 0); highlow.LowPen.Color = Color.FromRgb(240, 186, 0); highlow.Pen.Visible = false; double max = App.getDegScaleTemp(weather.LstWeather[0].MaxTemperature); double min = App.getDegScaleTemp(weather.LstWeather[0].MaxTemperature); foreach (var item in weather.LstWeather) { if (App.getDegScaleTemp(item.MaxTemperature) > max) { max = App.getDegScaleTemp(item.MaxTemperature); } if (App.getDegScaleTemp(item.MaxTemperature) < min) { min = App.getDegScaleTemp(item.MinTemperature); } maxTemp.Add(item.Date, App.getDegScaleTemp(item.MaxTemperature)); highlow.Add(maxTemp.XValues.Last, item.MaxTemperature, item.MinTemperature); } maxTemp.Marks.AutoPosition = true; maxTemp.Marks.Transparent = true; tChart1.Axes.Left.SetMinMax((int)min - 3, (int)max + 4); tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay); tChart1.Axes.Bottom.SetMinMax(tChart1.Axes.Bottom.MinXValue + 0.5, tChart1.Axes.Bottom.MaxXValue - 0.5); AxisSettings(tChart1); TitleSettings(tChart1); //SeriesMarksSettings(maxTemp); tChart1.Axes.Left.Increment = 4; ShowChart(tChart1); }
public void AddingTooBigValues() { var h = new Histogram(1); h.Add(2); }
public void AddingTooSmallValues() { var h = new Histogram(1); h.Add(0); }
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); } }