pub struct SimplicialComplex { /* private fields */ }Expand description
A finite simplicial complex represented by its simplices, grouped by dimension.
All simplices are stored as sorted vectors of vertex indices. Adding a simplex automatically adds all its faces (closure property).
§Example
use scirs2_graph::hypergraph::SimplicialComplex;
let mut sc = SimplicialComplex::new();
sc.add_simplex(vec![0, 1, 2]); // adds triangle + all edges + all vertices
let betti = sc.betti_numbers();
assert_eq!(betti[0], 1); // one connected component
assert_eq!(betti[1], 0); // boundary is filled inImplementations§
Source§impl SimplicialComplex
impl SimplicialComplex
Sourcepub fn add_simplex(&mut self, simplex: Vec<usize>)
pub fn add_simplex(&mut self, simplex: Vec<usize>)
Add a simplex and all its faces (the closure).
The simplex [v_0, v_1, …, v_k] is stored as a sorted, deduplicated
vertex list. All (k-1)-dimensional faces are recursively added.
Sourcepub fn max_dim(&self) -> Option<usize>
pub fn max_dim(&self) -> Option<usize>
Return the maximum dimension of the complex, or None if empty.
Sourcepub fn simplices_of_dim(&self, dim: usize) -> Vec<Vec<usize>>
pub fn simplices_of_dim(&self, dim: usize) -> Vec<Vec<usize>>
Return a slice of all simplices at dimension dim.
Sourcepub fn total_simplices(&self) -> usize
pub fn total_simplices(&self) -> usize
Total number of simplices across all dimensions.
Sourcepub fn num_simplices(&self, dim: usize) -> usize
pub fn num_simplices(&self, dim: usize) -> usize
Number of simplices at dimension dim.
Sourcepub fn boundary_matrix(&self, dim: usize) -> Array2<i8>
pub fn boundary_matrix(&self, dim: usize) -> Array2<i8>
Compute the boundary matrix ∂dim : C_dim → C{dim-1}.
Rows are indexed by (dim-1)-simplices; columns by dim-simplices.
Entry [i, j] is (-1)^k where k is the position of the omitted
vertex in simplex j that gives face i, else 0.
Returns an all-zero (1 × 1) matrix if there are no dim-simplices or no (dim-1)-simplices.
Sourcepub fn betti_numbers(&self) -> Vec<usize>
pub fn betti_numbers(&self) -> Vec<usize>
Compute the Betti numbers β_0, β_1, …, β_{max_dim}.
β_k = dim ker(∂k) − dim im(∂{k+1}) = (n_k − rank(∂k)) − rank(∂{k+1})
where n_k is the number of k-simplices.
Rank is computed by Gaussian elimination over ℤ (integer arithmetic, checking for divisibility). Because our coefficient field is effectively ℚ (we use rational row operations), this gives exact Betti numbers over ℤ/2ℤ which coincides with ℤ Betti numbers for these complexes.
Sourcepub fn euler_characteristic(&self) -> i64
pub fn euler_characteristic(&self) -> i64
Compute the Euler characteristic: χ = Σ_k (-1)^k |C_k|.
Sourcepub fn vietoris_rips(points: &Array2<f64>, epsilon: f64) -> Self
pub fn vietoris_rips(points: &Array2<f64>, epsilon: f64) -> Self
Build the Vietoris-Rips complex from a point cloud.
Inserts a simplex on every subset of points whose pairwise Euclidean
distances are all ≤ epsilon.
§Arguments
points– shape(n_points, n_dims)epsilon– edge threshold
§Complexity
This is O(2^n) in the worst case; use only on small point sets (< 20).
Sourcepub fn cech_complex(points: &Array2<f64>, radius: f64) -> Self
pub fn cech_complex(points: &Array2<f64>, radius: f64) -> Self
Build the Čech complex from a point cloud.
A simplex σ is included iff the miniball (smallest enclosing ball)
of the points in σ has radius ≤ radius.
§Arguments
points– shape(n_points, n_dims)radius– ball radius threshold
Sourcepub fn nerve_complex(cover: &[Vec<usize>]) -> Self
pub fn nerve_complex(cover: &[Vec<usize>]) -> Self
Build the nerve complex from a cover.
Given a cover cover = [U_0, U_1, …, U_{k-1}] where each U_i is a
list of point indices, the nerve has:
- A vertex for each
U_i. - A simplex
{i_0, …, i_r}wheneverU_{i_0} ∩ … ∩ U_{i_r} ≠ ∅.
§Arguments
cover– a slice of cover sets, each set being a sorted list of indices
Trait Implementations§
Source§impl Clone for SimplicialComplex
impl Clone for SimplicialComplex
Source§fn clone(&self) -> SimplicialComplex
fn clone(&self) -> SimplicialComplex
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SimplicialComplex
impl Debug for SimplicialComplex
Auto Trait Implementations§
impl Freeze for SimplicialComplex
impl RefUnwindSafe for SimplicialComplex
impl Send for SimplicialComplex
impl Sync for SimplicialComplex
impl Unpin for SimplicialComplex
impl UnsafeUnpin for SimplicialComplex
impl UnwindSafe for SimplicialComplex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more