/** * Generate a set of b-splines with a given polynomial degree on the specified knots. * @param knots holder for the knots and degree * @return a List of functions */ public List<Function<Double, Double>> generateSet(BasisFunctionKnots knots) { ArgChecker.notNull(knots, "knots"); double[] k = knots.getKnots(); List<Function<Double, Double>> set = null; for (int d = 0; d <= knots.getDegree(); d++) { set = generateSet(k, d, set); } return set; }
/** * Generate the i^th basis function * @param data Container for the knots and degree of the basis function * @param index The index (from zero) of the function. Must be in range 0 to data.getNumSplines() (exclusive) * For example if the degree is 1, and index is 0, this will cover the first three knots. * @return The i^th basis function */ protected Function<Double, Double> generate(BasisFunctionKnots data, final int index) { ArgChecker.notNull(data, "data"); ArgChecker.isTrue(index >= 0 && index < data.getNumSplines(), "index must be in range {} to {} (exclusive)", 0, data.getNumSplines()); return generate(data.getKnots(), data.getDegree(), index); }
@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()); }
@Test public void testInternalKnots() { BasisFunctionKnots knots = BasisFunctionKnots.fromInternalKnots(KNOTS, 2); assertEquals(2, knots.getDegree()); assertEquals(15, knots.getNumKnots()); assertEquals(12, knots.getNumSplines()); }
@Test public void testKnots() { BasisFunctionKnots knots = BasisFunctionKnots.fromKnots(KNOTS, 3); assertEquals(3, knots.getDegree()); assertEquals(11, knots.getNumKnots()); assertEquals(7, knots.getNumSplines()); ArrayAsserts.assertArrayEquals(KNOTS, knots.getKnots(), 1e-15); }