Esempio n. 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))
Esempio n. 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))
Esempio n. 3
0
 def test_get_principal_coordinates(self):
     """get_principal_coordinates normalizes eigvecs with eigvalues"""
     matrix = array([[1, 1, 1], [2, 2, 2], [3, 3, 3]])
     vec = array([0, 1, -4])
     result = get_principal_coordinates(vec, matrix)
     self.assertEqual(result[0], array([0, 0, 0]))
     self.assertEqual(result[1], array([2, 2, 2]))
     self.assertEqual(result[2], array([6, 6, 6]))
Esempio n. 4
0
 def test_get_principal_coordinates(self):
     """get_principal_coordinates normalizes eigvecs with eigvalues"""
     matrix = array([[1,1,1],[2,2,2],[3,3,3]])
     vec = array([0,1,-4])
     result = get_principal_coordinates(vec, matrix)
     self.assertEqual(result[0], array([0,0,0]))
     self.assertEqual(result[1], array([2,2,2]))
     self.assertEqual(result[2], array([6,6,6]))