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/

Hi again,
I'm writing a small package that builds on graph-tool, but not on its graphics capabilities (also because I have to represent other things rather than the graph itself). Still I could use some of the functions "under the hood" for my purposes. I have a question about gt.draw.get_hierarchy_control_points(): the function returns the Bézier spline control points for edges in a given graph, but I'm having difficulties in understanding how this information is encoded. For a single edge in graph, I have dozens of values as control points (half dozens + 2), hence I suspect all splines going from node A to the root of a hierarchy and back to node B are encoded there, and control points should be taken 6 by 6 (3x2 by 3x2 coordinates?). How (x,y) for control points are encoded then: (x, x, x, y, y, y) or (x, y, x, y, x, y)? What are the 2 additiona values I have for each vector? Also, are values absolute or relative to one node in particular (A, B or root...)?
Thanks
d

Hi all,
I've been trying to learn more about the Bayesian inference techniques
introduced in
https://journals.aps.org/prl/pdf/10.1103/PhysRevLett.123.128301 and have
been having much joy trying the graph-tool software - it is a fantastic
tool. I have been having difficulty understanding how one would estimate
both the posterior distribution of a graph and the corresponding
transmission probabilities in the SI dynamics example as suggested in the
Twitter example of the aforementioned paper. For example taking the example
from the cookbook (which is very clear) regarding these ideas but now
assigning a edge property for the transmission probabilities (although
leaving them homogeneous across all edges)
#####################################
### Look at using an edge based beta value
# We will first simulate the dynamics with a given network
g = gt.collection.data["dolphins"]
tau = g.new_ep("double", .7) # transmission probabilities
### simulate the dynamics
ss = []
for i in range(100):
si_state = gt.SIState(g, beta=tau)
s = [si_state.get_state().copy()]
for j in range(10):
si_state.iterate_sync()
s.append(si_state.get_state().copy())
# Each time series should be represented as a single vector-valued
# vertex property map with the states for each node at each time.
s = gt.group_vector_property(s)
ss.append(s)
####################################
and now considering the inference part my confusion is arising from how to
assign a prior transmission value as a edge property when we are
initializing the graph as empty. So below I am just changing the function
collect_marginals as I want the local transmission probs (accessed through
get_x() ) rather than the global beta as before and also not using a global
beta in the block state. I assume here that if we were only interested in
the transmisison probs i.e., not the graph posterior, then we'd assign an
edge property to the graph but if we assume that we also don't know the
edges I don't see how to assign the prior distribution. (I don't think beta
= .7 is setting the prior to 0.7 beforehand but I may be mistaken here?)
####################################
# Prepare the initial state of the reconstruction as an empty graph
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss] # time series properties need to be
'owned' by graph u
def collect_marginals(s):
global gm, bs
gm = s.collect_marginal(gm)
bs.append(s.bstate.b.a.copy())
betas.append(s.get_x().copy())
# Create reconstruction state
# but don't use a global beta and also don't state the no. of edges
# note the prior beta is the same as the true one?
rstate = gt.EpidemicsBlockState(u, s=ss, beta=.7, r=1e-6,
nested=False)
# Now we collect the marginals for exactly 100,000 sweeps, at
# intervals of 10 sweeps:
gm = None
bs = []
betas = []
gt.mcmc_equilibrate(rstate, force_niter=10000, mcmc_args=dict(niter=10,
xstep=0),
callback=collect_marginals)
##################################
but when I access the arrays within betas after they all just consist of 0
values (through betas[i].get_array()) which makes me think I am not doing
this process correctly (the graph similarities with the posterior and actual
are also negligible~0.05).
Any help with this problem (I may be doing something very incorrect in the
process) and how to correctly implement an edge prior without knowledge of
the graph would be greatly appreciated as I would like to delve further into
these techniques.
--
Sent from: https://nabble.skewed.de/

Hello Tiago,
It looks like the commit "e3c57b270640f9948d7fda7459376eb40d600719" has introduced a bug in the cairo_draw that I have fixed on my machine but I would like to create a merge request for the same. In short the following code throws the error:
import graph_tool.all as gt
g = gt.collection.data['karate']
gt.graph_draw(g, vertex_pen_width=5, vertex_color = 'k', output='test.png')
The error is:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py", line 1145, in graph_draw
x, y, w, h = fit_view
TypeError: cannot unpack non-iterable bool object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 4, in <module>
gt.graph_draw(g, vertex_pen_width=1, output='test.png')
File "/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py", line 1153, in graph_draw
x, y, zoom = fit_to_view_ink(g, pos, output_size, vprops,
File "/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py", line 1345, in fit_to_view_ink
eprops = dict(eprops, pen_width=min_lw(eprops.get("pen_width")))
File "/usr/lib/python3/dist-packages/graph_tool/draw/cairo_draw.py", line 1342, in min_lw
lw = max(lw, 0.1)
TypeError: '>' not supported between instances of 'float' and 'NoneType'
I tracked the error and it looks to me that in the function ``min_lw`` which itself is inside ``fit_to_view_ink``, if user passes ``pen_width`` only for edges or only for vertices, the other becomes ``None`` and should be handled properly. I could fix this by adding an extra ``if`` condition as follows:
# work around cairo bug with small line widths
def min_lw(lw):
if isinstance(lw, PropertyMap):
lw = lw.copy()
x = lw.fa
x[x < 0.05] = 0.1
lw.fa = x
else:
if lw == None:
lw = 0.1
lw = max(lw, 0.1)
return lw
I would like to push this change upstream, but you seem to have denied my access request so I can't create a merge request. If you think this is fine, could you make the change? In general, how do I fix bugs if/when I find them if access on git.skewed is not available?
Thanks and regards,
Snehal Shekatkar

Hi,
the dominator_tree function in graph_tool.topology outputs a vertex property map that codifies a graph.
To use the other graph_tool algorithms, it would be beneficial to get the dominator_tree back as Graph (or better GraphView).
Is there already a way to do this? Otherwise, how do you like the idea to implement it?
A possible use case is it to check, if a dominates b.
This would be the pseudo code, if dominator_tree returns a graph like object:
dom_tree = graph_tool.topology.dominator_tree(graph, start, as_graph=True)
try:
next(graph_tool.topology.all_paths(a, b))
return True
except StopIteration:
return False
This is without (the path search runs in Python, not that much LOCs but more difficult to understand in my opinion):
dom_tree = graph_tool.topology.dominator_tree(graph, start, as_graph=True)
while b:
if a == b:
return True
b = dom_tree[b]
return False
Best,
Gerion

Hello,
I'm in need of an efficient network format for frontend code, and I figured
that since you already have one I shouldn't reinvent the wheel. I'm
currently trying to implement it with Node + Typescript. I'm reading the
docs page for the format carefully, but I'm stuck at a point. I'm not used
to working at the level of bytes so if this is a waste of time, I'm sorry.
I'm using the "7th graders" graph from ns as an example. Everything is
working fine up to the number of nodes:
```
{
magicString: '⛾ gt',
version: 1,
bigEndian: false,
stringLength: 216,
commentString: 'graph-tool binary file (http:://graph-tool.skewed.de)
generated by version 2.34dev (commit 1f792136, Thu Jul 2 23:05:34 2020
+0200) stats: 29 vertices, 740 edges, directed, 6 graph props, 2 vertex
props, 2 edge props',
directed: true,
numNodes: 29,
usedBytesForNodeIndex: 1
}
```
But, for grabbing the neighbors for every node I'm stuck. I can read the
number of neighbors for the first node properly: 22. But, this is giving
nonsense when I read it as LE, but it's working as BE, even though
Big-Endian byte in the beginning was 0? That's my first source of confusion.
Next, after reading that 64bit int I move the offset forward by 8 and start
reading the neighbors (each consuming 1 byte because numNodes = 29 < 64?). I
get: "[0, 0, 0, 0, 0, 0, 0, 5, 7, 10, 11, 13, 15, 16, 18, 20, 21,
25, 26, 7, 10, 11]". Clearly I'm messing something up here. It's misaligned
by 7 bytes. If I move the offset forward by 7 I get the proper "[5, 7, 10,
11, 13, 15, 16, 18, 20, 21, 25, 26, 7, 10, 11, 1, 4, 5, 10, 11, 13,
15]". And, the number of nodes I read for the second vertex is garbage.
I'm doing something wrong at this point. Sorry if this is obvious and I'm
wasting time. Any idea what I'm missing here?
Thanks for any help!
--
Sent from: https://nabble.skewed.de/