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="constrainedconfiguration", 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://maindiscussionlistforthegraphtoolproject.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(((00.5)^2+(10.5)^2)/2)=0.5 ?
also q(n1)=sqrt((0.5^2+0.5^2)/(21))~=0.70710
0.3535 is sqrt(2)/4 which happens to be σ(n1)/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 σ(n1)~=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://maindiscussionlistforthegraphtoolproject.982480.n3.nabble.com…
Sent from the Main discussion list for the graphtool project mailing list archive at Nabble.com.
Dear GraphTool 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 postprocess 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
Dear community / Tiago
I have a hierarchical partition of a nested block state.
The original network contained 4453 vertices and 50051 edges.
state.print_summary()
l: 0, N: 4453, B: 126
l: 1, N: 126, B: 46
l: 2, N: 46, B: 20
l: 3, N: 20, B: 9
l: 4, N: 9, B: 3
l: 5, N: 3, B: 1
I want to extract the community label of each vertex of each possible hierarchical level.
To do this I wrote a loop based upon the guide at https://graphtool.skewed.de/static/doc/demos/inference/inference.html
Where vertexblocksdf is simply a df populated with the vertex numbers 04452.
for idx in range(len(vertexblocksdf)):
r = levels[0].get_blocks()[idx] # group membership of node idx in level 0
vertexblocksdf.ix[idx, 'level0'] = r
r = levels[0].get_blocks()[r] # group membership of node idx in level 1
vertexblocksdf.ix[idx, 'level1'] = r
r = levels[0].get_blocks()[r] # group membership of node idx in level 2
vertexblocksdf.ix[idx, 'level2'] = r
r = levels[0].get_blocks()[r] # group membership of node idx in level 3
vertexblocksdf.ix[idx, 'level3'] = r
r = levels[0].get_blocks()[r] # group membership of node idx in level 4
vertexblocksdf.ix[idx, 'level4'] = r
r = levels[0].get_blocks()[r] # group membership of node idx in level 5
vertexblocksdf.ix[idx, 'level5'] = r
But, I am getting strange results. My level0 column variables make sense, with 126 possibilities (as per l0 above). But my level1 column is a number between 0 and 13; of which none of my levels have 14 blocks. My level2 output is either 0 or 1, again doesn’t make sense! Level35 are all simply 0.
*this also reproduces the same behaviour if done manually without loop.
Any ideas??
James
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
Dear Tiago,
Thanks for building this wonderful package!
As a novice in Python I'm struggling to install this package My operating
system is MacOS and I installed graphtool via Homebrew.
It seems the installation was successful. When compiling, the command
'./configure' doesn't work, could you please give the further instructions?
Many thanks,
Yingjie

Sent from: http://maindiscussionlistforthegraphtoolproject.982480.n3.nabble.com/
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), degreecorrected, 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://maindiscussionlistforthegraphtoolproject.982480.n3.nabble.com/
Just to iterate:
If I have a graph
edge_list=[[0,1,1],[0,2,1],[0,3,1],[1,2,1],[1,3,1],[2,3,1],[0,4,2],[0,5,2],[0,6,2],[1,7,2],[1,8,2],[1,9,2],[2,10,2],[2,11,2],[2,12,2],[3,13,2],[3,14,2],[3,15,2],[4,5,2],[4,6,2],[5,6,2],[7,8,2],[7,9,2],[8,9,2],[10,11,2],[10,12,2],[11,12,2],[13,14,2],[13,15,2],[14,15,2]]
g = Graph(directed=False)
weight = g.new_edge_property('int')
g.add_edge_list(edge_list, eprops=[weight])
and a nested blockmodel
state = minimize_nested_blockmodel_dl(g, state_args=dict(eweight=weight))
then I can either draw the graph directly with a partition from a given level l
state.project_level(l=0).draw()
or store the partition in a property map
group = state.project_partition(l=0, j=0)
and then use this map in conventional drawing
graph_draw(g, vertex_fill_color=group)
Best
Haiko
Hi!
For the project I'm working on I need to calculate distances on a graph
from a couple of vertices to all other vertices. The
topology.shortest_distance can only do either from all vertices or from a
single one, and to save time I'd like this to run in parallel, so I set out
to implement this in C++. I took inspiration from graphtool's
implementation of shortest_distance for pairwise distances in unweighted
graphs (running BFS from all vertices in parallel), and managed to modify
that to only run from some vertices. However I ran into a problem trying to
do the same for weighted graphs. I think the problem I have is that when
passing the vector for distances to all vertices it is supposed to be a
property map and not a vector, but I cannot figure out how to get a 1d
property map from a 2d property map on a C++ level, basically I pass a
vector<double> property map to my function but I need to pass a simple
double property map to the dijskstra function from boost. Could anyone
please help me point to how would I do that? Or is my approach wrong
completely? What most confuses me that the same approach works fine for
breadth_first_search.
The errors I'm getting in compilation:
/usr/include/boost/graph/dijkstra_shortest_paths_no_color_map.hpp:43:63:
error: no type named ‘value_type’ in ‘struct
boost::property_traits<std::vector<double> >’
43  typedef typename property_traits<DistanceMap>::value_type
Distance;
/usr/include/boost/pending/indirect_cmp.hpp:32:78: error: no type named
‘value_type’ in ‘struct boost::property_traits<std::vector<double> >’
32  typedef typename
boost::property_traits<ReadablePropertyMap>::value_type T;

^
/usr/include/boost/pending/indirect_cmp.hpp:33:76: error: no type named
‘key_type’ in ‘struct boost::property_traits<std::vector<double> >’
33  typedef typename
boost::property_traits<ReadablePropertyMap>::key_type K;
Thank you,
Mikuláš
Hi all,
gt allows creating graph views where vertices and/or edges are filtered out. The principle is described in the documentation:
"Vertices or edges which are to be filtered should be marked with a PropertyMap with value type bool, and then set with set_vertex_filter() or set_edge_filter() methods. By default, vertex or edges with value '1' are kept in the graphs, and those with value '0' are filtered out." (https://graphtool.skewed.de/static/doc/quickstart.html#graphfiltering)
Given a layered graph, where layers are coded via an edge property, I want to draw the graphs layer by layer.
This is an example graph:
from graph_tool.all import *
import numpy as np
import pandas as pd
# data
edge_list = pd.DataFrame(np.array([[0, 1, 0], [1, 2, 1], [2, 0, 2]]), columns=['i', 'j', 'layer'])
# create graph
g = Graph(directed=False)
ep_layer = g.new_edge_property('int')
g.add_edge_list(edge_list.values, eprops=[ep_layer])
g.edge_properties['layer'] = ep_layer
# draw graph with edge colors showing the layers
graph_draw(g, edge_color=g.ep.layer)
It is possible to draw a single layer (in this example layer 0) in this complicated way:
# set layer to be drawn
layer = 0
# create graph view
ep_filter = g.new_edge_property('bool')
for i in range(0, len(edge_list)):
e = g.edge(edge_list['i'][i], edge_list['j'][i])
if edge_list['layer'][i] == layer:
ep_filter[e] = True
else:
ep_filter[e] = False
g_filter = GraphView(g, efilt=ep_filter)
# draw filtered graph
graph_draw(g_filter, edge_color=g.ep.layer)
If I proceed this way I will also have to create a vertex property map to filter unused vertices and do these steps for all layers I want to draw.
But isn't there a more elegant way  preferably handling vertices and edges in the same step?
Many thanks and best wishes
Haiko