Multilayer Graph Class

We have created a Python class to store the graph information used by the multilayer belief propagation.the same class can be used for both the single layer and the multilayer case. In addition we have created a class for generating realization of the Dynamic Stochastic Block Model.

Multilayer Graph

class modbp.MultilayerGraph(intralayer_edges, layer_vec, interlayer_edges=None, comm_vec=None, directed=False)[source]

Wrapper class for storing a ‘multilayer graph’ that can be used to call the modularity belief propagation A graph here is represented by a collection of igraphs (each one representing a “layer”) as well as a set of edges between the layers. In this formulation, each node can only be present in a single layer

__init__(intralayer_edges, layer_vec, interlayer_edges=None, comm_vec=None, directed=False)[source]
Parameters:
  • intralayer_edges – list of intralayer edges between the nodes. If intralayer_edges.shape[1] > 2 intralayer_edges[:,2] is assumed to represent the weights of the edges. Default weight is 1.
  • layer_vec – vector denoting layer membership for each edge. Size of network is taken to be len(layer_vec)
  • interlayer_edges – list of edges across layers. If interlayer_edges.shape[1] > 2 interlayer_edges[:,2] is assumed to represent the weights of the edges. Default weight is 1.
  • comm_vec – Underlying known communitiies of the network. Default is None
  • directed – Are intralayer and interlayer edges directed. #TODO: allow one or the other to be directed.
__weakref__

list of weak references to the object (if defined)

get_AMI_layer_avg_with_communities(labels)[source]

Calculate AMI of each layer with corresponding community in labels. Return average AMI weighted by number of nodes in each layer. :param labels: commmunity to assess agreement with. Len(labels) must equal self.N :return:

get_AMI_with_communities(labels)[source]

Calculate adjusted mutual information of labels with underlying community of network. :param labels: commmunity to assess agreement with. Len(labels) must equal self.N :return:

get_accuracy_with_communities(labels, permute=True)[source]

Calculate accuracy between supplied labels and the known communities of the networks.

Parameters:
  • labels – commmunity to assess agreement with. Len(labels) must equal self.N
  • permute – Should maximum accurracy across label permuations be identified?
Returns:

get_layer_edgecounts()[source]

m for each layer

plot_communities(comvec=None, layers=None, ax=None, cmap=None)[source]

Plot communities as an nlayers by nodes/layer heatmap. Note this only works for the multiplex case where the number of nodes is fixed throughout each layer.

Parameters:
  • comvec – community label for each nodes. If none, used stored ground truth for the network.
  • layers – Subset of the layers to plot. If None, plots all layers.
  • ax – matplotlib.Axes to draw on
  • cmap – color map to label communities with. Defaults to cube_helix.
Returns:

reorder_nodes()[source]

Resort all objects in the MultilayerGraph object by their community label :return:

to_scipy_csr()[source]

Create sparse matrix representations of the multilayer network.

Returns:(A_sparse,C_sparse) = interlayer adjacency , interlayer adjacency

Random Graph Classes

class modbp.MultilayerSBM(n, comm_prob_mat, layers=2, transition_prob=0.1, block_sizes0=None, use_gcc=False)[source]

Subclass of MultilayerGraph to create the dynamic stochastic block model from Ghasemian et al. 2016.

__init__(n, comm_prob_mat, layers=2, transition_prob=0.1, block_sizes0=None, use_gcc=False)[source]
Parameters:
  • n – number of nodes in each layer
  • comm_prob_mat – probability of block connections in SBM(this is fixed across all layers)
  • layers – number of layers
  • transition_prob – probability of each node changing communities from one layer to next. if transistion_prob=0 then community structure is constant across all layers.
  • block_sizes0 – Initial size of the blocks. Default is to use even block sizes starting out. block sizes at subsequent layers are determined by number of nodes that randomly transition between communities
  • use_gcc – use only giant connected component of starting SBM (option for single layer only)
get_all_layers_block()[source]

returns a single vector with block id for each node across all of the layers :return:

get_interlayer_adj()[source]

Singer interlayer adjencency matrix created by connecting each node to it’s equivalent node in the next layer. This is a temporal multiplex topology. :return: np.array of interlayer adjacency representation

get_interlayer_edgelist()[source]

Single list of edges giving the multilayer connections. For this model nodes are multiplex an connected to their neighboring slice identities.

Returns:np.array
get_intralayer_adj()[source]

Single adjacency matrix representing all layers. :return: np.array of intralayer adjacency representation

get_intralayer_edgelist()[source]

Single list of edges treating the group of single layer SBM’s as a surpra-adjacency format

Returns:np.array
get_node_layer_vec()[source]
Returns:np.array denoting which layer each node is in