Expand description
Polynomial and RBF basis-function constructors for BLR feature engineering.
Each function accepts a 1-D input slice x (length N) and returns
(matrix, ncols) where matrix is the N×ncols feature matrix in
row-major order (same layout as the phi argument to crate::fit).
§Row-major layout
The feature matrix is stored as a flat Vec<f64> where element
matrix[i * ncols + j] is the value of feature j for observation i.
This matches the convention expected by crate::fit.
§Example
use blr_core::features::{polynomial, rbf};
// 3 observations, polynomial degree 2 → 3 columns [1, x, x²]
let x = [0.0_f64, 1.0, 2.0];
let (mat, ncols) = polynomial(&x, 2);
assert_eq!(ncols, 3);
assert_eq!(mat.len(), 3 * 3);
// Row 2 (x=2): [1.0, 2.0, 4.0]
assert!((mat[2 * 3 + 0] - 1.0).abs() < 1e-12);
assert!((mat[2 * 3 + 1] - 2.0).abs() < 1e-12);
assert!((mat[2 * 3 + 2] - 4.0).abs() < 1e-12);§Performance
All constructors allocate a single Vec<f64> of size N×ncols.
Construction is O(N×D) time and memory. For typical sensor calibration
(N ≤ 200, D ≤ 20) this is negligible.
§References
- Bishop, C. M. (2006). Pattern Recognition and Machine Learning, Chapter 3.
- For physics-informed sensor features, see the
sensor-featurescrate.
Functions§
- polynomial
- Polynomial feature map:
[1, x, x², ..., x^degree]. - rbf
- Radial Basis Function (RBF / Gaussian) feature map.
- trig
- Trigonometric (sine/cosine) feature map.