LeastSquaresRegressionResult { public double getPredictedValue(final double[] x) { Validate.notNull(x, "x"); final double[] betas = getBetas(); if (hasIntercept()) { if (x.length != betas.length - 1) { throw new IllegalArgumentException("Number of variables did not match number used in regression"); } } else { if (x.length != betas.length) { throw new IllegalArgumentException("Number of variables did not match number used in regression"); } } double sum = 0; for (int i = 0; i < (hasIntercept() ? x.length + 1 : x.length); i++) { if (hasIntercept()) { if (i == 0) { sum += betas[0]; } else { sum += betas[i] * x[i - 1]; } } else { sum += x[i] * betas[i]; } } return sum; } LeastSquaresRegressionResult(final LeastSquaresRegressionResult result);  LeastSquaresRegressionResult(final double[] betas, final double[] residuals, final double meanSquareError, final double[] standardErrorOfBeta, final double rSquared,
      final double rSquaredAdjusted, final double[] tStats, final double[] pValues, final boolean hasIntercept); double[] getBetas(); double[] getResiduals(); double getMeanSquareError(); double[] getStandardErrorOfBetas(); double getRSquared(); double getAdjustedRSquared(); double[] getTStatistics(); double[] getPValues(); boolean hasIntercept(); double getPredictedValue(final double[] x); @Override int hashCode(); @Override boolean equals(final Object obj);  }
@Test(expectedExceptions = IllegalArgumentException.class) public void testNullArray() { NO_INTERCEPT.getPredictedValue(null); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testLongArray() { NO_INTERCEPT.getPredictedValue(new double[] {2.4, 2.5, 3.4}); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testShortArray() { NO_INTERCEPT.getPredictedValue(new double[] {2.4}); }
@Test public void testPredictedValue() { double[] z; for (int i = 0; i < 10; i++) { z = new double[] {RANDOM.nextDouble(), RANDOM.nextDouble()}; assertEquals(F1.evaluate(z[0], z[1]), NO_INTERCEPT.getPredictedValue(z), EPS); assertEquals(F2.evaluate(z[0], z[1]), INTERCEPT.getPredictedValue(z), EPS); } }