public void testPSplineFit() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare(); final GeneralizedLeastSquareResults<Double> results = gls.solve(X, Y, SIGMA, BASIS_FUNCTIONS, 1000.0, 2); final Function<Double, Double> spline = results.getFunction(); assertEquals(2225.7, results.getChiSq(), 1e-1); assertEquals(-0.758963811327287, spline.apply(1.1), 1e-8); /* * Print out function for debugging */ if (PRINT) { System.out.println("Chi^2:\t" + results.getChiSq()); System.out.println("weights:\t" + results.getFitParameters()); for (int i = 0; i < 101; i++) { final double x = 0 + i * 2.0 / 100.0; System.out.println(x + "\t" + spline.apply(x)); } for (int i = 0; i < X.length; i++) { System.out.println(X[i] + "\t" + Y[i]); } } }
public void testFit() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare(); final double[] y = new double[Y.length]; for (int i = 0; i < Y.length; i++) { y[i] = Y[i] + SIGMA[i] * NORMAL.nextRandom(); } final LeastSquareResults results = gls.solve(X, y, SIGMA, SIN_FUNCTIONS); assertTrue(results.getChiSq() < 3 * Y.length); }
public void testBSplineFit() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare(); final LeastSquareResults results = gls.solve(X, Y, SIGMA, BASIS_FUNCTIONS); final Function<Double, Double> spline = new BasisFunctionAggregation<>(BASIS_FUNCTIONS, results.getFitParameters().toArray()); assertEquals(0.0, results.getChiSq(), 1e-12); assertEquals(-0.023605293, spline.apply(0.5), 1e-8); if (PRINT) { System.out.println("Chi^2:\t" + results.getChiSq()); System.out.println("weights:\t" + results.getFitParameters()); for (int i = 0; i < 101; i++) { final double x = 0 + i * 2.0 / 100.0; System.out.println(x + "\t" + spline.apply(x)); } for (int i = 0; i < X.length; i++) { System.out.println(X[i] + "\t" + Y[i]); } } }
public void testBSplineFit2D() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare();
public void testPerfectFit() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare(); final LeastSquareResults results = gls.solve(X, Y, SIGMA, SIN_FUNCTIONS); assertEquals(0.0, results.getChiSq(), 1e-8); final DoubleArray w = results.getFitParameters(); for (int i = 0; i < WEIGHTS.length; i++) { assertEquals(WEIGHTS[i], w.get(i), 1e-8); } }
List<Function<Double, Double>> basisFuncsLog = generator.generateSet(BasisFunctionKnots.fromUniform(-5, 3, 100, 3)); final GeneralizedLeastSquare gls = new GeneralizedLeastSquare();
public void testPerfectFitVector() { final GeneralizedLeastSquare gls = new GeneralizedLeastSquare(); final LeastSquareResults results = gls.solve(X_TRIG, Y_TRIG, SIGMA_TRIG, VECTOR_TRIG_FUNCTIONS); assertEquals(0.0, results.getChiSq(), 1e-8); final DoubleArray w = results.getFitParameters(); for (int i = 0; i < WEIGHTS.length; i++) { assertEquals(WEIGHTS[i], w.get(i), 1e-8); } }