LeastSquaresRegression { protected void checkData(final double[][] x, final double[][] weights, final double[] y) { checkData(x, y); if (weights != null) { if (weights.length == 0) { throw new IllegalArgumentException("No data in weights array"); } if (weights.length != x.length) { throw new IllegalArgumentException("Independent variable and weight arrays are not the same length"); } final int n = weights[0].length; for (final double[] w : weights) { if (w.length != n) { throw new IllegalArgumentException("Need a rectangular array of weight"); } } } }  abstract LeastSquaresRegressionResult regress(double[][] x, double[][] weights, double[] y, boolean useIntercept);  }
@Test public void test() { final LeastSquaresRegression regression = new OrdinaryLeastSquaresRegression(); try { regression.checkData(null, null); Assert.fail(); } catch (final IllegalArgumentException e) { } double[][] x = new double[0][0]; try { regression.checkData(x, null); Assert.fail(); } catch (final IllegalArgumentException e) { } double[] y = new double[0]; try { regression.checkData(x, (double[]) null, y); Assert.fail(); } catch (final IllegalArgumentException e) { } x = new double[1][2]; y = new double[3]; try { regression.checkData(x, (double[]) null, y); Assert.fail(); } catch (final IllegalArgumentException e) { } x = new double[][] {new double[] {1., 2., 3.}, new double[] {4., 5.}, new double[] {6., 7., 8.}, new double[] {9., 0., 0.}}; try { regression.checkData(x, (double[]) null, y); Assert.fail(); } catch (final IllegalArgumentException e) { } x[1] = new double[] {4., 5., 6.}; try { regression.checkData(x, (double[]) null, y); Assert.fail(); } catch (final IllegalArgumentException e) { } y = new double[] {1., 2., 3., 4.}; double[] w1 = new double[0]; try { regression.checkData(x, w1, y); Assert.fail(); } catch (final IllegalArgumentException e) { } double[][] w = new double[0][0]; try { regression.checkData(x, w, y); Assert.fail(); } catch (final IllegalArgumentException e) { } w1 = new double[3]; try { regression.checkData(x, w1, y); Assert.fail(); } catch (final IllegalArgumentException e) { } w = new double[3][0]; try { regression.checkData(x, w, y); Assert.fail(); } catch (final IllegalArgumentException e) { } w = new double[][] {new double[] {1., 2., 3.}, new double[] {4., 5.}, new double[] {6., 7., 8.}, new double[] {9., 0., 0.}}; try { regression.checkData(x, w, y); Assert.fail(); } catch (final IllegalArgumentException e) { } }