Record Class BSpline
java.lang.Object
java.lang.Record
smile.regression.gam.BSpline
- Record Components:
degree- the degree of the B-spline polynomial (default: 3 for cubic splines).knots- the full (extended) knot vector, including repeated boundary knots.xmin- the minimum value of the predictor (used for clamping at prediction time).xmax- the maximum value of the predictor (used for clamping at prediction time).numBasis- the number of basis functions (columns of the basis matrix).
- All Implemented Interfaces:
Serializable
public record BSpline(int degree, double[] knots, double xmin, double xmax, int numBasis)
extends Record
implements Serializable
B-spline basis matrix for a single predictor. A B-spline (basis spline)
of degree
d is a piecewise polynomial defined on a knot sequence.
This class builds the basis matrix and the second-difference penalty matrix
used in penalized regression splines (P-splines).
The resulting basis has k + d columns, where k is the
number of inner knots. With a second-difference penalty on the B-spline
coefficients, this achieves smoothing similar to a cubic smoothing spline
but with the computational advantage of a banded penalty.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble[]basis(double x) Evaluates all B-spline basis functions at a single pointx.double[][]basis(double[] x) Computes the B-spline basis matrix for a set of predictor values.intdegree()Returns the value of thedegreerecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.double[]knots()Returns the value of theknotsrecord component.intnumBasis()Returns the value of thenumBasisrecord component.double[][]penalty()Computes the second-difference penalty matrixD'Dof sizenumBasis x numBasis.final StringtoString()Returns a string representation of this record class.doublexmax()Returns the value of thexmaxrecord component.doublexmin()Returns the value of thexminrecord component.
-
Constructor Details
-
BSpline
public BSpline(double[] x, int df, int degree) Constructor.- Parameters:
x- the predictor values (used to determine the knot placement).df- the desired degrees of freedom (number of basis functions). Must be>= degree + 1.degree- the polynomial degree (3 = cubic).
-
BSpline
public BSpline(double[] x, int df) Constructor with default cubic degree.- Parameters:
x- the predictor values.df- the desired degrees of freedom (number of basis functions).
-
BSpline
public BSpline(int degree, double[] knots, double xmin, double xmax, int numBasis) Creates an instance of aBSplinerecord class.
-
-
Method Details
-
basis
public double[][] basis(double[] x) Computes the B-spline basis matrix for a set of predictor values. Returns ann x numBasismatrix where each row contains the basis function evaluations for one observation.- Parameters:
x- the predictor values.- Returns:
- the basis matrix (n rows × numBasis columns).
-
basis
public double[] basis(double x) Evaluates all B-spline basis functions at a single pointx.- Parameters:
x- the point at which to evaluate the basis.- Returns:
- an array of length
numBasisof basis values.
-
penalty
public double[][] penalty()Computes the second-difference penalty matrixD'Dof sizenumBasis x numBasis. This penalizes the roughness of the fitted smooth function by penalizing differences in adjacent B-spline coefficients (a discrete approximation to the integrated squared second derivative).- Returns:
- the penalty matrix.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
degree
-
knots
-
xmin
-
xmax
-
numBasis
-