Skip to content
Snippets Groups Projects
Select Git revision
  • 0f31d00b47490408de84c71a560226c69ce48a58
  • master default protected
  • use_flight_altitude
  • distribute
4 results

__init__.py

Blame
  • 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,))