Skip to main content

SimplicialComplex

Struct SimplicialComplex 

Source
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 in

Implementations§

Source§

impl SimplicialComplex

Source

pub fn new() -> Self

Create an empty simplicial complex.

Source

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.

Source

pub fn max_dim(&self) -> Option<usize>

Return the maximum dimension of the complex, or None if empty.

Source

pub fn simplices_of_dim(&self, dim: usize) -> Vec<Vec<usize>>

Return a slice of all simplices at dimension dim.

Source

pub fn total_simplices(&self) -> usize

Total number of simplices across all dimensions.

Source

pub fn num_simplices(&self, dim: usize) -> usize

Number of simplices at dimension dim.

Source

pub fn boundary_matrix(&self, dim: usize) -> Array2<i8>

Compute the boundary matrixdim : 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.

Source

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.

Source

pub fn euler_characteristic(&self) -> i64

Compute the Euler characteristic: χ = Σ_k (-1)^k |C_k|.

Source

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).

Source

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
Source

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} whenever U_{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

Source§

fn clone(&self) -> SimplicialComplex

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SimplicialComplex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimplicialComplex

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V