pub struct Graph { /* private fields */ }Expand description
A weighted graph (directed or undirected).
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn from_correlation_matrix(matrix: &[Vec<f64>], threshold: f64) -> Self
pub fn from_correlation_matrix(matrix: &[Vec<f64>], threshold: f64) -> Self
Build an undirected graph from a correlation matrix with a threshold.
Adds an edge between nodes i and j if |correlation[i][j]| ≥ threshold. Edge weight is the absolute correlation.
Sourcepub fn from_sparse_matrix(matrix: &SparseMatrix) -> Self
pub fn from_sparse_matrix(matrix: &SparseMatrix) -> Self
Build an undirected graph from a sparse matrix.
For a symmetric matrix (e.g. adjacency/connectivity), each stored entry
(i, j, w) with i < j becomes an edge. Entries with i >= j are
skipped to avoid double-counting in undirected graphs.
Sourcepub fn louvain_with_resolution(&self, resolution: f64) -> Community
pub fn louvain_with_resolution(&self, resolution: f64) -> Community
Louvain community detection with a resolution parameter.
The resolution parameter γ controls community granularity:
- γ < 1.0 → fewer, larger communities
- γ = 1.0 → standard modularity
- γ > 1.0 → more, smaller communities
Implements both Phase 1 (local moves) and Phase 2 (hierarchical aggregation).
Sourcepub fn modularity_with_resolution(
&self,
assignments: &[usize],
resolution: f64,
) -> f64
pub fn modularity_with_resolution( &self, assignments: &[usize], resolution: f64, ) -> f64
Compute modularity Q with a resolution parameter.
Q = Σ_c [L_c / m - γ * (d_c / 2m)²]
Sourcepub fn degree_centrality(&self) -> Vec<f64>
pub fn degree_centrality(&self) -> Vec<f64>
Degree centrality: degree(v) / (n - 1).
Sourcepub fn betweenness_centrality(&self) -> Vec<f64>
pub fn betweenness_centrality(&self) -> Vec<f64>
Betweenness centrality using Brandes’ algorithm.
Sourcepub fn closeness_centrality(&self) -> Vec<f64>
pub fn closeness_centrality(&self) -> Vec<f64>
Closeness centrality: (n-1) / Σ d(v, u).
Sourcepub fn centrality(&self) -> CentralityScores
pub fn centrality(&self) -> CentralityScores
Compute all three centrality metrics.
Sourcepub fn louvain(&self) -> Community
pub fn louvain(&self) -> Community
Louvain community detection.
Iteratively moves nodes between communities to maximize modularity.
Sourcepub fn modularity(&self, assignments: &[usize]) -> f64
pub fn modularity(&self, assignments: &[usize]) -> f64
Compute modularity Q for a given community assignment.
Uses the community-level formula: Q = Σ_c [L_c / m - (d_c / 2m)²] where L_c = sum of edge weights within community c, m = total edge weight, and d_c = sum of node degrees in community c.