当前位置: 首页>>代码示例>>Python>>正文


Python SparseGraph.setWeightMatrix方法代码示例

本文整理汇总了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
开发者ID:pankajk,项目名称:Deep-Graph-Kernels,代码行数:19,代码来源:Kronecker_Generator.py

示例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
开发者ID:charanpald,项目名称:APGL,代码行数:20,代码来源:StochasticKroneckerGenerator.py

示例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)
开发者ID:malcolmreynolds,项目名称:APGL,代码行数:77,代码来源:IterativeSpectralClusteringTest.py


注:本文中的apgl.graph.SparseGraph.SparseGraph.setWeightMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。