1e-14);
double[] residuals = regression.estimateResiduals();
TestUtils.assertEquals(residuals, new double[]{0d,0d,0d,0d,0d,0d},
1e-14);
RealMatrix errors =
new Array2DRowRealMatrix(regression.estimateRegressionParametersVariance(), false);
final double[] s = { 1.0, -1.0 / 2.0, -1.0 / 3.0, -1.0 / 4.0, -1.0 / 5.0, -1.0 / 6.0 };
RealMatrix referenceVariance = new Array2DRowRealMatrix(s.length, s.length);
referenceVariance.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
@Override
public double visit(int row, int column, double value)
throws MatrixVisitorException {
if (row == 0) {
return s[column];
}
double x = s[row] * s[column];
return (row == column) ? 2 * x : x;
}
});
assertEquals(0.0,
errors.subtract(referenceVariance).getNorm(),
5.0e-16 * referenceVariance.getNorm());
}