public double[] PrepareAndCalcCholesskyFull(double[][] x, double[] y) { List <double> bMeans; _v = __calcV(x, out bMeans); _c = __calcC(x); for (int i = 0; i < _v.Length; i++) { _v[i][i] += 0.001; } var regressionCoefficients = RegressionToolkit.CalculateCholesskyRegression(_v, _c); regressionCoefficients[0] = y.Average(); for (int i = 1; i < regressionCoefficients.Count; i++) { regressionCoefficients[0] -= regressionCoefficients[i] * bMeans[i]; } return(regressionCoefficients.ToArray()); }
public double[] PrepareAndCalcCholesskyNewColumns(double[][] x, double[] y) { //Это должно вызываться после пересчета базисов с новым узлом if (_v.Length != x[0].Length || _v[0].Length != x[0].Length || _c.Length != x[0].Length || _v.Length < 3) { //TODO: Не надо пересчитывать полностью, а только добавленные на предыдущей операции колонки _v = __calcV(x, out xhat); } else { //ПЕРЕСЧИТАТЬ ТОЛЬКО ПОСЛЕДНИЕ ДВА СТОЛБЦА И ПОСЛЕДНИЕ ДВЕ КОЛОНКИ V int f0 = _v.Length - 2; int f1 = _v.Length - 1; xhat[f0] = __calcMean(x, f0); xhat[f1] = __calcMean(x, f1); //Зануляем то, что будем считать for (int i = f0; i <= f1; i++) //две колонки { for (int j = 0; j < _v.Length; j++) { _v[i][j] = 0.0; _v[j][i] = 0.0; } } //считаем for (int k = 0; k < x.Length; k++) { for (int i = f0; i <= f1; i++) //две колонки { for (int j = 0; j <= i; j++) // все фичи (Bj) { _v[i][j] += x[k][j] * (x[k][i] - xhat[i]); if (i != j) { _v[j][i] += x[k][i] * (x[k][j] - xhat[j]); } } } } } //ВЗЯТО ИЗ СТАРОЙ РЕАЛИЗАЦИИ (пока) for (int i = 0; i < _v.Length; i++) { _v[i][i] += 0.001; } //СОПОСТАВЛЕНИЕ //for (int i = 0; i < _v.Length; i++) // for (int j = 0; j < _v.Length; j++) // { // var d1 = _v[i][j] - VDEBUG[i][j]; // var d2 = _v[j][i] - VDEBUG[j][i]; // if (Math.Abs(d1) >= 0.1 || Math.Abs(d2) >= 0.1) // { // Console.WriteLine("DEBUG : {0}", d1); // Console.WriteLine("DEBUG : {0}", d2); // } // } _c = __calcC(x); var regressionCoefficients = RegressionToolkit.CalculateCholesskyRegression(_v, _c); regressionCoefficients[0] = y.Average(); for (int i = 1; i < regressionCoefficients.Count; i++) { regressionCoefficients[0] -= regressionCoefficients[i] * xhat[i]; } return(regressionCoefficients.ToArray()); }