Basic Usage

To detect communities in a graph using the HpMocd algorithm from pymocd, follow the steps below.

First, prepare your graph:

  import networkx as nx       # You can use igraph too
from pymocd import HpMocd   # Our library

G = nx.karate_club_graph()
  

Then, instantiate and run the algorithm:

  alg = HpMocd(
    graph=G,
    debug_level=1,
    pop_size=100,
    num_gens=100,
    cross_rate=0.8,
    mut_rate=0.2
)

solution = alg.run()
print(solution)
  

Parameters

ParameterTypeDescription
graphnetworkx.GraphYour unweighted, undirected graph. Only NetworkX graphs are supported.
debug_levelu8Verbosity of internal logging (0 = no debug output; 1–3 = increasing detail).
pop_sizeusizePopulation size for the evolutionary algorithm.
num_gensusizeNumber of generations (iterations) to run.
cross_ratef64Crossover rate, a floating-point value in [0.0, 1.0].
mut_ratef64Mutation rate, a floating-point value in [0.0, 1.0].

Further reading

Rust Parameter Types

  • usize: An unsigned integer whose size matches the platform’s pointer width (e.g. 64 bits on a 64-bit system).

  • u8: An 8-bit unsigned integer (values 0 to 255).s.

  • f64: A 64-bit (double-precision) floating-point number. Provides high precision for real-valued parameters.

Last updated 03 Jun 2025, 13:25 -0300 . history