Beispiel #1
0
def get_dis_of_face(face1, face2):
    data = np.vstack((face1, face2))
    l1 = np.shape(face1)[0]
    l2 = np.shape(face2)[0]
    index1 = range(l1)
    index2 = range(l1, l1 + l2, 1)

    dis = clusterdistance(data,
                          index1=index1,
                          index2=index2,
                          dist='e',
                          method='s')
    return dis
Beispiel #2
0
    def test_clusterdistance(self):
        if TestCluster.module == 'Bio.Cluster':
            from Bio.Cluster import clusterdistance
        elif TestCluster.module == 'Pycluster':
            from Pycluster import clusterdistance

        # First data set
        weight = numpy.array([1, 1, 1, 1, 1])
        data = numpy.array([[1.1, 2.2, 3.3, 4.4, 5.5],
                            [3.1, 3.2, 1.3, 2.4, 1.5],
                            [4.1, 2.2, 0.3, 5.4, 0.5],
                            [12.1, 2.0, 0.0, 5.0, 0.0]])
        mask = numpy.array([[1, 1, 1, 1, 1],
                            [1, 1, 1, 1, 1],
                            [1, 1, 1, 1, 1],
                            [1, 1, 1, 1, 1]], int)

        # Cluster assignments
        c1 = [0]
        c2 = [1, 2]
        c3 = [3]

        # TODO - Use a context manager here once we drop Python 2.6
        # Method should be one letter:
        self.assertRaises(ValueError, clusterdistance, data,
                          **{"mask": mask, "weight": weight,
                             "index1": c1, "index2": c2, "transpose": 0,
                             "method": "any", "dist": "e"})

        # Distance should be one letter:
        self.assertRaises(ValueError, clusterdistance, data,
                          **{"mask": mask, "weight": weight,
                             "index1": c1, "index2": c2, "transpose": 0,
                             "method": "a", "dist": "euclidean"})

        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c1, index2=c2, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 6.650, places=3)
        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c1, index2=c3, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 32.508, places=3)
        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c2, index2=c3, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 15.118, places=3)

        # Second data set
        weight = numpy.array([1, 1])
        data = numpy.array([[1.1, 1.2],
                         [1.4, 1.3],
                         [1.1, 1.5],
                         [2.0, 1.5],
                         [1.7, 1.9],
                         [1.7, 1.9],
                         [5.7, 5.9],
                         [5.7, 5.9],
                         [3.1, 3.3],
                         [5.4, 5.3],
                         [5.1, 5.5],
                         [5.0, 5.5],
                         [5.1, 5.2]])
        mask = numpy.array([[1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1],
                            [1, 1]], int)

        # Cluster assignments
        c1 = [0, 1, 2, 3]
        c2 = [4, 5, 6, 7]
        c3 = [8]

        # TODO - Use a context manager here once we drop Python 2.6
        # Method should be one letter:
        self.assertRaises(ValueError, clusterdistance, data,
                          **{"mask": mask, "weight": weight,
                             "index1": c1, "index2": c2,
                             "method": "any", "dist": "e",
                             "transpose": 0})

        # Distance should be one letter:
        self.assertRaises(ValueError, clusterdistance, data,
                          **{"mask": mask, "weight": weight,
                             "index1": c1, "index2": c2,
                             "method": "a", "dist": "euclidena",
                             "transpose": 0})

        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c1, index2=c2, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 5.833, places=3)
        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c1, index2=c3, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 3.298, places=3)
        distance = clusterdistance(data, mask=mask, weight=weight,
                                   index1=c2, index2=c3, dist='e',
                                   method='a', transpose=0)
        self.assertAlmostEqual(distance, 0.360, places=3)
Beispiel #3
0
def test_clusterdistance(module):
    if module == 'Bio.Cluster':
        from Bio.Cluster import clusterdistance
    elif module == 'Pycluster':
        from Pycluster import clusterdistance
    else:
        raise 'Unknown module name', module
    print "test_clusterdistance:"

    # First data set
    weight1 = array([1, 1, 1, 1, 1])
    data1 = array([[
        1.1,
        2.2,
        3.3,
        4.4,
        5.5,
    ], [
        3.1,
        3.2,
        1.3,
        2.4,
        1.5,
    ], [
        4.1,
        2.2,
        0.3,
        5.4,
        0.5,
    ], [
        12.1,
        2.0,
        0.0,
        5.0,
        0.0,
    ]])
    mask1 = array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1],
                   [1, 1, 1, 1, 1]])

    # Second data set
    weight2 = array([1, 1])
    data2 = array([[1.1, 1.2], [1.4, 1.3], [1.1, 1.5], [2.0, 1.5], [1.7, 1.9],
                   [1.7, 1.9], [5.7, 5.9], [5.7, 5.9], [3.1, 3.3], [5.4, 5.3],
                   [5.1, 5.5], [5.0, 5.5], [5.1, 5.2]])
    mask2 = array([[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1],
                   [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]])
    # Cluster assignments
    c1 = [0]
    c2 = [1, 2]
    c3 = [3]

    print "First data set:"
    print_matrix(data1, mask1)
    print "Clusters are", c1, c2, c3
    distance = clusterdistance(data1,
                               mask=mask1,
                               weight=weight1,
                               index1=c1,
                               index2=c2,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c1, "and", c2, "is %7.3f." % distance
    distance = clusterdistance(data1,
                               mask=mask1,
                               weight=weight1,
                               index1=c1,
                               index2=c3,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c1, "and", c3, "is %7.3f." % distance
    distance = clusterdistance(data1,
                               mask=mask1,
                               weight=weight1,
                               index1=c2,
                               index2=c3,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c2, "and", c3, "is %7.3f." % distance

    # Cluster assignments
    c1 = [0, 1, 2, 3]
    c2 = [4, 5, 6, 7]
    c3 = [8]
    print "Second data set:"
    print_matrix(data2, mask2)
    print "Clusters are", c1, c2, c3
    distance = clusterdistance(data2,
                               mask=mask2,
                               weight=weight2,
                               index1=c1,
                               index2=c2,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c1, "and", c2, "is %7.3f." % distance
    distance = clusterdistance(data2,
                               mask=mask2,
                               weight=weight2,
                               index1=c1,
                               index2=c3,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c1, "and", c3, "is %7.3f." % distance
    distance = clusterdistance(data2,
                               mask=mask2,
                               weight=weight2,
                               index1=c2,
                               index2=c3,
                               dist='e',
                               method='a',
                               transpose=0)
    print "Distance between cluster", c2, "and", c3, "is %7.3f." % distance
    print
Beispiel #4
0
    def test_clusterdistance(self):
        if TestCluster.module == "Bio.Cluster":
            from Bio.Cluster import clusterdistance
        elif TestCluster.module == "Pycluster":
            from Pycluster import clusterdistance

        # First data set
        weight = numpy.array([1, 1, 1, 1, 1])
        data = numpy.array(
            [
                [1.1, 2.2, 3.3, 4.4, 5.5],
                [3.1, 3.2, 1.3, 2.4, 1.5],
                [4.1, 2.2, 0.3, 5.4, 0.5],
                [12.1, 2.0, 0.0, 5.0, 0.0],
            ]
        )
        mask = numpy.array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]], int)

        # Cluster assignments
        c1 = [0]
        c2 = [1, 2]
        c3 = [3]

        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c1, index2=c2, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 6.650, 3)
        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c1, index2=c3, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 32.508, 3)
        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c2, index2=c3, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 15.118, 3)

        # Second data set
        weight = numpy.array([1, 1])
        data = numpy.array(
            [
                [1.1, 1.2],
                [1.4, 1.3],
                [1.1, 1.5],
                [2.0, 1.5],
                [1.7, 1.9],
                [1.7, 1.9],
                [5.7, 5.9],
                [5.7, 5.9],
                [3.1, 3.3],
                [5.4, 5.3],
                [5.1, 5.5],
                [5.0, 5.5],
                [5.1, 5.2],
            ]
        )
        mask = numpy.array(
            [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]],
            int,
        )

        # Cluster assignments
        c1 = [0, 1, 2, 3]
        c2 = [4, 5, 6, 7]
        c3 = [8]

        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c1, index2=c2, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 5.833, 3)
        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c1, index2=c3, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 3.298, 3)
        distance = clusterdistance(
            data, mask=mask, weight=weight, index1=c2, index2=c3, dist="e", method="a", transpose=0
        )
        self.assertAlmostEqual(distance, 0.360, 3)
Beispiel #5
0
    def test_clusterdistance(self):
        if TestCluster.module == 'Bio.Cluster':
            from Bio.Cluster import clusterdistance
        elif TestCluster.module == 'Pycluster':
            from Pycluster import clusterdistance

        # First data set
        weight = numpy.array([1, 1, 1, 1, 1])
        data = numpy.array([[1.1, 2.2, 3.3, 4.4,
                             5.5], [3.1, 3.2, 1.3, 2.4, 1.5],
                            [4.1, 2.2, 0.3, 5.4, 0.5],
                            [9.9, 2.0, 0.0, 5.0, 0.0]])
        mask = numpy.array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1],
                            [1, 1, 1, 1, 1]], int)

        # Cluster assignments
        c1 = [0]
        c2 = [1, 2]
        c3 = [3]

        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c1,
                                   index2=c2,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 6.650, places=3)
        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c1,
                                   index2=c3,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 23.796, places=3)
        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c2,
                                   index2=c3,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 8.606, places=3)

        # Second data set
        weight = numpy.array([1, 1])
        data = numpy.array([[1.1, 1.2], [1.4, 1.3], [1.1, 1.5], [2.0, 1.5],
                            [1.7, 1.9], [1.7, 1.9], [5.7, 5.9], [5.7, 5.9],
                            [3.1, 3.3], [5.4, 5.3], [5.1, 5.5], [5.0, 5.5],
                            [5.1, 5.2]])
        mask = numpy.array(
            [[1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1], [1, 1],
             [1, 1], [1, 1], [1, 1], [1, 1], [1, 1]], int)

        # Cluster assignments
        c1 = [0, 1, 2, 3]
        c2 = [4, 5, 6, 7]
        c3 = [8]

        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c1,
                                   index2=c2,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 5.833, places=3)
        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c1,
                                   index2=c3,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 3.298, places=3)
        distance = clusterdistance(data,
                                   mask=mask,
                                   weight=weight,
                                   index1=c2,
                                   index2=c3,
                                   dist='e',
                                   method='a',
                                   transpose=0)
        self.assertAlmostEqual(distance, 0.360, places=3)
Beispiel #6
0
def test_clusterdistance(module):
  if module=='Bio.Cluster':
    from Bio.Cluster import clusterdistance
  elif module=='Pycluster':
    from Pycluster import clusterdistance
  else:
    raise 'Unknown module name', module
  print "test_clusterdistance:"

  # First data set
  weight1 =  array([ 1,1,1,1,1 ])
  data1   =  array([[  1.1, 2.2, 3.3, 4.4, 5.5, ], 
                    [  3.1, 3.2, 1.3, 2.4, 1.5, ], 
                    [  4.1, 2.2, 0.3, 5.4, 0.5, ], 
                    [ 12.1, 2.0, 0.0, 5.0, 0.0, ]])
  mask1   = array([[ 1, 1, 1, 1, 1], 
                   [ 1, 1, 1, 1, 1], 
                   [ 1, 1, 1, 1, 1], 
                   [ 1, 1, 1, 1, 1]])

  # Second data set
  weight2 =  array([ 1,1 ])
  data2   =  array([[ 1.1, 1.2 ],
                    [ 1.4, 1.3 ],
                    [ 1.1, 1.5 ],
                    [ 2.0, 1.5 ],
                    [ 1.7, 1.9 ],
                    [ 1.7, 1.9 ],
                    [ 5.7, 5.9 ],
                    [ 5.7, 5.9 ],
                    [ 3.1, 3.3 ],
                    [ 5.4, 5.3 ],
                    [ 5.1, 5.5 ],
                    [ 5.0, 5.5 ],
                    [ 5.1, 5.2 ]])
  mask2 = array([[ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ],
                 [ 1, 1 ]])
  # Cluster assignments
  c1 = [0]
  c2 = [1,2]
  c3 = [3]

  print "First data set:"
  print_matrix(data1, mask1)
  print "Clusters are", c1, c2, c3
  distance = clusterdistance(data1, mask=mask1, weight=weight1, index1=c1, index2=c2, dist='e', method='a', transpose=0);
  print "Distance between cluster", c1, "and", c2, "is %7.3f." % distance
  distance = clusterdistance(data1, mask=mask1, weight=weight1, index1=c1, index2=c3, dist='e', method='a', transpose=0);
  print "Distance between cluster", c1, "and", c3, "is %7.3f." % distance
  distance = clusterdistance(data1, mask=mask1, weight=weight1, index1=c2, index2=c3, dist='e', method='a', transpose=0);
  print "Distance between cluster", c2, "and", c3, "is %7.3f." % distance

  # Cluster assignments
  c1 = [ 0, 1, 2, 3 ]
  c2 = [ 4, 5, 6, 7 ]
  c3 = [ 8 ]
  print "Second data set:"
  print_matrix(data2, mask2)
  print "Clusters are", c1, c2, c3
  distance = clusterdistance(data2, mask=mask2, weight=weight2, index1=c1, index2=c2, dist='e', method='a', transpose=0);
  print "Distance between cluster", c1, "and", c2, "is %7.3f." % distance
  distance = clusterdistance(data2, mask=mask2, weight=weight2, index1=c1, index2=c3, dist='e', method='a', transpose=0);
  print "Distance between cluster", c1, "and", c3, "is %7.3f." % distance
  distance = clusterdistance(data2, mask=mask2, weight=weight2, index1=c2, index2=c3, dist='e', method='a', transpose=0);
  print "Distance between cluster", c2, "and", c3, "is %7.3f." % distance
  print