本文整理汇总了Python中sandbox.util.Util.Util.distanceMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python Util.distanceMatrix方法的具体用法?Python Util.distanceMatrix怎么用?Python Util.distanceMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.util.Util.Util
的用法示例。
在下文中一共展示了Util.distanceMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matrixSimilarity
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import distanceMatrix [as 别名]
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
示例2: testDistanceMatrix
# 需要导入模块: from sandbox.util.Util import Util [as 别名]
# 或者: from sandbox.util.Util.Util import distanceMatrix [as 别名]
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)