Select Git revision
__init__.py
pca_expand.py 721 B
#!/usr/bin/env python3
# License: GPLv3
# Portions of this code refactored from Matlab to Python using Jetbrains AI Assistant, then reviewed and corrected by human.
# Original authors:
# P.Antonelli
# L.Borg
# R.Garcia
import numpy as np
from functools import reduce
def dimprod(shp):
return reduce(lambda a,b: a * b, shp)
def pca_expand( M: np.ndarray, U: np.ndarray, coef: np.ndarray ) -> np.ndarray:
ntr = coef.shape[-1]
shp = coef.shape[:-1]
nX = dimprod(shp)
coef = coef.reshape((nX, ntr))
# PCM = np.tile(M, (1, nX))
col = np.dot(coef, U[:ntr,:]) + M
# print(col.shape)
# print(M.shape)
nrecon = col.shape[-1]
return col.reshape(tuple(shp) + (nrecon,))