# ModularityBP Object¶

We have created a single Python object, modbp.ModularityBP

## Storing Graphs on ModularityBP Object¶

A representation of a network must be supplied at the instantiation of the modbp.ModularityBP object. Each instance can only be associated with one network. A network can be supplied in several different formats:

• A igraph.Graph object is supplied. In this case network will be treated as single layer. This is pass in through the mlgraph parameter:

rand_g=igraph.Graph.ErdosRenyi(n=100,p=.05)
modbp_obj=modbp.ModularityBP(mlgraph=rand_g)

• A modbp.MultilayerGraph object can be supplied, also through the mlgraph parameter. See Multilayer Graph for more details.

• Finally, one can pass in an array for intralayer_edges, interlayer_edges, and layer_vec, from which modbp.ModularityBP will internally construct a modbp.MultilayerGraph:

intra_edges=np.array([[0,1],[0,2],[3,4]])
inter_edges=np.array([[2,3]])
layer_vec=[0,0,0,1,1]
modbp_obj=modbp.ModularityBP(intra_edges=intra_edges,
inter_edges=inter_edges,
layer_vec=layer_vec)


The graph is stored internally each modbp.ModularityBP as a modbp.MultilayerGraph and is accessible through modbp.ModularityBP.graph variable.

## Running Multilayer Modularity Belief Propagation¶

ModularityBP.run_modbp(beta, q, niter=100, resgamma=1.0, omega=1.0, reset=False)[source]
Parameters: beta – The inverse tempature parameter at which to run the modularity belief propagation algorithm. Must be specified each time BP is run. q – The number of mariginals used for the run of modbp. Note that if self.use_effective is true, The final number of reported communities could be lower. niter – Maximum number of iterations allowed. If self._align_communities_across_layers is true, the actual number of runs could be higher than this upper bound though at most 2*niter resgamma – The resolution parameter at which to run modbp. Default is resgamma=1.0 omega – The coupling strength used in running multimodbp. This represent how strongly the algorithm tries to assign nodes connected by an interlayer connection to the same community. reset – If true, the marginals will be rerandomized when this method is called. Otherwise the state will be maintained from previous runs if existing (assuming q hasn’t changed). None