pub fn predict_fof(
fit: &FofResult,
new_x: &FdMatrix,
) -> Result<FdMatrix, FdarError>Expand description
Predict functional responses from new functional predictors.
Projects new_x onto the predictor FPCA, computes predicted Y-scores
via the fitted coefficient matrix, and reconstructs response curves.
§Arguments
fit- A fittedFofResultnew_x- New functional predictor data (n_new x m_x)
§Errors
Returns FdarError::InvalidDimension if the column count of new_x
does not match the predictor grid used during fitting.
§Examples
use fdars_core::matrix::FdMatrix;
use fdars_core::fof_regression::{fof_regression, predict_fof};
let (n, mx, my) = (25, 30, 20);
let x = FdMatrix::from_column_major(
(0..n * mx).map(|k| {
let i = (k % n) as f64;
let j = (k / n) as f64;
((i + 1.0) * j * 0.2).sin()
}).collect(), n, mx,
).unwrap();
let y = FdMatrix::from_column_major(
(0..n * my).map(|k| {
let i = (k % n) as f64;
let j = (k / n) as f64;
0.5 * ((i + 1.0) * j * 0.15).cos()
}).collect(), n, my,
).unwrap();
let tx: Vec<f64> = (0..mx).map(|j| j as f64 / (mx - 1) as f64).collect();
let ty: Vec<f64> = (0..my).map(|j| j as f64 / (my - 1) as f64).collect();
let fit = fof_regression(&x, &y, &tx, &ty, 3, 3).unwrap();
let predicted = predict_fof(&fit, &x).unwrap();
assert_eq!(predicted.shape(), (n, my));