scikit-spectra icon indicating copy to clipboard operation
scikit-spectra copied to clipboard

Vectorize asyn_codist in correlation analysis

Open hughesadam87 opened this issue 10 years ago • 1 comments

Code now:

 @property
    def async_codist(self):
        """ Asynchronous codistribution """

        # Empty asyn matrix
        numrows = self.shape[0]        
        async = np.empty((numrows,numrows))

        tm, t1 = self.columns[-1], self.columns[0]

        # Numpy arrays to speed up loop/indexer
        tbar = self.char_perturb.values
        std = self.joint_std.values

        # broadcast this?
        for i in range(numrows):
            for j in range(numrows):
                coeff = (tbar[j] - tbar[i]) / (tm -t1)
                # I believe std[i] std[j] is correct way
                async[i][j] = coeff * std[i,j]

        return Spec2d(async, 
                      corr2d=self, 
                      name='Asynchronous Codistribution', 
                      iunit='asynchronicity')

But want vectorization. This requires vectorizing the t2 - t1, which evelyn figured out is essentially this operation:

>>> array([[1,2,3],]*3)
v1 = array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])

>>> array([[1,2,3],]*3).transpose()
v2 = array([[1, 1, 1],
       [2, 2, 2],
       [3, 3, 3]])

v2 - v1

But kind of a pain in the ass, and not sure how much time it would save in the computation.

hughesadam87 avatar Nov 11 '14 19:11 hughesadam87

Here is thread for array solution:

http://stackoverflow.com/questions/1550130/cloning-row-or-column-vectors

hughesadam87 avatar Nov 11 '14 19:11 hughesadam87