public static DiscreteVariable ContinuosToDiscrete(DiscreteVariable veryBigDiscrete) { int r_1 = veryBigDiscrete.r_1; double h = veryBigDiscrete.p / r_1; // calculating new statistical table System.Collections.Generic.SortedDictionary <double, int> newStatisticalTable = new System.Collections.Generic.SortedDictionary <double, int>(); System.Collections.Generic.KeyValuePair <double, int>[] oldStatisticalTable = veryBigDiscrete.GetStatisticalTable(); double leftBorder = oldStatisticalTable.First().Key; double rightBorder = leftBorder + h; int leftIndex = 0; int rightIndex = 0; for (int i = 0; i < r_1 - 1; ++i)// for each class, except last one { // finding left and right index of element that will be summed while (oldStatisticalTable[rightIndex].Key < rightBorder) { ++rightIndex; } int sum = 0; for (int x = leftIndex; x < rightIndex; ++x) { sum += oldStatisticalTable[x].Value; } // set new value newStatisticalTable.Add((leftBorder + rightBorder) / 2, sum); leftIndex = rightIndex; leftBorder = rightBorder; rightBorder = leftBorder + h; } // calculate last class rightBorder = oldStatisticalTable.Last().Key; int lastSum = 0; for (int x = leftIndex; x < oldStatisticalTable.Length; ++x) { lastSum += oldStatisticalTable[x].Value; } // set new value newStatisticalTable.Add((leftBorder + rightBorder) / 2, lastSum); // new discrete variable has been created DiscreteVariable dv = new DiscreteVariable(newStatisticalTable); if (dv.Size != veryBigDiscrete.Size) { throw new System.ArgumentException("Some elements has been lost"); } return(dv); }
private void DataBox_Executed(object sender, EventArgs e) { Reset(); discreteVariable = dataBox.DiscreteVariable; // charting dataChartBox.IsDiscrete = dataBox.IsDiscrete; dataChartBox.DiscreteVariable = dataBox.DiscreteVariable; // statistics statisticsBox.DiscreteVariable = dataBox.DiscreteVariable; // pearsons test pearsonsTestBox.DiscreteVariable = dataBox.DiscreteVariable; }
public static DiscreteVariable OperateTableData(string[] stringData) { double[] xArr = stringData[0].Split(';').Select(double.Parse).ToArray(); int[] nArr = stringData[1].Split(';').Select(int.Parse).ToArray(); if (xArr.Length != nArr.Length) { throw new System.IO.InvalidDataException("The length of both rows should be the same"); } DiscreteVariable dv = new DiscreteVariable(); for (int i = 0; i < xArr.Length; ++i) { dv.statisticalTable.Add(xArr[i], nArr[i]); dv.size += nArr[i]; } if (dv.size < 2) { throw new System.ArgumentException("Too small."); } return(dv); }
public static DiscreteVariable OperateData(string stringData) { double[] xArr = stringData.Split(';').Select(double.Parse).ToArray(); DiscreteVariable dv = new DiscreteVariable(); foreach (double x in xArr) { if (dv.statisticalTable.ContainsKey(x)) { ++dv.statisticalTable[x]; } else { dv.statisticalTable.Add(x, 1); } ++dv.size; } if (dv.size < 2) { throw new System.ArgumentException("Too small."); } return(dv); }
// CONSTRUCTORS public PearsonsTest(DiscreteVariable dv) { this.dv = dv; bool needToRebuild = false; foreach (var item in this.dv.GetStatisticalTable()) { if (item.Key <= 5) { needToRebuild = true; } } if (needToRebuild) { this.dv = СontinuousToDiscrete.ContinuosToDiscrete(this.dv); } if (dv.Length < 5) { throw new System.ArgumentException("N < 5"); } p = CalcNormalDistributedFunctionProbabilities(); m = this.dv.GetStatisticalTable().Select(d => d.Value).ToArray(); }
// METHODS // MENU private void newToolStripMenuItem_Click(object sender, EventArgs e) { discreteVariable = null; CleanUp(); }