leiden-rs 0.6.0

High-performance Leiden community detection algorithm for graphs in Rust
Documentation
//! # leiden-rs
//!
//! A Rust implementation of the [Leiden algorithm](https://doi.org/10.1038/s41598-019-41695-z)
//! for community detection in graphs, built on the [gryf](https://github.com/pnevyk/gryf) graph library.
//!
//! The Leiden algorithm guarantees well-connected communities through three phases:
//! local moving, refinement, and aggregation. It supports four quality functions:
//! **Modularity**, **CPM**, **RBConfiguration**, and **RBER**.
//!
//! # Quick Start
//!
//! ```
//! use gryf::{Graph, core::marker::Undirected};
//! use leiden_rs::{Leiden, LeidenConfig};
//!
//! let mut graph: Graph<i32, f64, Undirected> = Graph::new_undirected();
//! let a = graph.add_vertex(1);
//! let b = graph.add_vertex(2);
//! let c = graph.add_vertex(3);
//! graph.add_edge(&a, &b, 1.0);
//! graph.add_edge(&b, &c, 1.0);
//!
//! let leiden = Leiden::new(LeidenConfig::default());
//! let result = leiden.run(&graph).expect("leiden failed");
//! println!("Found {} communities (quality: {:.4})", result.partition.num_communities(), result.quality);
//! ```
//!
//! # Quality Functions
//!
//! - **Modularity**: `Q = Σ_c [e_c/m - γ*(Σ_c/(2m))²]` — the classic Newman-Girvan modularity
//! - **CPM**: `H = Σ_c [e_c - γ * n_c*(n_c-1)/2]` — avoids resolution limit, tunable via γ
//! - **RBConfiguration**: `Q = Σ_c [e_c - γ * K_c²/(4m)]` — Reichardt-Bornholdt with configuration null model
//! - **RBER**: `Q = Σ_c [e_c - γ * p * n_c*(n_c-1)/2]` — Reichardt-Bornholdt with Erdős-Rényi null model

#![warn(missing_docs)]

pub mod error;
pub mod hierarchy;
pub mod leiden;
pub mod lfr;
pub mod metrics;
pub mod multiplex;
pub mod partition;
pub mod quality;
pub mod resolution;

#[cfg(feature = "wasm")]
pub mod wasm;

pub use error::{LeidenError, Result as LeidenResult};
pub use hierarchy::{HierarchicalOutput, HierarchyLevel};
pub use leiden::{Leiden, LeidenConfig, LeidenConfigBuilder, LeidenOutput, QualityType};
pub use lfr::{generate_lfr_graph, LfrConfig, LfrGraph};
pub use metrics::{ari, conductance, coverage, internal_density, nmi};
pub use multiplex::{run_multiplex, MultiplexConfig, MultiplexOutput};
pub use partition::Partition;
pub use quality::{
    GraphData, Modularity, MoveComponents, QualityFunction, RBConfiguration, CPM, RBER,
};
pub use resolution::{resolution_profile, resolution_scan, ResolutionEntry};