pflm.fpca.utils.get_covariance_matrix#
- get_covariance_matrix(raw_cov: ndarray, obs_grid: ndarray) ndarray[source][source]#
Aggregate raw covariance entries onto a dense symmetric matrix.
This maps the compact raw covariance table returned by get_raw_cov to a dense covariance matrix on the observation grid by summing weighted covariances per unique (t1, t2) pair and normalizing by (sum_w - 1).
- Parameters:
- raw_covnp.ndarray of shape (M, 5)
Columns are (sid, t1, t2, w, cov), typically from get_raw_cov.
- obs_gridnp.ndarray of shape (nt,)
Sorted unique observation grid values.
- Returns:
- cov_matrixnp.ndarray of shape (nt, nt)
Symmetric covariance matrix aligned to obs_grid.
- Raises:
- ValueError
If raw_cov does not have at least 5 columns, or obs_grid is empty.
See also
get_raw_covGet raw covariance entries from functional data.
Notes
Pairs with total weight <= 1 are set to zero to avoid division by zero.
The diagonal is adjusted to ensure symmetry after filling the upper-triangular part.