<s> from ilastik . modules . unsupervised_decomposition . core . algorithms . unsupervisedDecompositionBase import UnsupervisedDecompositionBase <EOL> import numpy <EOL> class UnsupervisedDecompositionPCA ( UnsupervisedDecompositionBase ) : <EOL> name = "<STR_LIT>" <EOL> shortname = "<STR_LIT>" <EOL> description = "<STR_LIT>" <EOL> author = "<STR_LIT>" <EOL> homepage = "<STR_LIT>" <EOL> numComponents = <NUM_LIT:3> <EOL> def __init__ ( self ) : <EOL> UnsupervisedDecompositionBase . __init__ ( self ) <EOL> self . numComponents = UnsupervisedDecompositionPCA . numComponents <EOL> def decompose ( self , features ) : <EOL> self . numComponents = self . checkNumComponents ( features . shape [ <NUM_LIT:1> ] , self . numComponents ) <EOL> meanData = self . meanData ( features ) <EOL> features_centered = features - meanData <EOL> U , s , Vh = numpy . linalg . svd ( features_centered , full_matrices = False ) <EOL> ZV = ( U * s ) . T <EOL> FZ = Vh <EOL> ZV = ZV [ range ( <NUM_LIT:0> , self . numComponents ) , : ] <EOL> FZ = FZ [ : , range ( <NUM_LIT:0> , self . numComponents ) ] <EOL> return FZ , ZV <EOL> def meanData ( self , X ) : <EOL> return numpy . ones ( ( X . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> ) ) * numpy . mean ( X , axis = <NUM_LIT:0> ) </s>
