/** * This regression method is private and called in other regression methods * @param xDataMatrix _nData x (_degree + 1) matrix whose low vector is (xData[i]^0, xData[i]^1, ..., xData[i]^{_degree}) * @param yDataVector the y-values * @param nData Number of data points * @param degree the degree */ private LeastSquaresRegressionResult regress( DoubleMatrix xDataMatrix, DoubleArray yDataVector, int nData, int degree) { Decomposition<QRDecompositionResult> qrComm = new QRDecompositionCommons(); DecompositionResult decompResult = qrComm.apply(xDataMatrix); _qrResult = (QRDecompositionResult) decompResult; DoubleMatrix qMatrix = _qrResult.getQ(); DoubleMatrix rMatrix = _qrResult.getR(); double[] betas = backSubstitution(qMatrix, rMatrix, yDataVector, degree); double[] residuals = residualsSolver(xDataMatrix, betas, yDataVector); for (int i = 0; i < degree + 1; ++i) { ArgChecker.isFalse(Double.isNaN(betas[i]), "Input is too large or small"); } for (int i = 0; i < nData; ++i) { ArgChecker.isFalse(Double.isNaN(residuals[i]), "Input is too large or small"); } return new LeastSquaresRegressionResult(betas, residuals, 0.0, null, 0.0, 0.0, null, null, true); }