Hi Tiago,
sometimes, when delete the graph and create a new one, then plot it, the
plotted graph is shown upside down (in terms of the node text). So how could
we control the orientation of the graph? Or which parameter we should use to
always make node text shown in a correct orientation. Thanks a lot.
--
View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com…
Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.

Hi,
I'm suffering from the same issue mentioned in this post:
https://git.skewed.de/count0/graph-tool/issues/174
Namely, I'm trying to draw a graph that includes a lot of self-looping
edges, and my labels are being printed upside down. If I remove the
self-loops the labels are shown the right way up.
Is there a fix for it?
Thanks,
Charlie
--
View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com…
Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.

Dear Tiago,
I have a directed graph of about half a million nodes and approximately a
million edges following scale free behaviour and a power law degree
distribution. To test some of my hypothesis, I would like to generate random
smaller graphs (about 50 up to 200 nodes) representative of the big one.
When I used a sample function that samples straight away from the real
distribution of the big network, I have following problems:
- I generate unconnected nodes with both 0 in AND out degree.
- I generate small sub parts of a few nodes that are not connected to the
main graph.
- If only sampling from nodes with at least 1 degree, the generated graph is
coherent, but not representative anymore as I need a big portion of nodes
with either only one in or one out degree.
Here is the part of my script I used for that, where samples are drawn from
dictionaries of the degrees:
def sample_in():
a=np.random.randint(num)
k_in = in_degrees[a]
return k_in
def sample_out():
if sample_in()==0:
b=np.random.randint(num_out)
k_out=out_zero_zeros.values()[b]
return k_out
else:
b=np.random.randint(num)
k_out=out_degrees[b]
return k_out
N=200
g=gt.random_graph(N, lambda:(sample_in(), sample_out()),
model="constrained-configuration", directed=True)
I also tried sampling from a list of tuples as you have mentioned before in
the forum, but I didn't receive any results, as the tuples randomly drawn
from my list might not be combinable.
degs=[(7,1),(4,3),(5,6),(2,4),(6,8),(2,0),(3,5),(0,3),(2,7),(2,1)]
g = gt.random_graph(4, lambda i: degs[i], directed=True)
- Is there any option I could active that would help me in those cases I
described above?
- Is there a better way how to create representative small networks?
Any help on that issue will be much appreciated.
Best wishes,
Jana
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/

I am curious what is being used to calculate the standard deviation of the
average in gt.vertex_average and gt.edge_average
>>> t2=gt.Graph()
>>> t2.add_vertex(2)
>>> t2.add_edge(t2.vertex(0), t2.vertex(1))
>>> gt.vertex_average(t2, "in")
(0.5, 0.35355339059327373)
Now, shouldn't std be σ(n)=sqrt(((0-0.5)^2+(1-0.5)^2)/2)=0.5 ?
also q(n-1)=sqrt((0.5^2+0.5^2)/(2-1))~=0.70710
0.3535 is sqrt(2)/4 which happens to be σ(n-1)/2, so it seems there is some
relation to that.
A little bigger graph.
>>> t3=gt.Graph()
>>> t3.add_vertex(5)
>>> t3.add_edge(t3.vertex(0), t3.vertex(1))
>>> gt.vertex_average(t3, "in")
(0.2, 0.17888543819998318)
Now, we should have 0,1,0,0,0 series for vertex incoming degree.
So Windows calc gives σ(n)=0.4 and σ(n-1)~=0.44721, so where does 0.1788854
come from ?
Reason, I am asking because, I have a large graph, where the average looks
quite alright but the std makes no sense, as going by the histogram, degree
values are quite a bit more distributed than the std would indicate.
--
View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com…
Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.

Hi,
I was wondering if there is any way to assign vertex properties while
adding edges to the graph. for example using "add_edge_list" I can assign
edge properties but later I have to iterate through all vertices again to
assign their properties.
I know this is not a problem when the vertex property is of the type "int"
or "float" because then one can use "vprop.a = values", but in case of
"string" and "object" this method doesn't work
What would be the best/fastest way to handle this situation.
I guess it would be very helpful to extend the "add_edge_list" function to
accept vertex property in some way.
cheers,
--
Mohsen

I ran mcmc_equilibrate on a nested block state model in a weighted graph. As
per instructions, I copied the initially computed state in another object
with increased hierarchy depth to 10. However, this fixed the depth to 10.
Everything computed afterwards has depth 10 even if is clear that after 3 or
4 levels the nodes converge to one.
There are many empty branches and when I try to plot it with empty_branches
= False, I get an error stating it is not a tree.
RuntimeError: Invalid hierarchical tree: No path from source to target.
Did anybody perform any similar analyses?
The hierarchy after mcmc_equilibrate:
<NestedBlockState object, with base <BlockState object with 24 blocks (24
nonempty), degree-corrected, with 1 edge covariate, for graph <Graph
object, undirected, with 230 vertices and 11230 edges, edges filtered by
(<PropertyMap object with key type 'Edge' and value type 'bool', for
Graph 0x7fc3a89f1210, at 0x7fc3a64911d0>, False), vertices filtered by
(<PropertyMap object with key type 'Vertex' and value type 'bool', for Graph
0x7fc3a89f1210, at 0x7fc3a64912d0>, False) at 0x7fc3a89f1210>, at
0x7fc3a6491950>, and 10 levels of sizes [(230, 24), (24, 5), (5, 1), (1, 1),
(1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1)] at 0x7fc3a6491590>
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/

Dear all,
I am a bit confused about the use of the weighted network models for a
weight prediction task;
Suppose we have a weighted network where edges are integers. We fit a
SBM with a Poisson kernel as follows:
|data = gt.load_graph(...) # The adjacency matrix has integer entries,
and weights greater than zero are stored in data.ep.weights. state =
gt.inference.minimize_blockmodel(data, B_min=10, B_max=10, state_args=
{'recs':[data.ep.weights], 'rec_types' : ["discrete-poisson"]}) |
My question, is how can we obtain, from |state|, a point estimate of the
Poisson parameters in order to compute the distribution of the weights
between pairs of nodes.
Regards,
Adrien Dulac

Sir,
I am trying to follow the example on "edge prediction as binary
classification".
Here is my code:
*import graph_tool as gt
import pandas as pd*
# create a graph object in data frame format
*ndf =
pd.DataFrame({'Node1':['a','b','c','d','e'],'Node2':['c','e','b','a','d'],'Weight':[0.2,0.8,0.4,0.5,0.7],
'RandProp1':[1,2,3,1,2]})
ng = gt.Graph()
nprop = ng.new_edge_property("float")
ng.edge_properties['Weight'] = nprop* # important to map the properties to
the graph
*LayerProp = ng.new_edge_property('float')
ng.edge_properties['LayerProp'] = LayerProp*
*nvp =
ng.add_edge_list(ndf.values.tolist(),hashed=True,string_vals=True,eprops=[nprop,LayerProp])*
# minimizing the graph and inferring partitions
*stateA = gt.inference.minimize_nested_blockmodel_dl(ng,layers=True,
state_args=dict(ec=LayerProp,layers=True),
deg_corr=True,verbose=True)*
*L = 10
bs = stateA.get_bs()
bs += [np.zeros(1)]*(L-len(bs))
stateB = stateA.copy(bs=bs, sampling=True)
probs=([])
def collect_edge_probs(s):
p =
s.get_edges_prob([missing_edges[0]],entropy_args=dict(partition_dl=False))
probs[0].append(p);
missing_edges = [(1,2,1)] *# for layered network you need to specify layer
number
*gt.inference.mcmc_equilibrate(stateB,force_niter=1000,mcmc_args=dict(niter=10),
callback=collect_edge_probs,verbose=True)*
When I run this code, it gives me kernel died error. Please help.
I have another query that; how can we get the layer associated with the
node?
In the above code when I try the command
*for i in nvp: print(i)*
I get the output as : *a,c,b,e,d*
and when I type the command
*LayerProp.a*
I get the output: *PropertyArray([ 1., 2., 3., 1., 2.])*
How do I understand that because the order of addition of nodes depends on
the order they come along with add_edge_list command, while the LayerProp is
added in the order as mentioned in the property map.
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/

Hi
I was experimenting Kruskal performance against a data file for 100 graphs (n, m<20000) :
# =================================================
from time import clock
from sys import stderr, stdin
import graph_tool as gt
from graph_tool.topology import min_spanning_tree
import networkx as nx
# ------------ NetworkX Code ---------------------------
def kruskal_networkX(edges, n):
G=nx.Graph()
for a, b, w in edges:
G.add_edge(a,b,weight=w)
return sum(d['weight'] for (_,_,d) in nx.minimum_spanning_tree(G).edges(data=True))
# ------------ Graph_tool Code ---------------------------
def kruskal_gt(wedges,n):
g= gt.Graph(directed=False)
edges, weights= zip(*[((a,b),w) for (a,b,w) in wedges])
weight = g.new_edge_property("long long")
for a,b,w in wedges:
e=g.add_edge(a,b)
weight[e]=w
tree=min_spanning_tree(g, weights=weight)
return sum(b*weight[e] for (e,b) in zip(g.edges(), tree))
# ------------ Benchmark ---------------------------
def go(solver, L):
global duration
N=len(L)
k=1
while k<N:
edges=[]
n=L[k]
k+=1
for a in range(n):
d=L[k]
k+=1
for j in range(d):
b=L[k]
k+=1
w=L[k]
k+=1
if a<b:
edges.append([a,b-1,w])
start=clock()
print(solver(edges, n))
print("----------------------------")
duration+=clock()-start
# data
L=list(int(z) for z in stdin.read().split() if z.isdigit())
for solver in [kruskal_networkX, kruskal_gt]:
duration=0
go(solver, L)
print("%s : %.3f" %(solver.__name__, duration), file=stderr)
# =================================================
Outputs are in agreement but gt execution is very slow:
$ python3 gt.py < big.in > bench.out
kruskal_networkX : 15.721
kruskal_gt : 134.839
the bottleneck being within the following loop-filling the graph:
# --------------------------------------------
for a,b,w in wedges:
e=g.add_edge(a,b)
weight[e]=w
# --------------------------------------------
Probably, i'm filling the graph in the wrong way.
You can dowload the data file here:
https://drive.google.com/file/d/1y0fX1kopgzQEWgmRHRnouWHnMkuliwfw/view?usp=…

I am trying to use the graph-tool to perform a huge automated series of
path analyses as part of a commute-justice project I am working on. I am
very new to graph-tool and somewhat new to Python.
I have converted an ESRI shapefile of street centerlines in Los Angeles
County into a GT file using this short script:
https://github.com/CordThomas/shp2gt - i think it creates a valid
graph-tool network. Prior to that conversion I made sure the
OpenStreetMap centerlines were split at all intersections.
Running the code below gives me INF as the output to the dist_map returned
from the shortest_path request.
What diagnostics might i try to check the traversal of my network?
Running this on the Shapefile used to create the GT, I am able to use QGIS
to produce the shortest_path - see screenshot attached.
[image: Screen Shot 2018-11-29 at 1.54.38 PM (2).png]
I'd be glad to post my GT file somewhere if others wanted to poke at this
Thank you in advance,
Cord Thomas
Code:
from graph_tool import util as gutil
from graph_tool import topology as gtopo
from graph_tool.all import *
g = Graph(directed=False)
g.load('/ds/data/spatial/Network/streets/
tl_2016_06000_roads_la_clipped_extended_split.gt')
vertex_geoid = g.vertex_properties["geoid"]
vertices = gutil.find_vertex(g, vertex_geoid, '060372760005003')
start_vertex = vertices[0]
vertices = gutil.find_vertex(g, vertex_geoid, '060377019023041')
end_vertex = vertices[0]
dist_map = gtopo.shortest_distance(g, source=start_vertex,
target=end_vertex, weights=g.edge_properties['weight_dist'])
dist_map
returns inf
output of some data for verification:
>>> start_vertex
<Vertex object with index '7783' at 0x7f91c35693f0>
>>> end_vertex
<Vertex object with index '11265' at 0x7f91c35696f0>
>>> g.num_edges()
560517
>>> g.num_vertices()
549021