Hi everyone,
I was wondering if it would be possible to provide some more examples of
how to run a nested mixed membership SBM with edge weights. The new version
seems to have removed the "overlap=True" option for state_args in the
minimize_* functions.
Is this the correct way to do it now?
import graph_tool as gta
> import numpy as np
> g = .... # build graph
> e_score = .... #Set edge weights
> state_args = dict(
> deg_corr=deg_corr,
> base_type=gta.inference.overlap_blockmodel.OverlapBlockState,
> B=2*g.num_edges(), #B_max
> deg_corr=True,
> recs=[e_score],
> rec_types=["real-normal"])
> state = gta.inference.minimize_nested_blockmodel_dl(
> g,
> state_args=state_args,
> multilevel_mcmc_args=dict(verbose=True))
> # improve solution with merge-split
> state = state.copy(bs=state.get_bs() + [np.zeros(1)] * 4, sampling=True)
for i in range(100):
> if i%10==0: print(".", end="")
> ret = state.multiflip_mcmc_sweep(niter=10, beta=np.inf, verbose=True)
I am currently running this for a fully connected bipartite graph with 3454
nodes and 55008 edges. I understand it would take longer than the
non-overlapping version, but do you have any suggestions on how to speed it
up? The non-overlapping version takes about 15 minutes, while the
overlapping version is still running after 1 day.
Thanks for your help,
Eli
--
PhD Candidate, Phil Bourne's lab
University of Virginia
_______________________________________________
graph-tool mailing list -- graph-tool(a)skewed.de
To unsubscribe send an email to graph-tool-leave(a)skewed.de

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.

Hello,
I'm studying political coalitions over time (three time slices) and across discrete types of relationships (collaboration, ideological similarity, and discursive similarity). Since graph-tool offers (the only) principled approach that does not require arbitrary user-specified parameters (such as 'resolution' or 'coupling'), I would very much like to use it for my analysis.
I'm trying to fit a SBM to a graph with edges divided into distinct layers (three time slices X three types of relationships). Each edge has a discrete weight in the range of [0, 3], with weight referring to the 'strength' of the relationship. Not all nodes participate in all layers.
I'm interested in how/if the block membership varies across layers that I expect to be somewhat dependent on one another (hence I would like to avoid fitting a separate SBM to each layer). In my ideal scenario, I would be using the NestedBlockState with LayeredBlockState as base and allowing for overlaps across layers:
state=NestedBlockState(g, base_type=LayeredBlockState, state_args=dict(deg_corr=True, overlap=True, layers=True, ec=g.ep.layer, recs=[g.ep.weight], rec_types=["discrete-binomial"]))
dS, nmoves=0, 0
for i in range(100):
ret=state.multiflip_mcmc_sweep(niter=10)
dS+=ret[0]
nmoves+=ret[1]
print("Change in description length:", dS)
print("Number of accepted vertex moves:", nmoves)
mcmc_equilibrate(state, wait=1000, mcmc_args=dict(niter=10), verbose=True)
bs=[]
def collect_partitions(s):
global bs
bs.append(s.get_bs())
mcmc_equilibrate(state, force_niter=10000, mcmc_args=dict(niter=10), verbose=True, callback=collect_partitions)
pm=PartitionModeState(bs, nested=True, converge=True)
pv=pm.get_marginal(g)
bs=pm.get_max_nested()
state=state.copy(bs=bs)
Two questions:
Q1)
This is taking very long (days) on a high performance cluster and actually I haven't seen it finishing up for once. Is my model specification correct or simply too complex? If the latter, is there a better strategy to perform my analysis? All I can think of is to revert to a non-nested model and/or reduce the number of layers and/or edges:
state=LayeredBlockState(g, deg_corr=True, overlap=True, layers=True, ec=g.ep.layer, recs=[g.ep.weight], rec_types=["discrete-binomial"])
dS, nattempts, nmoves=state.multiflip_mcmc_sweep(niter=1000)
print("Change in description length:", dS)
print("Number of accepted vertex moves:", nmoves)
mcmc_equilibrate(state, wait=1000, nbreaks=2, mcmc_args=dict(niter=10), verbose=True)
bs=[]
def collect_partitions(s):
global bs
bs.append(s.b.a.copy())
mcmc_equilibrate(state, force_niter=10000, mcmc_args=dict(niter=10), verbose=True, callback=collect_partitions)
pm=PartitionModeState(bs, converge=True)
pv=pm.get_marginal(g)
Q2)
Say that the model runs and yields a neat NestedBlockState (or LayeredBlockState) object with X overlapping blocks, 9 layers, degree-corrected, with 2 edge covariates, for graph <Graph object, undirected, with 220 vertices and 11322 edges, 2 internal vertex properties, 4 internal edge properties>.
Now, in previous posts there are mentions about the number of nodes multiplying by the number of layers when 'overlap=True', but in my experiments with only two layers, this does not seem to be the case and I struggle to find a way to extract the layer-specific block and respective memberships of nodes.
I've tried iteration over vertices, but what I eventually need is a 2d_array [y=all nodes in g, x=all layers in g, values=most likely block membership] in order to map how/if the block membership of each node varies across those layers in which they participate (ideally somehow denoting non-participation in the layer with NaN or some unique value). Is there some way to get there?
l=state.get_levels()[0] #NestedBlockState
B=l.get_nonempty_B()
bv=l.get_overlap_blocks()[0]
z=np.zeros((g.num_vertices(), B)) #to be filled with most likely block membership with potential overlaps across ALL layers, but I need the layer-specific information
for i in range(g.num_vertices()):
z[int(i), :len(z[v])]=bv[i].a+1
for v in range(g.num_vertices()*max(g.ep.layer)+1): #to see if the number of vertices multiplied by layers, which it didn't
print(bv[v])
Many thanks,
Arttu

Hi everyone!
I've written an open-source package for interactive graph visualization with Python and HTML/CSS/JS called gravis.
It supports graph-tool by accepting its Graph object as input for the provided plotting functions. The output is a Figure object that can be displayed in a web browser (separate window or inline in Jupyter notebook) and exported to a standalone HTML file or a static image (JPG, PNG, SVG). In the browser you can drag around nodes, play with layout algorithms and their parameters, see additional information when hovering over or clicking on an element, and more.
The package and its documenation can be found here:
https://pypi.org/project/gravishttps://robert-haas.github.io/gravis-docs
The examples in the documentation contain a (preliminary) notebook that demonstrates the combined use of graph-tool and gravis:
https://robert-haas.github.io/gravis-docs/code/examples/external_tools/grap…
I hope you find it useful for inspecting your graphs and networks! Feedback of any sorts is always welcome. Please keep in mind that the package is in its beta version, so things may still change slightly in future releases, but you'll always be able to download any version from PyPI.

Hi,
I'd like to perform a DFS to find some nodes. However, I only need the first occurrences of these nodes.
To visualize the problem, I have drawn a little example graph: https://i.imgur.com/BgdUzOz.png
The graph is directed but has no further constraints. The search should start at the orange node.
It should reveal the two nearby red nodes but not the red node labeled with "This one not".
Precisely said: It should not reveal a red node that is dominated by another red node.
If I would implement the DFS by myself I just wouldn't follow the outgoing edges of a red node (and stop the search for this path).
However, within graph-tool I have only found a way to stop the _whole_ search with an StopSearch exception.
Is there a way to use graph-tool to perform a search like I have described it?
Kind regards,
Gerion
_______________________________________________
graph-tool mailing list -- graph-tool(a)skewed.de
To unsubscribe send an email to graph-tool-leave(a)skewed.de