| Title: | Optimal Graph Partition using the Persistence |
|---|---|
| Description: | Calculate the optimal vertex partition of a graph using the persistence as objective function. These subroutines have been used in Avellone et al. <doi:10.1007/s10288-023-00559-z>. |
| 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-06-03 09:27:29 UTC |
| Source: | https://github.com/cran/persistence |
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 = TRUE, seed = NULL, tol = NULL, max_level = 0L, ... ) ## S3 method for class 'igraph' cluster_milano( x, membership = NULL, H0 = TRUE, seed = NULL, tol = NULL, max_level = 0L, ... )cluster_milano(x, ...) ## Default S3 method: cluster_milano( x, edge_list, weights = NULL, membership = NULL, H0 = TRUE, seed = NULL, tol = NULL, max_level = 0L, ... ) ## S3 method for class 'igraph' cluster_milano( x, membership = NULL, H0 = TRUE, seed = NULL, tol = NULL, max_level = 0L, ... )
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 |
Logical value. Default is |
seed |
Non-negative integer seed for the random number generator.
If |
tol |
Optional numeric tolerance for the stopping criterion.
If |
max_level |
Optional integer representing the maximum number of aggregation levels.
If |
A list with three elements:
The optimal vertex partition.
The measure value of the optimal partition.
The seed used to generate random numbers.
library(persistence) # --- 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(persistence) # --- 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 |
Optional numeric value in |
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(persistence) # --- 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(persistence) # --- 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 |
Optional numeric value in |
Numeric scalar: the persistence probability when H0 = NULL,
the null-adjusted persistence when H0 = 0,
or the null-adjusted persistence density when H0 is in .
library(persistence) # --- 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(persistence) # --- 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) }