本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.setWeightMatrix方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.setWeightMatrix方法的具体用法?Python SparseGraph.setWeightMatrix怎么用?Python SparseGraph.setWeightMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.setWeightMatrix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setWeightMatrix [as 别名]
def generate(self):
"""
Generate a Kronecker graph using the adjacency matrix of the input graph.
:returns: The generate graph as a SparseGraph object.
"""
W = self.initialGraph.adjacencyMatrix()
Wi = W
for i in range(1, self.k):
Wi = np.kron(Wi, W)
vList = VertexList(Wi.shape[0], 0)
graph = SparseGraph(vList, self.initialGraph.isUndirected())
graph.setWeightMatrix(Wi)
return graph
示例2: generateGraph
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setWeightMatrix [as 别名]
def generateGraph(self):
"""
Generate a Kronecker graph
"""
W = self.initialGraph.getWeightMatrix()
Wi = W
for i in range(1, self.k):
Wi = numpy.kron(Wi, W)
P = numpy.random.rand(Wi.shape[0], Wi.shape[0])
Wi = numpy.array(P < Wi, numpy.float64)
vList = VertexList(Wi.shape[0], 0)
graph = SparseGraph(vList, self.initialGraph.isUndirected())
graph.setWeightMatrix(Wi)
return graph
示例3: testClusterOnIncreasingGraphs
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import setWeightMatrix [as 别名]
def testClusterOnIncreasingGraphs(self):
#Create a large graph and try the clustering.
numClusters = 3
ClusterSize = 30
numFeatures = 0
pNoise = 0
pClust = 1
numVertices = numClusters*ClusterSize
vList = GeneralVertexList(numVertices)
vList = VertexList(numVertices, numFeatures)
graph = SparseGraph(vList)
# ell = 2
# m = 2
# generator = BarabasiAlbertGenerator(ell, m)
# graph = generator.generate(graph)
#Generate matrix of probabilities
W = numpy.ones((numVertices, numVertices))*pNoise
for i in range(numClusters):
W[ClusterSize*i:ClusterSize*(i+1), ClusterSize*i:ClusterSize*(i+1)] = pClust
P = numpy.random.rand(numVertices, numVertices)
W = numpy.array(P < W, numpy.float)
upTriInds = numpy.triu_indices(numVertices)
W[upTriInds] = 0
W = W + W.T
graph = SparseGraph(vList)
graph.setWeightMatrix(W)
indices = numpy.random.permutation(numVertices)
subgraphIndicesList = [indices[0:numVertices/2], indices]
k1 = numClusters
k2 = 10
clusterer = IterativeSpectralClustering(k1, k2)
#Test full computation of eigenvectors
graphIterator = IncreasingSubgraphListIterator(graph, subgraphIndicesList)
clustersList = clusterer.clusterFromIterator(graphIterator, False)
self.assertEquals(len(clustersList), len(subgraphIndicesList))
for i in range(len(clustersList)):
clusters = clustersList[i]
self.assertEquals(len(subgraphIndicesList[i]), len(clusters))
#print(clusters)
#Test full computation of eigenvectors with iterator
graphIterator = IncreasingSubgraphListIterator(graph, subgraphIndicesList)
clustersList = clusterer.clusterFromIterator(graphIterator, False)
self.assertEquals(len(clustersList), len(subgraphIndicesList))
for i in range(len(clustersList)):
clusters = clustersList[i]
self.assertEquals(len(subgraphIndicesList[i]), len(clusters))
#print(clusters)
#Now test approximation of eigenvectors with iterator
graphIterator = IncreasingSubgraphListIterator(graph, subgraphIndicesList)
clustersList2 = clusterer.clusterFromIterator(graphIterator)
for i in range(len(clustersList2)):
clusters = clustersList2[i]
self.assertEquals(len(subgraphIndicesList[i]), len(clusters))
#print(clusters)
#Test case where 2 graphs are identical
subgraphIndicesList = []
subgraphIndicesList.append(range(graph.getNumVertices()))
subgraphIndicesList.append(range(graph.getNumVertices()))
graphIterator = IncreasingSubgraphListIterator(graph, subgraphIndicesList)
clustersList = clusterer.clusterFromIterator(graphIterator, True)