Esempio n. 1
0
    def matrixSimilarity(self, V1, V2):
        """
        Compute a vertex similarity matrix C, such that the ijth entry is the matching 
        score between V1_i and V2_j, where larger is a better match. 
        """
        X = numpy.r_[V1, V2]
        standardiser = Standardiser()
        X = standardiser.normaliseArray(X)

        V1 = X[0:V1.shape[0], :]
        V2 = X[V1.shape[0]:, :]

        #print(X)

        #Extend arrays with zeros to make them the same size
        #if V1.shape[0] < V2.shape[0]:
        #    V1 = Util.extendArray(V1, V2.shape, numpy.min(V1))
        #elif V2.shape[0] < V1.shape[0]:
        #    V2 = Util.extendArray(V2, V1.shape, numpy.min(V2))

        #Let's compute C as the distance between vertices
        #Distance is bounded by 1
        D = Util.distanceMatrix(V1, V2)
        maxD = numpy.max(D)
        minD = numpy.min(D)
        if (maxD - minD) != 0:
            C = (maxD - D) / (maxD - minD)
        else:
            C = numpy.ones((V1.shape[0], V2.shape[0]))

        return C
Esempio n. 2
0
    def matrixSimilarity(self, V1, V2):
        """
        Compute a vertex similarity matrix C, such that the ijth entry is the matching 
        score between V1_i and V2_j, where larger is a better match. 
        """
        X = numpy.r_[V1, V2]
        standardiser = Standardiser()
        X = standardiser.normaliseArray(X)

        V1 = X[0 : V1.shape[0], :]
        V2 = X[V1.shape[0] :, :]

        # print(X)

        # Extend arrays with zeros to make them the same size
        # if V1.shape[0] < V2.shape[0]:
        #    V1 = Util.extendArray(V1, V2.shape, numpy.min(V1))
        # elif V2.shape[0] < V1.shape[0]:
        #    V2 = Util.extendArray(V2, V1.shape, numpy.min(V2))

        # Let's compute C as the distance between vertices
        # Distance is bounded by 1
        D = Util.distanceMatrix(V1, V2)
        maxD = numpy.max(D)
        minD = numpy.min(D)
        if (maxD - minD) != 0:
            C = (maxD - D) / (maxD - minD)
        else:
            C = numpy.ones((V1.shape[0], V2.shape[0]))

        return C
Esempio n. 3
0
 def testDistanceMatrix(self): 
     numExamples1 = 10 
     numExamples2 = 15 
     numFeatures = 2 
     
     U = numpy.random.randn(numExamples1, numFeatures)
     V = numpy.random.randn(numExamples2, numFeatures)
     
     D = Util.distanceMatrix(U, V)
     
     D2 = numpy.zeros((numExamples1, numExamples2))
     
     for i in range(numExamples1): 
         for j in range(numExamples2): 
             D2[i, j] = numpy.sqrt(numpy.sum((U[i, :] - V[j, :])**2))
             
     nptst.assert_almost_equal(D, D2)
Esempio n. 4
0
    def testDistanceMatrix(self):
        numExamples1 = 10
        numExamples2 = 15
        numFeatures = 2

        U = numpy.random.randn(numExamples1, numFeatures)
        V = numpy.random.randn(numExamples2, numFeatures)

        D = Util.distanceMatrix(U, V)

        D2 = numpy.zeros((numExamples1, numExamples2))

        for i in range(numExamples1):
            for j in range(numExamples2):
                D2[i, j] = numpy.sqrt(numpy.sum((U[i, :] - V[j, :])**2))

        nptst.assert_almost_equal(D, D2)