FunctionalVAR._fpca_basis#
- FunctionalVAR._fpca_basis()[source]#
Estimate the principal-component basis from the centered sample.
A thin SVD of the centered panel gives the eigenfunctions as right singular vectors and the variance shares as normalized squared singular values; the count is
n_componentsor the smallest count whose cumulative share reaches 95%, capped by the numerical rank.- Return type:
- Returns:
The basis matrix, the mean curve, and the retained components’ variance shares.
- Raises:
SpecificationError – If
n_componentsexceeds the sample’s numerical rank.
Example
>>> import numpy as np >>> rng = np.random.default_rng(0) >>> grid = np.linspace(0.0, 1.0, 25) >>> curves = 0.1 * np.cumsum(rng.standard_normal(80))[:, None] + np.sin(np.pi * grid) >>> curves = curves + 0.01 * rng.standard_normal((80, 25)) >>> matrix, mean, shares = FunctionalVAR(curves, grid, order=1)._fpca_basis() >>> matrix.shape, bool(np.allclose(mean, curves.mean(axis=0))), bool(shares[0] > 0.95) ((25, 1), True, True) >>> too_many = FunctionalVAR(curves, grid, order=1, n_components=30) >>> too_many._fpca_basis() Traceback (most recent call last): cultivars.exceptions.SpecificationError: n_components (30) exceeds the sample's ...