In my network, beside to the information of which two nodes create an edge, I have the information of the time duration which an edge has lasted. I included this information as weight and used them as the covariate
 of the SBM. The results seems more reasonable compared to not considering any weights. However, the number of blocks changes slightly in each time I ran my script with the piece of code given before. So I was wondering if I must run minimize_nested_blockmodel_dl function by determining the higher number of MCMC iterations as argument, and then I would get more accurate results with highest confidence interval or I just need to repeat this function in a loop and then compute the mean number of blocks? I hope my question makes sense.

Thanks again.

On Thu, Apr 26, 2018 at 3:43 PM, Tiago de Paula Peixoto <> wrote:
On 26.04.2018 12:52, Zahra Sheikhbahaee wrote:
> Hi there,
> I am trying to include the edge weights by taking to account an edge covariate matrix for the nested block model inference. Well, Each time I run the code on my data set I get slightly different results both in terms of number of blocks and the nodes in each block.

This is because the inference is made using MCMC, which is a stochastic
algorithm. You have to run it multiple times, and select the result with
largest posterior probability (if you only want a point estimate).

> This is my code:
> state = minimize_nested_blockmodel_dl(g, state_args=dict(recs=[g.edge_properties["weight"]], rec_types=["discrete-geometric"]))
> state.draw(edge_color=prop_to_size(g.edge_properties["weight"], power=1, log=True),
>                ecmap=(, .6),
>                eorder=g.edge_properties["weight"],
>                edge_pen_width=prop_to_size(g.edge_properties["weight"], 1, 4, power=1, log=True),
>                edge_gradient=[],
>                vertex_text=g.vertex_properties["attribute"],
>                vertex_text_position="centered",
>                vertex_text_rotation=g.vertex_properties['text_rotation'],
>                vertex_font_size=10,
>                vertex_font_family='mono',
>                vertex_anchor=0,
>                output_size=[1024*2,1024*2],
>                output="DiscreteGeometric_%s.pdf"%(eventName))

Although it not important for the questions you have raised, it is not very
useful to post incomplete code. Normally, for troubleshooting purposes, it
is necessary for you to provide a _minimal_ and _self-contained_ program
that anyone could execute and verify the problem you are reporting.

> I appreciate if you explain what your approach would be and how I can run
> graph-tool using the covariance matrix of edges in order to get
> statistically reliable results?

This is covered in detail in the HOWTO:

and also in many papers, e.g.

However, I'm note sure what you mean by "covariance matrix of edges". The
approach in question deals with graphs with edge covariates (a.k.a.
weights). A covariance matrix usually refers to something else.

> Is there also any way to get the full posterior of each node belonging to
> each block?

This is also explained in detail in the HOWTO:


Tiago de Paula Peixoto <>
graph-tool mailing list