Am 11.07.21 um 23:31 schrieb arttu.malkamaki@helsinki.fi:
Hi,
I'm sorry, I'll try to be more specific.
I eventually need a matrix that I can plot as done in this post by ulgenklc: https://nabble.skewed.de/Temporal-community-detection-with-DSBM-tt4028581.ht...
Here, I use a subgraph with only two layers to demonstrate this seemingly trivial issue:
np.random.seed(42) gt.seed_rng(42)
state = minimize_nested_blockmodel_dl(g, state_args=dict(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"])))
This yields:
<NestedBlockState object, with base <LayeredBlockState object with 4610 overlapping blocks, 2 layers, degree-corrected, with 2 edge covariates, for graph <Graph object, undirected, with 82 vertices and 2305 edges, 2 internal vertex properties, 4 internal edge properties, and 8 levels of sizes [(82, 3), (3, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1)] at 0x2b1aa8982dc0>
While there are 4610 overlapping blocks in this stage, state.draw() divides the nodes neatly into three sensible communities. Hence, I know that the snippet of code that I need already exists somewhere in draw_hierarchy.
Then, I filter the edges in state.g by layer and use get_edge_blocks() to extract the layer-specific half-edges:
lay = [] for e in g.edges(): lay.append(g.ep.layer[e]==0) #edges in the first layer lay = np.array(lay, dtype="int") ft = g.new_edge_property("bool") ft.a = lay state.g.set_edge_filter(ft) be = state.levels[0].get_edge_blocks()
This is where I struggle to find a way to extract the desired information. My best guess on how to extract the layer-specific node memberships from _be_ is the following:
s = OverlapBlockState(state.g, b=be) #state.g with filter on mb = s.get_majority_blocks() for v in g.vertices(): print(mb[v])
If I compare the _mb_ for the discrete layers, the memberships vary slightly (this is what I need), but I'm unsure whether this is the correct way to extract this information?
If "be" is the property map returned by state.levels[0].get_edge_blocks(), then
bm = g.new_vp("vector<int>", val=[0] * state.levels[0].get_B()) for e in g.edges(): if layer[e] != 0: continue u, v = e u, v = sorted((u, v)) r, s = be[e] bm[u][r] += 1 bm[v][s] += 1
will give you the memberships in each group at layer 0 in the property map "bm". Is this what you want?
Best, Tiago