Esempio n. 1
0
    def stat(self, baseline=0.0):
        """
        Return the decision statistic associated with the test of the
        null hypothesis: (H0) 'contrast equals baseline'
            """
        self._baseline = baseline
        
        # Case: one-dimensional contrast ==> t or t**2
        if self.dim == 1: 
            # avoids division by zero
            t = (self.effect-baseline) / np.sqrt(np.maximum(self.variance, self._tiny)) 
            if self.type == 'F':
                t = t**2
        # Case: F contrast 
        elif self.type == 'F':
            # F = |t|^2/q ,  |t|^2 = e^t v-1 e  
            t = mahalanobis(self.effect-baseline, np.maximum(self.variance, self._tiny))/self.dim
        # Case: tmin (conjunctions)
        elif self.type == 'tmin':
            vdiag = self.variance.reshape([self.dim**2]+list(self.variance.shape[2:]))[::self.dim+1]
            t = (self.effect-baseline) / np.sqrt(np.maximum(vdiag, self._tiny))
            t = t.min(0)
            
        # Unknwon stat
        else:
            raise ValueError, 'Unknown statistic type'

        self._stat = t
        return t
Esempio n. 2
0
 def test_mahalanobis2(self):
     x = rand(100,3,4)
     Aa = zeros([100,100,3,4])
     for i in range(3):
         for j in range(4):
             A = rand(100,100)
             A = dot(A.transpose(), A)
             Aa[:,:,i,j] = A
     i = randint(3)
     j = randint(4)
     mah = dot(x[:,i,j], dot(inv(Aa[:,:,i,j]), x[:,i,j]))
     f_mah = (fu.mahalanobis(x, Aa))[i,j]        
     assert_almost_equal(mah, f_mah, decimal=3)
Esempio n. 3
0
 def test_mahalanobis(self):
     x = rand(100)
     A = rand(100, 100)
     A = dot(A.transpose(), A)
     mah = dot(x, dot(inv(A), x))
     assert_almost_equal(mah, fu.mahalanobis(x, A), decimal=1)