| Title: | Community Detection by Scaled Null-Adjusted Persistence |
|---|---|
| Description: | Finds the vertex partition of an undirected graph that maximises a persistence-based objective, using the Milano local-search algorithm. Three related quality measures are supported: the persistence probability of a community, its null-adjusted persistence (NAP), and the scaled null-adjusted persistence (Scaled-NAP), which interpolates between NAP and modularity. The methods are described in Avellone et al. (2023) <doi:10.1007/s10288-023-00559-z> and Avellone et al. (2025) <doi:10.1016/j.ins.2025.123032>. |
| Authors: | Alessandro Avellone [aut, cre], Paolo Bartesaghi [aut], Stefano Benati [aut], Rosanna Grassi [aut] |
| Maintainer: | Alessandro Avellone <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 1.0.0 |
| Built: | 2026-09-26 10:44:11 UTC |
| Source: | https://github.com/aavellone/scalednap-r |
Given a non-oriented graph, calculates the optimal vertex partition using persistence as the objective function.
See manual entries.
Maintainer: Alessandro Avellone [email protected]
Authors:
Alessandro Avellone [email protected]
Paolo Bartesaghi [email protected]
Stefano Benati [email protected]
Rosanna Grassi [email protected]
Calculates the vertex partition with maximum global null-adjusted persistence.
This function is polymorphic: it automatically detects the input type and accepts
either a vertex vector (accompanied by an edge list) or directly an igraph object.
cluster_milano(x, ...) ## Default S3 method: cluster_milano( x, edge_list, weights = NULL, membership = NULL, H0 = 0, seed = NULL, n_restarts = 1L, tol = NULL, max_level = 0L, num_threads = 1L, collect_stats = FALSE, ... ) ## S3 method for class 'igraph' cluster_milano( x, membership = NULL, H0 = 0, seed = NULL, n_restarts = 1L, tol = NULL, max_level = 0L, num_threads = 1L, collect_stats = FALSE, ... )cluster_milano(x, ...) ## Default S3 method: cluster_milano( x, edge_list, weights = NULL, membership = NULL, H0 = 0, seed = NULL, n_restarts = 1L, tol = NULL, max_level = 0L, num_threads = 1L, collect_stats = FALSE, ... ) ## S3 method for class 'igraph' cluster_milano( x, membership = NULL, H0 = 0, seed = NULL, n_restarts = 1L, tol = NULL, max_level = 0L, num_threads = 1L, collect_stats = FALSE, ... )
x |
An integer or character vector representing the graph vertices,
OR an object of class |
... |
Additional arguments passed to specific methods (e.g., |
edge_list |
Integer matrix with two columns representing the graph edge list. |
weights |
Numeric vector of positive edge weights. If |
membership |
Integer vector representing the starting partition: |
H0 |
Selects the quality measure. If |
seed |
Two forms are accepted. A single non-negative integer is
the master seed: if |
n_restarts |
Positive integer: number of independent restarts (default
|
tol |
Optional numeric tolerance for the stopping criterion.
If |
max_level |
Optional integer representing the maximum number of aggregation levels.
If |
num_threads |
Number of threads for the move-node phase. |
collect_stats |
Logical. If |
A list with five elements:
The optimal vertex partition.
The measure value of the optimal partition.
Numeric vector with the score of each cluster,
or NULL unless collect_stats = TRUE.
Integer vector: number of move-node sweeps performed at each coarsening level.
The master seed actually used (numeric). Re-running with
seed set to this value and the same n_restarts
reproduces the result exactly. NA when the run was launched
with an exact 64-bit seed string (no master exists in that case).
1-based index of the restart that produced the returned partition.
Character string: the exact 64-bit seed used by the
winning restart (returned as a string because R doubles are exact
only up to 2^53). Pass it back as seed to reproduce that
single winning run directly.
library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) cluster_milano(x = vertex, edge_list = edge_list) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) cluster_milano(g) }library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) cluster_milano(x = vertex, edge_list = edge_list) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) cluster_milano(g) }
Given a partition of the graph vertices, calculates the global persistence
as the sum of the local persistences of the individual clusters.
Persistence can be either null-adjusted or probability-based.
This function is polymorphic: it automatically detects the input type and accepts
either a vertex vector (accompanied by an edge list) or directly an igraph object.
global_persistence(x, ...) ## Default S3 method: global_persistence(x, edge_list, weights = NULL, membership, H0 = 0, ...) ## S3 method for class 'igraph' global_persistence(x, membership, H0 = 0, ...)global_persistence(x, ...) ## Default S3 method: global_persistence(x, edge_list, weights = NULL, membership, H0 = 0, ...) ## S3 method for class 'igraph' global_persistence(x, membership, H0 = 0, ...)
x |
An integer or character vector representing the graph vertices,
OR an object of class |
... |
Additional arguments passed to specific methods (e.g., |
edge_list |
Integer matrix with two columns representing the graph edge list. |
weights |
Numeric vector of edge weights. If |
membership |
Integer vector of vertex cluster assignments: |
H0 |
Selects the quality measure. If |
A list with two elements:
The global persistence of the partition.
The local persistence of each cluster. A value of NaN
indicates that cluster is empty in the input membership.
library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) mem <- c(1, 1, 1, 1, 2, 2, 2) global_persistence(x = vertex, edge_list = edge_list, membership = mem) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) mem <- c(rep(1, 5), rep(2, 5)) global_persistence(g, membership = mem) }library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) mem <- c(1, 1, 1, 1, 2, 2, 2) global_persistence(x = vertex, edge_list = edge_list, membership = mem) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) mem <- c(rep(1, 5), rep(2, 5)) global_persistence(g, membership = mem) }
Given the incidence vector of a vertex subset, calculates either the
persistence probability or the null-adjusted persistence of cluster C.
This function is polymorphic: it automatically detects the input type and accepts
either a vertex vector (accompanied by an edge list) or directly an igraph object.
local_persistence(x, ...) ## Default S3 method: local_persistence(x, edge_list, weights = NULL, cluster, H0 = 0, ...) ## S3 method for class 'igraph' local_persistence(x, cluster, H0 = 0, ...)local_persistence(x, ...) ## Default S3 method: local_persistence(x, edge_list, weights = NULL, cluster, H0 = 0, ...) ## S3 method for class 'igraph' local_persistence(x, cluster, H0 = 0, ...)
x |
An integer or character vector representing the graph vertices,
OR an object of class |
... |
Additional arguments passed to specific methods (e.g., |
edge_list |
Integer matrix with two columns representing the graph edge list. |
weights |
Numeric vector of edge weights. If |
cluster |
Binary incidence vector of the cluster: |
H0 |
Selects the quality measure. If |
Numeric scalar: the persistence probability when H0 = NULL,
the null-adjusted persistence (NAP) when H0 = 0,
or the scaled null-adjusted persistence (Scaled-NAP,
, with = H0) when H0
is in .
library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) cluster_bin <- c(1, 1, 1, 1, 0, 0, 0) local_persistence(x = vertex, edge_list = edge_list, cluster = cluster_bin) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) cluster_bin <- c(rep(1, 5), rep(0, 5)) local_persistence(g, cluster = cluster_bin) }library(scalednap) # --- EXAMPLE 1: Standard input (vectors and matrices) --- edg <- c(1, 2, 1, 3, 1, 4, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 7) edge_list <- matrix(edg, ncol = 2, byrow = TRUE) vertex <- c(1, 2, 3, 4, 5, 6, 7) cluster_bin <- c(1, 1, 1, 1, 0, 0, 0) local_persistence(x = vertex, edge_list = edge_list, cluster = cluster_bin) # --- EXAMPLE 2: igraph input --- if (requireNamespace("igraph", quietly = TRUE)) { g <- igraph::make_ring(10) cluster_bin <- c(rep(1, 5), rep(0, 5)) local_persistence(g, cluster = cluster_bin) }