pretab.transformers.ThinPlateSplineTransformer
- class pretab.transformers.ThinPlateSplineTransformer(output_dim=6, include_bias=False)[source]
Bases:
SplineBasisMixin,TransformerMixin,BaseEstimatorThin Plate Spline Transformer for smooth univariate basis expansion.
This transformer constructs a smooth, nonparametric basis using eigen-decomposed thin plate spline (TPS) kernels. It supports only univariate input and is useful for modeling smooth nonlinear functions in regression tasks. The basis functions are the leading eigenvectors of the projected TPS kernel matrix.
Let \(m := \mathtt{output\_dim}\) be the number of non-bias output columns. The transformer keeps the top \(m\) eigenvectors, so the output width equals
output_dimdirectly (this family is knot-free; there is no knot inversion).include_bias=Trueadds one further intercept column.- Parameters:
output_dim (int, default=6) – Number of non-bias output columns (\(m\)) extracted from the eigen-decomposition of the TPS kernel. Must be at least 1.
include_bias (bool, default=False) – If True, prepend a constant intercept column to the output. The bias term is left unpenalized (a zero row/column is added to the penalty matrix).
- Variables:
x (ndarray of shape (n_samples, 1)) – Training input used to compute the TPS kernel and projection matrix.
Z (ndarray of shape (n_samples, 2)) – Matrix containing intercept and linear term (used for null space projection).
eigvals (ndarray of shape (output_dim,)) – Top eigenvalues from the projected kernel matrix.
basis (ndarray of shape (n_samples, output_dim)) – Orthogonal basis functions corresponding to the top eigenvectors.
penalty (ndarray of shape (output_dim, output_dim)) – Diagonal penalty matrix containing eigenvalues (used for smoothing regularization).
n_basis (list of int) – Number of output columns for the single feature, including the optional bias.
n_features_in (int) – Number of input features seen during
fit(always 1).total_output_dim (int) – Total number of output columns (fitted); equals
output_dim (+1 if include_bias).
Notes
Input must be univariate. Multivariate input will raise a ValueError.
Basis functions are derived from a kernel matrix projected onto the orthogonal complement of the null space of the linear terms (intercept and slope) [1].
The transformer uses an eigendecomposition of the projected TPS kernel to define the basis [2].
The transformer is kernel-based rather than knot-based, so the knot-oriented options shared by the other splines (
degree,target_aware,placement_strategy,task) do not apply here.
References
Examples
>>> import numpy as np >>> from pretab.transformers import ThinPlateSplineTransformer >>> X = np.linspace(0, 1, 30).reshape(-1, 1) >>> transformer = ThinPlateSplineTransformer(output_dim=6) >>> Xt = transformer.fit_transform(X) >>> Xt.shape (30, 6) >>> transformer.total_output_dim_ 6- __init__(output_dim=6, include_bias=False)[source]
Methods
__init__([output_dim, include_bias])fit(X[, y])fit_transform(X[, y])Fit to data, then transform it.
get_feature_names_out([input_features])Return output feature names of the form
{feature}_{suffix}{j}.get_metadata_routing()Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
get_penalty_matrix([feature_index])Return the smoothing penalty matrix for the fitted basis.
set_output(*[, transform])Set output container.
set_params(**params)Set the parameters of this estimator.
transform(X)Attributes
total_output_dim_Total number of output columns produced across all input features.
n_basis_n_features_in_adaptive- get_penalty_matrix(feature_index=0)[source]
Return the smoothing penalty matrix for the fitted basis.
- Parameters:
feature_index (int, default=0) – Accepted for signature parity with the other spline transformers; ignored because the thin-plate transformer is univariate.
- Returns:
penalty_ (ndarray of shape (output_dim, output_dim)) – Diagonal penalty matrix of eigenvalues used for regularization (with an unpenalized leading row/column when
include_bias=True).