PEATDB/plugins/PCA.py
def doPCA(self,m,standardize=True):
        '''Performs pca on the Core.Matrix.Matrix instance m.

        Returns: 
                eigenvalues - A numpy 1-D array.
                eigenvectors - A numpy 2-D array
                transformedData - A numpy 2-D array'''

        print >>sys.stderr, 'Calculating mean vector'
        data = numpy.array(m.matrix)
        if standardize==True:
            data = self.standardize(data)   
        average = numpy.zeros(m.numberOfColumns())
        for row in data:                
            row = numpy.array(row, dtype=numpy.float)               
            average = average + row

        average /= m.numberOfRows()
        temp = zip(m.columnHeaders(), average)
        print >>sys.stderr, 'Result: '
        for el in temp:
            print >>sys.stderr, '\t%s: %lf' % tuple(el)

        print >>sys.stderr, '\nMean-Centering'
        data = data - numpy.tile(average, [m.numberOfRows(),1])

        print >>sys.stderr, 'Calculating covariance matrix'
        cov = numpy.cov(data, rowvar=0)

        print >>sys.stderr, 'Performing eigenvalue decomposition'
        eigenvalues, eigenvectors = numpy.linalg.linalg.eig(cov)
        eigenvectors = eigenvectors.astype(numpy.float32)

        print >>sys.stderr, 'Sorting'
        x = range(len(eigenvalues))
        x.sort(lambda x,y: cmp(eigenvalues[x], eigenvalues[y]), reverse=True)
        eigenvalues = eigenvalues[x]
        eigenvectors = eigenvectors[:,x]

        print >>sys.stderr, 'Complete'

        z = numpy.dot(data, eigenvectors)
        
        return eigenvalues, eigenvectors, z
Performs pca on the Core.Matrix.Matrix instance m.

        Returns: 
                eigenvalues - A numpy 1-D array.
                eigenvectors - A numpy 2-D array
                transformedData - A numpy 2-D array
Performs pca on the Core.Matrix.Matrix instance m.
Performs pca on the Core . Matrix . Matrix instance m .
def doPCA(self,m,standardize=True):
        print >>sys.stderr, 'Calculating mean vector'
        data = numpy.array(m.matrix)
        if standardize==True:
            data = self.standardize(data)   
        average = numpy.zeros(m.numberOfColumns())
        for row in data:                
            row = numpy.array(row, dtype=numpy.float)               
            average = average + row
        average /= m.numberOfRows()
        temp = zip(m.columnHeaders(), average)
        print >>sys.stderr, 'Result: '
        for el in temp:
            print >>sys.stderr, '\t%s: %lf' % tuple(el)
        print >>sys.stderr, '\nMean-Centering'
        data = data - numpy.tile(average, [m.numberOfRows(),1])
        print >>sys.stderr, 'Calculating covariance matrix'
        cov = numpy.cov(data, rowvar=0)
        print >>sys.stderr, 'Performing eigenvalue decomposition'
        eigenvalues, eigenvectors = numpy.linalg.linalg.eig(cov)
        eigenvectors = eigenvectors.astype(numpy.float32)
        print >>sys.stderr, 'Sorting'
        x = range(len(eigenvalues))
        x.sort(lambda x,y: cmp(eigenvalues[x], eigenvalues[y]), reverse=True)
        eigenvalues = eigenvalues[x]
        eigenvectors = eigenvectors[:,x]
        print >>sys.stderr, 'Complete'
        z = numpy.dot(data, eigenvectors)
        return eigenvalues, eigenvectors, z
def doPCA ( self , m , standardize = True ) : print >> sys . stderr , 'Calculating mean vector' data = numpy . array ( m . matrix ) if standardize == True : data = self . standardize ( data ) average = numpy . zeros ( m . numberOfColumns ( ) ) for row in data : row = numpy . array ( row , dtype = numpy . float ) average = average + row average /= m . numberOfRows ( ) temp = zip ( m . columnHeaders ( ) , average ) print >> sys . stderr , 'Result: ' for el in temp : print >> sys . stderr , '\t%s: %lf' % tuple ( el ) print >> sys . stderr , '\nMean-Centering' data = data - numpy . tile ( average , [ m . numberOfRows ( ) , 1 ] ) print >> sys . stderr , 'Calculating covariance matrix' cov = numpy . cov ( data , rowvar = 0 ) print >> sys . stderr , 'Performing eigenvalue decomposition' eigenvalues , eigenvectors = numpy . linalg . linalg . eig ( cov ) eigenvectors = eigenvectors . astype ( numpy . float32 ) print >> sys . stderr , 'Sorting' x = range ( len ( eigenvalues ) ) x . sort ( lambda x , y : cmp ( eigenvalues [ x ] , eigenvalues [ y ] ) , reverse = True ) eigenvalues = eigenvalues [ x ] eigenvectors = eigenvectors [ : , x ] print >> sys . stderr , 'Complete' z = numpy . dot ( data , eigenvectors ) return eigenvalues , eigenvectors , z
Performs pca on the Core.Matrix.Matrix instance m.
Performs pca on the Core . Matrix . Matrix instance m .
'''Performs pca on the Core.Matrix.Matrix instance m.

        Returns: 
                eigenvalues - A numpy 1-D array.
                eigenvectors - A numpy 2-D array
                transformedData - A numpy 2-D array'''
A numpy 1-D array.
eigenvectors - A numpy 2-D array
transformedData - A numpy 2-D array
A numpy 1 - D array . eigenvectors - A numpy 2 - D array transformedData - A numpy 2 - D array
self
m
standardize