@Test(expectedExceptions = IllegalArgumentException.class) public void testDegreeToHigh1() { BasisFunctionKnots.fromUniform(0.0, 10.0, 11, 11); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testWrongOrderUniform() { BasisFunctionKnots.fromUniform(2.0, 1.0, 10, 3); }
/** * Fits a curve to x-y data. * @param x The independent variables * @param y The dependent variables * @param sigma The error (or tolerance) on the y variables * @param xa The lowest value of x * @param xb The highest value of x * @param nKnots Number of knots (note, the actual number of basis splines and thus fitted weights, equals nKnots + degree-1) * @param degree The degree of the basis function - 0 is piecewise constant, 1 is a sawtooth function (i.e. two straight lines joined in the middle), 2 gives three * quadratic sections joined together, etc. For a large value of degree, the basis function tends to a gaussian * @param lambda The weight given to the penalty function * @param differenceOrder applies the penalty the nth order difference in the weights, so a differenceOrder of 2 will penalise large 2nd derivatives etc * @return The results of the fit */ public GeneralizedLeastSquareResults<Double> solve(List<Double> x, List<Double> y, List<Double> sigma, double xa, double xb, int nKnots, int degree, double lambda, int differenceOrder) { List<Function<Double, Double>> bSplines = _generator.generateSet(BasisFunctionKnots.fromUniform(xa, xb, nKnots, degree)); return _gls.solve(x, y, sigma, bSplines, lambda, differenceOrder); }
BasisFunctionKnots[] knots = new BasisFunctionKnots[xa.length]; for (int i = 0; i < xa.length; i++) { knots[i] = BasisFunctionKnots.fromUniform(xa[i], xb[i], nKnots[i], degree[i]);
@Test public void testUniform() { BasisFunctionKnots knots = BasisFunctionKnots.fromUniform(1.0, 2.0, 10, 3); assertEquals(3, knots.getDegree()); assertEquals(16, knots.getNumKnots()); assertEquals(12, knots.getNumSplines()); }
public void testPSplineFit2() { final BasisFunctionGenerator generator = new BasisFunctionGenerator(); List<Function<Double, Double>> basisFuncs = generator.generateSet(BasisFunctionKnots.fromUniform(0, 12, 100, 3)); List<Function<Double, Double>> basisFuncsLog = generator.generateSet(BasisFunctionKnots.fromUniform(-5, 3, 100, 3));