本文整理汇总了Python中graph_tool.Graph.edge_properties["type"]方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.edge_properties["type"]方法的具体用法?Python Graph.edge_properties["type"]怎么用?Python Graph.edge_properties["type"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph_tool.Graph
的用法示例。
在下文中一共展示了Graph.edge_properties["type"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_er
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties["type"] [as 别名]
def gen_er(dicProperties):
np.random.seed()
# initialize graph
graphER = Graph()
nNodes = 0
nEdges = 0
rDens = 0.0
if "Nodes" in dicProperties.keys():
nNodes = dicProperties["Nodes"]
graphER.add_vertex(nNodes)
if "Edges" in dicProperties.keys():
nEdges = dicProperties["Edges"]
rDens = nEdges / float(nNodes**2)
dicProperties["Density"] = rDens
else:
rDens = dicProperties["Density"]
nEdges = int(np.floor(rDens*nNodes**2))
dicProperties["Edges"] = nEdges
else:
nEdges = dicProperties["Edges"]
rDens = dicProperties["Density"]
nNodes = int(np.floor(np.sqrt(nEdges/rDens)))
graphER.add_vertex(nNodes)
dicProperties["Nodes"] = nNodes
# generate edges
numTest,numCurrentEdges = 0,0
while numCurrentEdges != nEdges and numTest < n_MAXTESTS:
lstEdges = np.random.randint(0,nNodes,(nEdges-numCurrentEdges,2))
graphER.add_edge_list(lstEdges)
# remove loops and duplicate edges
remove_self_loops(graphER)
remove_parallel_edges(graphER)
numCurrentEdges = graphER.num_edges()
numTest += 1
graphER.reindex_edges()
nEdges = graphER.num_edges()
rDens = nEdges / float(nNodes**2)
# generate types
rInhibFrac = dicProperties["InhibFrac"]
lstTypesGen = np.random.uniform(0,1,nEdges)
lstTypeLimit = np.full(nEdges,rInhibFrac)
lstIsExcitatory = np.greater(lstTypesGen,lstTypeLimit)
nExc = np.count_nonzero(lstIsExcitatory)
epropType = graphER.new_edge_property("int",np.multiply(2,lstIsExcitatory)-np.repeat(1,nEdges)) # excitatory (True) or inhibitory (False)
graphER.edge_properties["type"] = epropType
# and weights
if dicProperties["Weighted"]:
lstWeights = dicGenWeights[dicProperties["Distribution"]](graphER,dicProperties,nEdges,nExc) # generate the weights
epropW = graphER.new_edge_property("double",lstWeights) # crée la propriété pour stocker les poids
graphER.edge_properties["weight"] = epropW
return graphER
示例2: gen_fs
# 需要导入模块: from graph_tool import Graph [as 别名]
# 或者: from graph_tool.Graph import edge_properties["type"] [as 别名]
#.........这里部分代码省略.........
dicProperties["Density"] = rDens
else:
rDens = dicProperties["Density"]
nEdges = int(np.floor(rDens*nNodes**2))
dicProperties["Edges"] = nEdges
else:
nEdges = dicProperties["Edges"]
rDens = dicProperties["Density"]
nNodes = int(np.floor(np.sqrt(nEdges/rDens)))
graphFS.add_vertex(nNodes)
dicProperties["Nodes"] = nNodes
# on définit le nombre d'arcs à créer
nArcs = int(np.floor(rDens*nNodes**2)/(1+rFracRecip))
# on définit les paramètres fonctions de probabilité associées F(x) = A x^{-tau}
Ai = nArcs*(rInDeg-1)/(nNodes)
Ao = nArcs*(rOutDeg-1)/(nNodes)
# on définit les moyennes des distributions de pareto 2 = lomax
rMi = 1/(rInDeg-2.)
rMo = 1/(rOutDeg-2.)
# on définit les trois listes contenant les degrés sortant/entrant/bidirectionnels associés aux noeuds i in range(nNodes)
lstInDeg = np.random.pareto(rInDeg,nNodes)+1
lstOutDeg = np.random.pareto(rOutDeg,nNodes)+1
lstInDeg = np.floor(np.multiply(Ai/np.mean(lstInDeg), lstInDeg)).astype(int)
lstOutDeg = np.floor(np.multiply(Ao/np.mean(lstOutDeg), lstOutDeg)).astype(int)
# on génère les stubs qui vont être nécessaires et on les compte
nInStubs = int(np.sum(lstInDeg))
nOutStubs = int(np.sum(lstOutDeg))
lstInStubs = np.zeros(np.sum(lstInDeg))
lstOutStubs = np.zeros(np.sum(lstOutDeg))
nStartIn = 0
nStartOut = 0
for vert in range(nNodes):
nInDegVert = lstInDeg[vert]
nOutDegVert = lstOutDeg[vert]
for j in range(np.max([nInDegVert,nOutDegVert])):
if j < nInDegVert:
lstInStubs[nStartIn+j] += vert
if j < nOutDegVert:
lstOutStubs[nStartOut+j] += vert
nStartOut+=nOutDegVert
nStartIn+=nInDegVert
# on vérifie qu'on a à peu près le nombre voulu d'edges
while nInStubs*(1+rFracRecip)/float(nArcs) < 0.95 :
vert = np.random.randint(0,nNodes)
nAddInStubs = int(np.floor(Ai/rMi*(np.random.pareto(rInDeg)+1)))
lstInStubs = np.append(lstInStubs,np.repeat(vert,nAddInStubs)).astype(int)
nInStubs+=nAddInStubs
while nOutStubs*(1+rFracRecip)/float(nArcs) < 0.95 :
nAddOutStubs = int(np.floor(Ao/rMo*(np.random.pareto(rOutDeg)+1)))
lstOutStubs = np.append(lstOutStubs,np.repeat(vert,nAddOutStubs)).astype(int)
nOutStubs+=nAddOutStubs
# on s'assure d'avoir le même nombre de in et out stubs (1.13 is an experimental correction)
nMaxStubs = int(1.13*(2.0*nArcs)/(2*(1+rFracRecip)))
if nInStubs > nMaxStubs and nOutStubs > nMaxStubs:
np.random.shuffle(lstInStubs)
np.random.shuffle(lstOutStubs)
lstOutStubs.resize(nMaxStubs)
lstInStubs.resize(nMaxStubs)
nOutStubs = nInStubs = nMaxStubs
elif nInStubs < nOutStubs:
np.random.shuffle(lstOutStubs)
lstOutStubs.resize(nInStubs)
nOutStubs = nInStubs
else:
np.random.shuffle(lstInStubs)
lstInStubs.resize(nOutStubs)
nInStubs = nOutStubs
# on crée le graphe, les noeuds et les stubs
nRecip = int(np.floor(nInStubs*rFracRecip))
nEdges = nInStubs + nRecip +1
# les stubs réciproques
np.random.shuffle(lstInStubs)
np.random.shuffle(lstOutStubs)
lstInRecip = lstInStubs[0:nRecip]
lstOutRecip = lstOutStubs[0:nRecip]
lstEdges = np.array([np.concatenate((lstOutStubs,lstInRecip)),np.concatenate((lstInStubs,lstOutRecip))]).astype(int)
# add edges
graphFS.add_edge_list(np.transpose(lstEdges))
remove_self_loops(graphFS)
remove_parallel_edges(graphFS)
lstIsolatedVert = find_vertex(graphFS, graphFS.degree_property_map("total"), 0)
graphFS.remove_vertex(lstIsolatedVert)
graphFS.reindex_edges()
nNodes = graphFS.num_vertices()
nEdges = graphFS.num_edges()
rDens = nEdges / float(nNodes**2)
# generate types
rInhibFrac = dicProperties["InhibFrac"]
lstTypesGen = np.random.uniform(0,1,nEdges)
lstTypeLimit = np.full(nEdges,rInhibFrac)
lstIsExcitatory = np.greater(lstTypesGen,lstTypeLimit)
nExc = np.count_nonzero(lstIsExcitatory)
epropType = graphFS.new_edge_property("int",np.multiply(2,lstIsExcitatory)-np.repeat(1,nEdges)) # excitatory (True) or inhibitory (False)
graphFS.edge_properties["type"] = epropType
# and weights
if dicProperties["Weighted"]:
lstWeights = dicGenWeights[dicProperties["Distribution"]](graphFS,dicProperties,nEdges,nExc) # generate the weights
epropW = graphFS.new_edge_property("double",lstWeights) # crée la propriété pour stocker les poids
graphFS.edge_properties["weight"] = epropW
return graphFS