Esempio n. 1
0
def test_recipr0():
    X = np.array([[2,1],[-4,0]])
    Y = recipr0(X)
    yield assert_array_almost_equal, Y, np.array([[0.5,1],[-0.25,0]])
    # check that lists have arrived
    XL = [0, 1, -1]
    yield assert_array_almost_equal, recipr0(XL), [0, 1, -1]
    # scalars
    yield assert_equal, recipr0(-1), -1
    yield assert_equal, recipr0(0), 0
    yield assert_equal, recipr0(2), 0.5
Esempio n. 2
0
    def _extract_sd(self, results):

        delay = self.IRF.delay

        self.T1 = np.zeros(self.gamma0.shape)

        nrow = self.gamma0.shape[0]
        for i in range(nrow):
            self.T1[i] = self.gamma1[i] * pos_recipr(np.sqrt(results.cov_beta(matrix=self.deltamatrix[i])))

        a1 = 1 + 1. * pos_recipr(self.T0sq)

        gdot = np.array(([(self.r * (a1 - 2.) *
                          recipr0(self.gamma0 * a1**2)),
                         recipr0(self.gamma0 * a1)] *
                        recipr0(delay.dforward(self.deltahat))))

        Cov = results.cov_beta
        E = self.effectmatrix
        D = self.deltamatrix

        nrow = self.effectmatrix.shape[0]
            
        cov = np.zeros((nrow,)*2 + self.T0sq.shape[1:])

        for i in range(nrow):
            for j in range(i + 1):
                cov[i,j] = (gdot[0,i] * gdot[0,j] * Cov(matrix=E[i],
                                                      other=E[j]) +  
                            gdot[0,i] * gdot[1,j] * Cov(matrix=E[i],
                                                      other=D[j]) +
                            gdot[1,i] * gdot[0,j] * Cov(matrix=D[i],
                                                      other=E[j]) +
                            gdot[1,i] * gdot[1,j] * Cov(matrix=D[i],
                                                      other=D[j]))
                cov[j,i] = cov[i,j]

        nout = self.weights.shape[0]
        self._sd = np.zeros(self._effect.shape)

        for r in range(nout):
            var = 0
            for i in range(nrow):
                var += cov[i,i] * np.power(self.weights[r,i], 2)
                for j in range(i):
                    var += 2 * cov[i,j] * self.weights[r,i] * self.weights[r,j]

            self._sd[r] = np.sqrt(var)                
Esempio n. 3
0
    def _extract_effect(self, results):

        delay = self.IRF.delay

        self.gamma0 = np.dot(self.effectmatrix, results.beta)
        self.gamma1 = np.dot(self.deltamatrix, results.beta)

        nrow = self.gamma0.shape[0]
        self.T0sq = np.zeros(self.gamma0.shape)
        
        for i in range(nrow):
            self.T0sq[i] = (self.gamma0[i]**2 *
                            pos_recipr(results.cov_beta(matrix=self.effectmatrix[i])))

        self.r = self.gamma1 * recipr0(self.gamma0)
        self.rC = self.r * self.T0sq / (1. + self.T0sq)
        self.deltahat = delay.inverse(self.rC)

        self._effect = np.dot(self.weights, self.deltahat)