public int[] DropoutErrors(double alpha, out string rep) { rep = string.Format("ОТСЕВ ПОГРЕШНОСТЕЙ ДЛЯ {0}<br>Уровень значимости: α = {1}<table border = 1 cellspacing = 0>" + "<tr><td>№ наблюдения<td>Значение<td>τ<sub>набл</sub><td>τ<sub>теор</sub>", name, alpha); List <int> lIgnore = new List <int>(), lI = new List <int>(); for (int i = 0; i < arr.Length; i++) { lI.Add(i); } while (true) { double min = double.MaxValue, max = double.MinValue; double sum = 0, sum2 = 0; int iMin = -1, iMax = -1; foreach (int i in lI) { if (arr[i] < min) { min = arr[i]; iMin = i; } if (arr[i] > max) { max = arr[i]; iMax = i; } sum += arr[i]; sum2 += arr[i] * arr[i]; } int n = lI.Count; double average = sum / n; double devStd = (sum2 / n - (sum / n) * (sum / n)) * n / (n - 1); double sigmaStd = (double)Math.Sqrt(devStd); double tauXMin, tauXMax; tauXMin = Math.Abs(min - average) / sigmaStd; tauXMax = Math.Abs(max - average) / sigmaStd; int index; double tauMax; if (tauXMin >= tauXMax) { index = iMin; tauMax = tauXMin; } else { index = iMax; tauMax = tauXMax; } double tauCrit; if (n <= 25) { tauCrit = StatTables.GetTau(1 - alpha, n); } else { double t = StatTables.GetStudInv(n - 2, alpha); tauCrit = t * Math.Sqrt(n - 1) / Math.Sqrt(n - 2 + t * t); } if (tauMax > tauCrit) { rep += string.Format("<tr><td>{0}<td>{1:g5}<td>{2:g3}<td>{3:g3}{4}", index, arr[index], tauMax, tauCrit, n <= 25 ? "" : "(исп. t(α,n-2))"); int pos = lIgnore.BinarySearch(index); lIgnore.Insert(~pos, index); pos = lI.BinarySearch(index); lI.RemoveAt(pos); } else { break; } } return(lIgnore.ToArray()); }
public int[] DropoutErrorsTau(double alpha) { ArrayList listX = new ArrayList(arrX); ArrayList listIndexIgnore = new ArrayList(); while (true) { double min = double.MaxValue, max = double.MinValue; double sum = 0, sumXPow2 = 0; int indexMin = -1, indexMax = -1; for (int i = 0; i < listX.Count; i++) { if (listIndexIgnore.BinarySearch(i) >= 0) { continue; } double x = (double)listX[i]; if (x < min) { min = x; indexMin = i; } if (x > max) { max = x; indexMax = i; } sum += x; sumXPow2 += x * x; } int n = listX.Count - listIndexIgnore.Count; double average = sum / n; double devStd = sumXPow2 / (n - 1) - (sum / (n - 1)) * (sum / (n - 1)); double sigmaStd = (double)Math.Sqrt(devStd); double tauXMin, tauXMax; tauXMin = (double)Math.Abs(min - average) / sigmaStd; tauXMax = (double)Math.Abs(max - average) / sigmaStd; int index; double tauMax; if (tauXMin >= tauXMax) { index = indexMin; tauMax = tauXMin; } else { index = indexMax; tauMax = tauXMax; } if (tauMax > StatTables.GetTau(alpha, n)) { listIndexIgnore.Add(index); listIndexIgnore.Sort(); } else { break; } } return((int[])listIndexIgnore.ToArray(typeof(int))); }
public int[] DropoutErrorsTau(double alpha, out string[] arrReason) { ArrayList listX = new ArrayList(arrX); ArrayList listIndexIgnore = new ArrayList(); List <string> listReason = new List <string>(); while (true) { double min = double.MaxValue, max = double.MinValue; double sum = 0, sumXPow2 = 0; int indexMin = -1, indexMax = -1; for (int i = 0; i < listX.Count; i++) { if (listIndexIgnore.BinarySearch(i) >= 0) { continue; } double x = (double)listX[i]; if (x < min) { min = x; indexMin = i; } if (x > max) { max = x; indexMax = i; } sum += x; sumXPow2 += x * x; } int n = listX.Count - listIndexIgnore.Count; double average = sum / n; double devStd = sumXPow2 / (n - 1) - (sum / (n - 1)) * (sum / (n - 1)); double sigmaStd = (double)Math.Sqrt(devStd); double tauXMin, tauXMax; tauXMin = (double)Math.Abs(min - average) / sigmaStd; tauXMax = (double)Math.Abs(max - average) / sigmaStd; int index; double tauMax; if (tauXMin >= tauXMax) { index = indexMin; tauMax = tauXMin; } else { index = indexMax; tauMax = tauXMax; } double tauTheor = StatTables.GetTau(alpha, n); if (tauMax > tauTheor) { int i = listIndexIgnore.BinarySearch(index); listIndexIgnore.Insert(~i, index); listReason.Insert(~i, string.Format("Для {0}: tau<SUB>max</SUB> = {1} > {2}", Math.Round(arrX[index], 3), Math.Round(tauMax, 3), Math.Round(tauTheor, 3))); } else { break; } } arrReason = listReason.ToArray(); return((int[])listIndexIgnore.ToArray(typeof(int))); }