本文整理汇总了Python中apgl.graph.SparseGraph.SparseGraph.getAllEdges方法的典型用法代码示例。如果您正苦于以下问题:Python SparseGraph.getAllEdges方法的具体用法?Python SparseGraph.getAllEdges怎么用?Python SparseGraph.getAllEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.SparseGraph.SparseGraph
的用法示例。
在下文中一共展示了SparseGraph.getAllEdges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cvModelSelection
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import getAllEdges [as 别名]
def cvModelSelection(self, graph, paramList, paramFunc, folds, errorFunc):
"""
ParamList is a list of lists of parameters and paramFunc
is a list of the corresponding functions to call with the parameters
as arguments. Note that a parameter can also be a tuple which is expanded
out before the function is called.
e.g.
paramList = [[1, 2], [2, 1], [12, 1]]
paramFunc = [predictor.setC, predictor.setD]
"""
inds = Sampling.crossValidation(folds, graph.getNumEdges())
errors = numpy.zeros((len(paramList), folds))
allEdges = graph.getAllEdges()
for i in range(len(paramList)):
paramSet = paramList[i]
logging.debug("Using paramSet=" + str(paramSet))
for j in range(len(paramSet)):
if type(paramSet[j]) == tuple:
paramFunc[j](*paramSet[j])
else:
paramFunc[j](paramSet[j])
predY = numpy.zeros(0)
y = numpy.zeros(0)
j = 0
for (trainInds, testInds) in inds:
trainEdges = allEdges[trainInds, :]
testEdges = allEdges[testInds, :]
trainGraph = SparseGraph(graph.getVertexList(), graph.isUndirected())
trainGraph.addEdges(trainEdges, graph.getEdgeValues(trainEdges))
testGraph = SparseGraph(graph.getVertexList(), graph.isUndirected())
testGraph.addEdges(testEdges, graph.getEdgeValues(testEdges))
self.learnModel(trainGraph)
predY = self.predictEdges(testGraph, testGraph.getAllEdges())
y = testGraph.getEdgeValues(testGraph.getAllEdges())
#Note that the order the edges is different in testGraphs as
#opposed to graph when calling getAllEdges()
errors[i, j] = errorFunc(y, predY)
j = j+1
logging.info("Error of current fold: " + str(numpy.mean(errors[i, :])))
meanErrors = numpy.mean(errors, 1)
strErrors = numpy.std(errors, 1)
return meanErrors, strErrors
示例2: VertexList
# 需要导入模块: from apgl.graph.SparseGraph import SparseGraph [as 别名]
# 或者: from apgl.graph.SparseGraph.SparseGraph import getAllEdges [as 别名]
for p in ps:
for size in sizes:
vList = VertexList(size, numFeatures)
sGraph = SparseGraph(vList)
generator = ErdosRenyiGenerator(sGraph)
sGraph = generator.generateGraph(p)
graphsA.append(sGraph)
#Form graphB by shuffling edges and adding/deleting ones
sGraph2 = SparseGraph(vList)
graphsB.append(sGraph2)
#Permute edges here
inds = numpy.random.permutation(size)
edges = sGraph.getAllEdges()
for i in range(0, edges.shape[0]):
sGraph2.addEdge(inds[edges[i, 0]], inds[edges[i, 1]])
numExtraEdges = numpy.random.randint(0, maxEdges)
for i in range(0, numExtraEdges):
edgeIndex1 = numpy.random.randint(0, size)
edgeIndex2 = numpy.random.randint(0, size)
#print(str(edgeIndex1) + " " + str(edgeIndex2))
sGraph2.addEdge(edgeIndex1, edgeIndex2)
#Check graphs are correct
#Now, compute the kernel matrix between all edges