Record Class SmoothingSpline

java.lang.Object
java.lang.Record
smile.regression.gam.SmoothingSpline
Record Components:
name - the name of the predictor variable.
spline - the B-spline basis specification for this predictor.
lambda - the smoothing parameter. Larger values produce smoother fits. The penalty term added to the log-likelihood is lambda * beta' P beta, where P is the second-difference penalty matrix.
coefficients - the fitted B-spline coefficients (after centering).
center - the centering constant (mean of f(x_i) over training data), subtracted to make the smooth identifiable in the additive model.
edf - the effective degrees of freedom consumed by this smooth. Computed as trace(S), where S is the smoother/hat matrix.
All Implemented Interfaces:
Serializable

public record SmoothingSpline(String name, BSpline spline, double lambda, double[] coefficients, double center, double edf) extends Record implements Serializable
A penalized regression spline (P-spline) for a single predictor variable. This is the building block of a Generalized Additive Model: each predictor in the GAM is associated with one SmoothingSpline that models the non-parametric smooth contribution f_j(x_j).

The smooth function is represented as a linear combination of B-spline basis functions:

    f(x) = B(x) * beta
where B(x) is a row vector of B-spline basis evaluations and beta is the vector of coefficients estimated during model fitting.

To ensure identifiability within the additive model, the smooth is centered: its mean over the training data is subtracted so that sum_i f(x_i) = 0. This centering constant is stored and added back on prediction.

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SmoothingSpline(String name, BSpline spline, double lambda, double[] coefficients, double center, double edf)
    Creates an instance of a SmoothingSpline record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the value of the center record component.
    double[]
    Returns the fitted B-spline coefficients.
    double
    edf()
    Returns the effective degrees of freedom for this smooth.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    double
    Returns the value of the lambda record component.
    Returns the name of the predictor variable.
    double
    predict(double x)
    Evaluates the smooth function at a single point.
    double[]
    predict(double[] x)
    Evaluates the smooth function at multiple points.
    Returns the value of the spline record component.
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SmoothingSpline

      public SmoothingSpline(String name, BSpline spline, double lambda, double[] coefficients, double center, double edf)
      Creates an instance of a SmoothingSpline record class.
      Parameters:
      name - the value for the name record component
      spline - the value for the spline record component
      lambda - the value for the lambda record component
      coefficients - the value for the coefficients record component
      center - the value for the center record component
      edf - the value for the edf record component
  • Method Details

    • predict

      public double predict(double x)
      Evaluates the smooth function at a single point. Returns f(x) = B(x) * coefficients - center. The centering is applied so that the smooth has zero mean over training data.
      Parameters:
      x - the predictor value.
      Returns:
      the smooth function value (centered).
    • predict

      public double[] predict(double[] x)
      Evaluates the smooth function at multiple points.
      Parameters:
      x - the predictor values.
      Returns:
      the smooth function values (centered).
    • coefficients

      public double[] coefficients()
      Returns the fitted B-spline coefficients.
      Returns:
      the coefficients.
    • edf

      public double edf()
      Returns the effective degrees of freedom for this smooth.
      Returns:
      the effective degrees of freedom.
    • name

      public String name()
      Returns the name of the predictor variable.
      Returns:
      the predictor name.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • spline

      public BSpline spline()
      Returns the value of the spline record component.
      Returns:
      the value of the spline record component
    • lambda

      public double lambda()
      Returns the value of the lambda record component.
      Returns:
      the value of the lambda record component
    • center

      public double center()
      Returns the value of the center record component.
      Returns:
      the value of the center record component