示例#1
0
    def test_integration(self):
        """Integration test of PCoA should work correctly"""
        u = array(
            [[0., 0.7123611, 0.76849198, 0.80018563, 0.68248524, 0.74634629],
             [0.7123611, 0., 0.86645691, 0.80485282, 0.83381301, 0.73881726],
             [0.76849198, 0.86645691, 0., 0.82308396, 0.77451746, 0.76498872],
             [0.80018563, 0.80485282, 0.82308396, 0., 0.84167365, 0.77614366],
             [0.68248524, 0.83381301, 0.77451746, 0.84167365, 0., 0.72661163],
             [0.74634629, 0.73881726, 0.76498872, 0.77614366, 0.72661163, 0.]])

        e = make_E_matrix(u)
        f = make_F_matrix(e)
        eigvals, eigvecs = run_eig(f)
        bigfirstorder = eigvals.argsort()[::-1]
        #eigvecs = eigvecs[bigfirstorder]
        #eigvals = eigvals[bigfirstorder]
        principal_coords = get_principal_coordinates(eigvals, eigvecs)
        principal_coords = principal_coords[bigfirstorder]
        expected = array([[
            2.85970001e-02, -3.74940557e-01, 3.35175925e-01, -2.54123944e-01,
            2.82568441e-01, -1.72768652e-02
        ],
                          [
                              2.29038532e-01, 2.23340550e-01, -2.38559794e-01,
                              -4.12346397e-01, 1.86069108e-01, 1.24580018e-02
                          ],
                          [
                              7.05527166e-02, -2.08929136e-01, -3.09988697e-01,
                              2.33436419e-01, 2.88756308e-01, -7.38276099e-02
                          ]])
        self.assertFloatEqual(abs(principal_coords[[0, 1, 2]]), abs(expected))
示例#2
0
    def test_integration(self):
        """Integration test of PCoA should work correctly"""
        u = array([[ 0.        ,  0.7123611 ,  0.76849198,  0.80018563,  0.68248524,  0.74634629],
               [ 0.7123611 ,  0.        ,  0.86645691,  0.80485282,  0.83381301,  0.73881726],
               [ 0.76849198,  0.86645691,  0.        ,  0.82308396,  0.77451746,  0.76498872],
               [ 0.80018563,  0.80485282,  0.82308396,  0.        ,  0.84167365,  0.77614366],
               [ 0.68248524,  0.83381301,  0.77451746,  0.84167365,  0.        ,  0.72661163],
               [ 0.74634629,  0.73881726,  0.76498872,  0.77614366,  0.72661163,  0.        ]])

        e = make_E_matrix(u)
        f = make_F_matrix(e)
        eigvals, eigvecs = run_eig(f)
        bigfirstorder = eigvals.argsort()[::-1]
        #eigvecs = eigvecs[bigfirstorder]
        #eigvals = eigvals[bigfirstorder]
        principal_coords = get_principal_coordinates(eigvals, eigvecs)
        principal_coords = principal_coords[bigfirstorder]
        expected = array([
                   [  2.85970001e-02,  -3.74940557e-01,   3.35175925e-01,
                     -2.54123944e-01,   2.82568441e-01,  -1.72768652e-02],
                   [  2.29038532e-01,   2.23340550e-01,  -2.38559794e-01,
                     -4.12346397e-01,   1.86069108e-01,   1.24580018e-02],
                   [  7.05527166e-02,  -2.08929136e-01,  -3.09988697e-01,
                      2.33436419e-01,   2.88756308e-01,  -7.38276099e-02]])
        self.assertFloatEqual(abs(principal_coords[[0,1,2]]), abs(expected))
示例#3
0
 def test_make_E_matrix(self):
     """make_E_matrix converts a distance matrix to an E matrix"""
     matrix = self.matrix
     E_matrix = make_E_matrix(matrix)
     self.assertFloatEqual(E_matrix[0, 0], -0.5)
     self.assertFloatEqual(E_matrix[0, 1], -2.0)
     self.assertFloatEqual(E_matrix[1, 0], -8.0)
     self.assertFloatEqual(E_matrix[1, 2], -18.0)
示例#4
0
 def test_make_E_matrix(self):
     """make_E_matrix converts a distance matrix to an E matrix"""
     matrix = self.matrix
     E_matrix = make_E_matrix(matrix)
     self.assertFloatEqual(E_matrix[0,0], -0.5)
     self.assertFloatEqual(E_matrix[0,1], -2.0)
     self.assertFloatEqual(E_matrix[1,0], -8.0)
     self.assertFloatEqual(E_matrix[1,2], -18.0)