def test_normalize_condensed_matrix(self):
     condensed = CondensedDistanceMatrix([ 1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6,2.2, 2.])
     expected = CondensedDistanceMatrix([0.0, 0.47, 1.0, 0.83, 0.47, 0.91, 0.76, 0.35, 0.16, 0.13])
     minmax = condensed.get_minimum_and_maximum()
     condensed.normalize(minmax[0], minmax[1])
     for i in range(len(condensed.get_data())):
         self.assertAlmostEqual(condensed.get_data()[i],expected.get_data()[i],2)
Пример #2
0
 def test_normalize_condensed_matrix(self):
     condensed = CondensedDistanceMatrix(
         [1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6, 2.2, 2.])
     expected = CondensedDistanceMatrix(
         [0.0, 0.47, 1.0, 0.83, 0.47, 0.91, 0.76, 0.35, 0.16, 0.13])
     minmax = condensed.get_minimum_and_maximum()
     condensed.normalize(minmax[0], minmax[1])
     for i in range(len(condensed.get_data())):
         self.assertAlmostEqual(condensed.get_data()[i],
                                expected.get_data()[i], 2)
    def test_load_condensed_matrix(self):
        matrix_string =  """1.0 
4.5 8.5 
7.2 4.5 7.8 
6.7 3.6 2.2 2.0
"""
        expected_matrix = CondensedDistanceMatrix([ 1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6,2.2, 2.])
        input = cStringIO.StringIO(matrix_string)
        loaded_matrix =  load_condensed_matrix(input)
        for i in range(len(expected_matrix.get_data())):
            self.assertAlmostEqual(expected_matrix.get_data()[i],\
                                   loaded_matrix.get_data()[i],3)
Пример #4
0
    def test_load_condensed_matrix(self):
        matrix_string = """1.0 
4.5 8.5 
7.2 4.5 7.8 
6.7 3.6 2.2 2.0
"""
        expected_matrix = CondensedDistanceMatrix(
            [1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6, 2.2, 2.])
        input = cStringIO.StringIO(matrix_string)
        loaded_matrix = load_condensed_matrix(input)
        for i in range(len(expected_matrix.get_data())):
            self.assertAlmostEqual(expected_matrix.get_data()[i],\
                                   loaded_matrix.get_data()[i],3)
Пример #5
0
    def test_item_access(self):
        condensed_matrix_1 = CondensedDistanceMatrix(
            [1.0, 4.5, 7.2, 8.5, 4.5, 7.8])
        condensed_matrix_2 = CondensedDistanceMatrix([.0] * 6)

        complete_matrix = [[0.0, 1.0, 4.5, 7.2], [1.0, 0.0, 8.5, 4.5],
                           [4.5, 8.5, 0.0, 7.8], [7.2, 4.5, 7.8, 0.0]]

        row_len = condensed_matrix_1.row_length

        for i in range(row_len):
            for j in range(row_len):
                condensed_matrix_2[i, j] = complete_matrix[i][j]

        ## The access for a complete and a condensed matrix is exactly the same
        for i in range(row_len):
            for j in range(row_len):
                self.assertEquals(condensed_matrix_1[i, j],
                                  complete_matrix[i][j])

        ## And we can build a condensed matrix as a complete matrix
        self.assertItemsEqual(condensed_matrix_1.get_data(),
                              condensed_matrix_2.get_data())
 def test_item_access(self):
     condensed_matrix_1 = CondensedDistanceMatrix([1.0, 4.5,7.2, 
                                                     8.5, 4.5, 
                                                          7.8])
     condensed_matrix_2 = CondensedDistanceMatrix([.0]*6)
     
     complete_matrix = [[0.0, 1.0, 4.5, 7.2],
                        [1.0, 0.0, 8.5, 4.5],
                        [4.5, 8.5, 0.0, 7.8],
                        [7.2, 4.5, 7.8, 0.0]]
     
     row_len = condensed_matrix_1.row_length
     
     for i in range(row_len):
         for j in range(row_len):
             condensed_matrix_2[i,j] = complete_matrix[i][j]
     
     ## The access for a complete and a condensed matrix is exactly the same
     for i in range(row_len):
         for j in range(row_len):
             self.assertEquals(condensed_matrix_1[i,j],complete_matrix[i][j])
     
     ## And we can build a condensed matrix as a complete matrix
     self.assertItemsEqual(condensed_matrix_1.get_data(), condensed_matrix_2.get_data())
Пример #7
0
    def test_data_sharing(self):
        mylist = [1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6, 2.2, 2.]
        myarray = np.array([1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6, 2.2, 2.])
        mylistaarray = np.array(mylist)
        condensed1 = CondensedDistanceMatrix(mylist)
        condensed2 = CondensedDistanceMatrix(myarray)
        condensed3 = CondensedDistanceMatrix(mylistaarray)

        mylist[5] = 0.
        self.assertEqual(False, mylist[5] == condensed1.get_data()[5])
        myarray[5] = 0.
        self.assertEqual(False, myarray[5] == condensed2.get_data()[5])
        mylistaarray[5] = 0.
        self.assertEqual(False, mylistaarray[5] == condensed3.get_data()[5])

        mycontents = condensed3.get_data()
        mycontents[5] = 0.
        self.assertEqual(True, mycontents[5] == condensed3.get_data()[5] and\
                         condensed3.get_data()[5] == 0.)
 def test_data_sharing(self):
     mylist = [ 1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6,2.2, 2.]        
     myarray = np.array([ 1., 4.5, 8.5, 7.2, 4.5, 7.8, 6.7, 3.6,2.2, 2.])
     mylistaarray = np.array(mylist)
     condensed1 = CondensedDistanceMatrix(mylist)
     condensed2 = CondensedDistanceMatrix(myarray)
     condensed3 = CondensedDistanceMatrix(mylistaarray)
     
     mylist[5] = 0.
     self.assertEqual(False, mylist[5] == condensed1.get_data()[5])
     myarray[5] = 0.
     self.assertEqual(False, myarray[5] == condensed2.get_data()[5])
     mylistaarray[5] = 0.
     self.assertEqual(False, mylistaarray[5] == condensed3.get_data()[5])
     
     mycontents = condensed3.get_data()
     mycontents[5] = 0.
     self.assertEqual(True, mycontents[5] == condensed3.get_data()[5] and\
                      condensed3.get_data()[5] == 0.)