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

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, everyone!
I met a problem when I'm learning how to use graph-tool. I read the paper,
network reconstruction and community detection from dynamics, and I am
trying to achieve the same result. When I followed the same settings for
real networks with synthetic dynamics, their similarities were just about
0.2. I have a question about how to control the number of infection events
per node,a, for the first model and the number of micro-state, M, for the
second model. The whole process is shown as following.
import graph_tool.all as gt
from matplotlib import cm
g = gt.collection.konect_data["openflights"] ## airport network with SIS
dynamics
gt.remove_parallel_edges(g)
g = gt.extract_largest_component(g, prune=False)
#simulation of an empirical dynamic model
# The algorithm accepts multiple independent time-series for the
# reconstruction. We will generate 100 SIS cascades starting from a
# random node each time, and uniform infection probability beta=0.2.
ss = []
for i in range(100):
si_state = gt.SISState(g, beta=.2)
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 note at each time.
s = gt.group_vector_property(s)
ss.append(s)
# 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
# Create reconstruction state
rstate = gt.EpidemicsBlockState(u, s=ss, beta = None, r=1e-6,
global_beta=.2,
state_args=dict(B=20), nested=False,
aE=g.num_edges())
# Now we collect the marginals for exactly 10,000 sweeps, at
# intervals of 10 sweeps:
gm = None
bm = None
betas = []
def collect_marginals(s):
global gm, bm
gm = s.collect_marginal(gm)
b = gt.perfect_prop_hash([s.bstate.b])[0]
bm = s.bstate.collect_vertex_marginals(bm, b=b)
betas.append(s.params["global_beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10,
xstep=0),
callback=collect_marginals)
print("Posterior similarity: ", gt.similarity(g, gm, g.new_ep("double", 1),
gm.ep.eprob))
print("Inferred infection probability: %g ± %g" % (mean(betas), std(betas)))
##########################################################
g = gt.GraphView(gt.collection.konect_data["maayan-foodweb"],
directed=True)##a food web network with Ising dynamic
gt.remove_parallel_edges(g)
# The algorithm accepts multiple independent time-series for the
# reconstruction. We will generate 1000 Ising cascades starting from a
# random node each time, and the uniform inverse temperature beta=0.2.
ss = []
for i in range(1000):
si_state = gt.IsingGlauberState(g, beta=.1)
s = [si_state.get_state().copy()]
si_state.iterate_async(niter=1000)
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 note at each time.
s = gt.group_vector_property(s)
ss.append(s)
u = g.copy()
u.clear_edges()
ss = [u.own_property(s) for s in ss]
rstate = gt.PseudoIsingBlockState(g,s=ss,beta=0.1,state_args=dict(B=1),
nested=False, aE=g.num_edges())
gm = None
bm = None
betas = []
def collect_marginals(s):
global gm, bm
gm = s.collect_marginal(gm)
b = gt.perfect_prop_hash([s.bstate.b])[0]
bm = s.bstate.collect_vertex_marginals(bm, b=b)
betas.append(s.params["beta"])
gt.mcmc_equilibrate(rstate, force_niter=1000, mcmc_args=dict(niter=10,
xstep=0),
callback=collect_marginals)
print("Posterior similarity: ", gt.similarity(g, gm, g.new_ep("double", 1),
gm.ep.eprob))
print("Inversed temperature: %g ± %g" % (mean(betas), std(betas)))
Moreover, I also wonder how to do a nested version for the same network.
Please let me know if you need more information on the question. otherwise,
I hope to hear how this can be achieved using graph-tool?
Thanks,
Gege Hou
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/

Hi,
I am computing a weight for each edge, in a graph of some million nodes and
about 50 mil edges. Initially, it was doing 25000 edges per minute, so it
should have finished processing in about 30+ hours. Now I check the server
for results after more than 72 hours, and the process is still running, but
very slowly, doing less than 1000 edges per minute.
Is there anything I am doing wrong, or what could be the reason for such a
slowdown?
I list here the code:
def compute_exclusivities(g):
count = 0
excl = g.new_edge_property("double")
g.edge_properties["Exclusivity"] = excl
edges = g.get_edges([g.edge_properties["label_id"]])
for edge in edges:
edges_of_head = g.get_out_edges(edge[0],
[g.edge_properties["label_id"]])
count_edges_ofhead_sametype = len(np.where(np.where(edges_of_head ==
edge[2])[1] == 2)[0])
edges_of_tail = g.get_in_edges(edge[1],
[g.edge_properties["label_id"]])
count_edges_oftail_sametype = len(np.where(np.where(edges_of_tail ==
edge[2])[1] == 2)[0])
excl[g.edge(edge[0], edge[1])] = 1 / (count_edges_ofhead_sametype +
count_edges_oftail_sametype - 1)
count = count + 1
if count % 1000 == 0:
print(count, " exclusivities computed")
Thanks,
Ioana
--
Sent from: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/

Dear Graph-Tool Community,
I am interested in analysing the hierarchical partitions generated by the nested blockmodel. Specifically, after I have generated a nested SBM; I would then like to post-process this and calculate measures such as eigenvector centrality for a given hierarchical node; save this as a property, and then in visualisation apply either a size or colormap constraint to said node weighted by its centrality.
Using the collection data;
g = gt.collection.data["celegansneural”]
state = gt.minimize_nested_blockmodel_dl(g)
I can then ascertain what my levels are with;
l1state = state.levels[1].g
l2state = state.levels[2].g
etc.
I can then calculate eigenvector centrality of a given hierarchical partition as follows;
ee1, x1 = gt.eigenvector(l1state)
ee2, x2 = gt.eigenvector(l2state)
1) This presumably then needs to be saved as a hvprops(?!). But, I am unclear how to do this, not least in a way that I know for sure that the correct hierarchical vertices within l1state and l2state are aligning to the generated centrality measures of x1 and x2, respectively.
2) Furthermore, if/when that is achieved, how can I call upon this in drawing, for example to size the level 1 hierarchical vertices according to centrality, or level 2 vertices by another measure, etc.?
Hugely grateful for any solutions!
James

I'm attempting to use get_edges_prob to find the most likely missing edges
out of every possible non-edge. I know every possible edge is O(n^2).
Currently I'm sampling the like this:
non_edges_probs = [[] for _ in range(len(non_edges))]
def collect_edge_probs(s):
s = s.levels[0]
for i, non_edge in enumerate(non_edges):
p = s.get_edges_prob([non_edge], [],
entropy_args=dict(partition_dl=False))
non_edges_probs[i].append(p)
gt.mcmc_equilibrate(nested_state,
force_niter=100,
mcmc_args=dict(niter=10),
callback=collect_edge_probs,
verbose=True)
Is there a way to speed this up at all? If not, is there a heuristic I can
use to reduce the number of possibilities?
Currently I'm using vertex similarity measures to cut the possibilities,
but I'm wondering if there is a heuristic involving just the NestedState.
Any help appreciated!

I'm saving NestedState with pickle and then loading it later to use
get_edges_prob.
nested_state = pickle.load(
open(f"output/graphtool_output/pickle/{name}_nested_blockstate.p",
"rb"))
I realized that NestedState needs a reference to the underlying graph for
get_edges_prob to work. So, I try this.
G = gt.load_graph(f'output/graphtool_output/{name}.graphml')
nested_state.g = G
Now, get_edges_prob is working if I use the base level of the state, like
so:
def collect_edge_probs(s):
s = s.levels[0]
for i, non_edge in enumerate(non_edges):
p = s.get_edges_prob([non_edge], [],
entropy_args=dict(partition_dl=False))
non_edges_probs[i].append(p)
If I remove this " s = s.levels[0]" I'm getting an error about "invalid
edge descriptor". Is there some other reference I need to recover for this
to work correctly?
Any help appreciated!