PETLS
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
petls::Complex Class Reference

#include <Complex.hpp>

Inheritance diagram for petls::Complex:
petls::Alpha petls::Rips petls::dFlag

Public Member Functions

 Complex ()
 
 Complex (std::vector< Eigen::SparseMatrix< storage >> boundaries, std::vector< std::vector< filtration_type >> filtrations)
 
 ~Complex ()
 
void set_eigs_algorithm_func (std::function< spectra_vec(DenseMatrix_PL &)> _eigs_algorithm_func)
 
void set_eigs_algorithm_func (std::string name)
 
void set_up_algorithm_func (std::function< void(FilteredBoundaryMatrix< int > *, filtration_type, filtration_type, DenseMatrix_PL &)> _up_algorithm_func)
 
void set_up_algorithm_func (std::string name)
 
void set_boundaries_filtrations (std::vector< Eigen::SparseMatrix< storage >> boundaries, std::vector< std::vector< filtration_type >> filtrations)
 
void set_verbose (bool verbose)
 
void set_flipped (bool use_flipped)
 
void get_L (int dim, filtration_type a, filtration_type b, DenseMatrix_PL &L)
 
DenseMatrix_PL get_L (int dim, filtration_type a, filtration_type b)
 
void get_L_top_dim_flipped (filtration_type a, SparseMatrix_PL &L)
 
SparseMatrix_PL get_L_top_dim_flipped (filtration_type a)
 
void get_up (int dim, filtration_type a, filtration_type b, DenseMatrix_PL &L_up)
 
DenseMatrix_PL get_up (int dim, filtration_type a, filtration_type b)
 
void get_down (int dim, filtration_type a, Eigen::SparseMatrix< storage > &L_down)
 
DenseMatrix_PL get_down (int dim, filtration_type a)
 
std::vector< spectra_type > nonzero_spectra (int dim, filtration_type a, filtration_type b, SparseMatrix_PL PH_basis, bool use_dummy_harmonic_basis)
 
std::vector< spectra_type > spectra (int dim, filtration_type a, filtration_type b)
 
std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > spectra ()
 
std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > spectra (std::vector< std::tuple< int, filtration_type, filtration_type >> spectra_request_list)
 
std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > spectra_allpairs ()
 
std::pair< std::vector< spectra_type >, DenseMatrix_PL > eigenpairs (int dim, filtration_type a, filtration_type b)
 
std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >, DenseMatrix_PL > > eigenpairs ()
 
std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >, DenseMatrix_PL > > eigenpairs (std::vector< std::tuple< int, filtration_type, filtration_type >> spectra_request_list)
 
std::pair< int, spectra_type > eigenvalues_summarize (std::vector< spectra_type > eigenvalues)
 
void store_L (int dim, filtration_type a, filtration_type b, std::string filename)
 
void print_boundaries ()
 
void store_spectra (std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >>> spectra, std::string out_prefix)
 
void store_spectra_summary (std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >>> spectra, std::string out_prefix)
 
void time_to_csv (std::string filename)
 
std::vector< std::tuple< int, filtration_type, filtration_type > > filtration_list_to_spectra_request (std::vector< filtration_type > filtrations, std::vector< int > dims)
 
std::vector< std::tuple< int, filtration_type, filtration_type > > filtration_list_to_spectra_request_allpairs (std::vector< filtration_type > filtrations, std::vector< int > dims)
 
std::vector< filtration_type > get_all_filtrations ()
 

Public Attributes

int top_dim
 Top dimension of the complex. More...
 
std::vector< FilteredBoundaryMatrix< storage > > filtered_boundaries
 Boundary matrix assuming real (or integer) coefficients. More...
 
bool verbose
 Print progress if spectra() is called. More...
 
bool use_flipped
 Compute the top-dimensional Laplacian's eigenvalues in spectra function via the eigenvalues of the smaller of B_N B_N^T or B_N^T B_N and possible zero-padding. More...
 
Profile profile
 Profiler to track time usage of various steps. More...
 
std::function< spectra_vec(DenseMatrix_PL &)> eigs_algorithm_func
 
std::function< std::pair< spectra_vec, DenseMatrix_PL >DenseMatrix_PL &)> eigenpairs_algorithm_func
 
std::function< void(FilteredBoundaryMatrix< storage > *, filtration_type, filtration_type, DenseMatrix_PL &)> up_algorithm_func
 

Protected Member Functions

petls::FilteredBoundaryMatrix< storage > dummy_d0 ()
 

Detailed Description

Primary class for computing persistent Laplacians

Template Parameters
eigs_AlgorithmAlgorithm wrapper class to use for computing eigenvalues of the Laplacian in the spectra family of functions. Default is a wrapper for Eigen::SelfAdjointEigenSolver.
up_AlgorithmAlgorithm wrapper class to use for computing the up-Laplacian. Default is the Schur complement algorithm presented in Memoli, Wan, and Wang 2020. //TODO: \see up_algorithms and eigs_algorithms

Constructor & Destructor Documentation

◆ Complex() [1/2]

petls::Complex::Complex ( )

Default constructor with no boundary maps or simplices.

◆ Complex() [2/2]

petls::Complex::Complex ( std::vector< Eigen::SparseMatrix< storage >>  boundaries,
std::vector< std::vector< filtration_type >>  filtrations 
)
Parameters
boundariesa vector of Eigen::SparseMatrix of type int. Boundaries must be sorted in order of dimension.
filtrationsa vector of vector of filtrations. filtrations[dim] is a list of all filtrations of simplices in dimension dim. filtrations must be sorted in order of dimension, each filtrations[i] must be sorted in order of filtration

Primary constructor. Important Assumptions: 1) Boundary matrix has real coefficients stored as integers (but not mod 2!) 2) Boundary matrix dimensions agree with filtrations sizes 3) Length(filtrations) = Length(boundaries) + 1

◆ ~Complex()

petls::Complex::~Complex ( )
inline

Member Function Documentation

◆ dummy_d0()

petls::FilteredBoundaryMatrix< storage > petls::Complex::dummy_d0 ( )
protected

◆ eigenpairs() [1/3]

std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >, DenseMatrix_PL > > petls::Complex::eigenpairs ( )

Get all eigenvalues for all combinations of dimension and successive filtration values: a=filtrations[i] and b=filtrations[i+1]. Note: the caller does not know what spectra to expect from this.

Returns
vector of tuples (dim, a, b, eigenvalues, eigenvectors) where "eigenvalues" is a sorted vector of real, nonnegative eigenvalues and "eigenvectors" is an Eigen::MatrixXf where column i is the eigenvector for eigenvalue i

◆ eigenpairs() [2/3]

std::pair< std::vector< spectra_type >, DenseMatrix_PL > petls::Complex::eigenpairs ( int  dim,
filtration_type  a,
filtration_type  b 
)

Get the Persistent Laplacian's eigenvalues and eigenvectors at a given dimension and filtration.

Parameters
dimdimension
astart filtration level
bend filtration level
Returns
sorted pair of: vector of real, nonnegative eigenvalues and Eigen matrix where column i is the eigenvector for eigenvalue i

◆ eigenpairs() [3/3]

std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >, DenseMatrix_PL > > petls::Complex::eigenpairs ( std::vector< std::tuple< int, filtration_type, filtration_type >>  spectra_request_list)

This function essentially just calls eigenpairs(dim, a, b) in a loop.

Parameters
spectra_quest_listvector of tuples (dim, a, b) to compute the eigenvalues of L_{dim}^{a,b}.
Returns
vector of tuples (dim, a, b, eigenvalues, eigenvalues), where eigenvalues it istelf a vector of real, nonnegative eigenvalues and "eigenvectors" is an Eigen::MatrixXf where column i is the eigenvector for eigenvalue i.

◆ eigenvalues_summarize()

std::pair< int, spectra_type > petls::Complex::eigenvalues_summarize ( std::vector< spectra_type >  eigenvalues)

Utility function to get the Betti number and least nonzero eigenvalue form a vector of eigenvalues.

Parameters
eigenvalueseigenvalues
Returns
pair of (Betti number, least nonzero eigenvalue)

◆ filtration_list_to_spectra_request()

std::vector< std::tuple< int, filtration_type, filtration_type > > petls::Complex::filtration_list_to_spectra_request ( std::vector< filtration_type >  filtrations,
std::vector< int >  dims 
)

Get tuples (dim, a, b) for all combinations of dimension and successive filtration values: a=filtrations[i], b=filtrations[i+1].

Parameters
filtrationsvector of filtration values
dimsvector of dimensions
Returns
tuples (dim, a, b) for all combinations of dimension and successive filtration values: a=filtrations[i], b=filtrations[i+1].

◆ filtration_list_to_spectra_request_allpairs()

std::vector< std::tuple< int, filtration_type, filtration_type > > petls::Complex::filtration_list_to_spectra_request_allpairs ( std::vector< filtration_type >  filtrations,
std::vector< int >  dims 
)

Get tuples (dim, a, b) for all combinations of dimension and filtrations.

Parameters
filtrationsvector of filtration values
dimsvector of dimensions
Returns
tuples (dim, a, b) for all combinations of dimension and filtration values.

◆ get_all_filtrations()

std::vector< filtration_type > petls::Complex::get_all_filtrations ( )

Get all unique filtration values in the complex.

◆ get_down() [1/2]

DenseMatrix_PL petls::Complex::get_down ( int  dim,
filtration_type  a 
)

Get the down persistent Laplacian (by value).

Warning: this does a potentially expensive copy. The primary reason this function exists is to provide reasonable python binding access to the matrix itself. If you do not need this matrix directly in python (e.g. you want its eigenvalues) it will be more efficient to compute by reference via get_down(int dim, filtration_type a, Eigen::SparseMatrix<storage> &L_down).

Parameters
dimdimension
astart filtration value \return The matrix (by value) of the down presistent Laplacian

◆ get_down() [2/2]

void petls::Complex::get_down ( int  dim,
filtration_type  a,
Eigen::SparseMatrix< storage > &  L_down 
)

Get the down persistent Laplacian (by reference).

Parameters
dimdimension
astart filtration value
[out]L_downthe matrix (by reference) of the down presistent Laplacian

◆ get_L() [1/2]

DenseMatrix_PL petls::Complex::get_L ( int  dim,
filtration_type  a,
filtration_type  b 
)

Get the Persistent Laplacian Matrix (by value).

Warning: this does a potentially expensive copy. The primary reason this function exists is to provide reasonable python binding access to the matrix L itself. If you do not need the persistent Laplacian matrix directly in python (e.g. you want its eigenvalues) it will be more efficient to compute by reference via get_L(int dim, filtration_type a, filtration_type b, DenseMatrix_PL &L).

Parameters
dimdimension
astart filtration value
bend filtration value (must be >= a)
Returns
L the persistent Laplacian matrix.

◆ get_L() [2/2]

void petls::Complex::get_L ( int  dim,
filtration_type  a,
filtration_type  b,
DenseMatrix_PL &  L 
)

Get the Persistent Laplacian Matrix (by reference).

Parameters
dimdimension
astart filtration value
bend filtration value (must be >= a)
[out]Lthe matrix where the persistent Laplacian will be stored (by reference).

◆ get_L_top_dim_flipped() [1/2]

SparseMatrix_PL petls::Complex::get_L_top_dim_flipped ( filtration_type  a)

Get a matrix with the same nonzero eigenvalues as the top-dimensional Persistent Laplacian Matrix (by value).

Warning: this does a potentially expensive copy. The primary reason this function exists is to provide reasonable python binding access to the matrix itself. If you do not need this matrix directly in python (e.g. you want its eigenvalues) it will be more efficient to compute by reference via get_L_top_dim_flipped(filtration_type a, SparseMatrix_PL &L).

Parameters
astart filtration value
Returns
A matrix with the same nonzero eigenvalues as the top-dimensional persistent Laplacian (but not the persistent Laplacian itself).

◆ get_L_top_dim_flipped() [2/2]

void petls::Complex::get_L_top_dim_flipped ( filtration_type  a,
SparseMatrix_PL &  L 
)

Get a matrix with the same nonzero eigenvalues as the top-dimensional Persistent Laplacian Matrix (by reference).

Parameters
astart filtration value
[out]Lthe matrix (by reference) that has the same eigenvalues as the top-dimensional Persistent Laplacian

◆ get_up() [1/2]

DenseMatrix_PL petls::Complex::get_up ( int  dim,
filtration_type  a,
filtration_type  b 
)

Get the up persistent Laplacian (by value). The algorithm used is determined by the template parameter. See up_algorithms.hpp.

Parameters
dimdimension
astart filtration value
bend filtration value
Returns
up persistent Laplacian

◆ get_up() [2/2]

void petls::Complex::get_up ( int  dim,
filtration_type  a,
filtration_type  b,
DenseMatrix_PL &  L_up 
)

Get the up persistent Laplacian (by reference). The algorithm used is determined by the template parameter. See up_algorithms.hpp.

Parameters
dimdimension
astart filtration value
bend filtration value
[out]L_upup persistent Laplacian (by reference)

◆ nonzero_spectra()

std::vector< spectra_type > petls::Complex::nonzero_spectra ( int  dim,
filtration_type  a,
filtration_type  b,
SparseMatrix_PL  PH_basis,
bool  use_dummy_harmonic_basis 
)

Compute the nonzero eigenvalues of a persistent Laplacian using Schur restriction with the null space, either given by Persistent Homology representatives or by computing the null space.

Parameters
dimdimension
astart filtration level
bend filtration level
(optional)PH_basis Basis for the null space of the Laplacian, possibly obtained through persistent homology
use_dummy_harmonic_basisCompute the null space of the Laplacian here, then do the same projected as if we had been given the null space
Returns
sorted vector of real, positive eigenvalues

◆ print_boundaries()

void petls::Complex::print_boundaries ( )

Print all boundaries and corresponding filtrations.

◆ set_boundaries_filtrations()

void petls::Complex::set_boundaries_filtrations ( std::vector< Eigen::SparseMatrix< storage >>  boundaries,
std::vector< std::vector< filtration_type >>  filtrations 
)

Set the boundaries and filtrations of a complex, particularly if the default constructor was called.

Parameters
boundariesa vector of Eigen::SparseMatrix of type int. Boundaries must be sorted in order of dimension.
filtrationsa vector of vector of filtrations. filtrations[dim] is a list of all filtrations of simplices in dimension dim. filtrations must be sorted in order of dimension, each filtrations[i] must be sorted in order of filtration. Important Assumptions: 1) Boundary matrix has real coefficients stored as integers (but not mod 2!), 2) Boundary matrix dimensions agree with filtrations sizes, 3) Length(filtrations) = Length(boundaries) + 1.

◆ set_eigs_algorithm_func() [1/2]

void petls::Complex::set_eigs_algorithm_func ( std::function< spectra_vec(DenseMatrix_PL &)>  _eigs_algorithm_func)

◆ set_eigs_algorithm_func() [2/2]

void petls::Complex::set_eigs_algorithm_func ( std::string  name)

◆ set_flipped()

void petls::Complex::set_flipped ( bool  use_flipped)
inline

Set flipped

Parameters
use_flippedNew setting

◆ set_up_algorithm_func() [1/2]

void petls::Complex::set_up_algorithm_func ( std::function< void(FilteredBoundaryMatrix< int > *, filtration_type, filtration_type, DenseMatrix_PL &)>  _up_algorithm_func)

◆ set_up_algorithm_func() [2/2]

void petls::Complex::set_up_algorithm_func ( std::string  name)

◆ set_verbose()

void petls::Complex::set_verbose ( bool  verbose)
inline

Set verbose

Parameters
verboseNew setting.

◆ spectra() [1/3]

std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > petls::Complex::spectra ( )

Get all eigenvalues for all combinations of dimension and successive filtration values: a=filtrations[i] and b=filtrations[i+1]. Note: the caller does not know what spectra to expect from this.

Returns
vector of tuples (dim, a, b, eigenvalues) where "eigenvalues" is a sorted vector of real, nonnegative eigenvalues.

◆ spectra() [2/3]

std::vector< spectra_type > petls::Complex::spectra ( int  dim,
filtration_type  a,
filtration_type  b 
)

Get the Persistent Laplacian's eigenvalues at a given dimension and filtration.

Parameters
dimdimension
astart filtration level
bend filtration level
Returns
sorted vector of real, nonnegative eigenvalues

◆ spectra() [3/3]

std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > petls::Complex::spectra ( std::vector< std::tuple< int, filtration_type, filtration_type >>  spectra_request_list)

This function essentially just calls spectra(dim, a, b) in a loop.

Parameters
spectra_quest_listvector of tuples (dim, a, b) to compute the eigenvalues of L_{dim}^{a,b}.
Returns
vector of tuples (dim, a, b, eigenvalues), where eigenvalues it istelf a vector of real, nonnegative eigenvalues.

◆ spectra_allpairs()

std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type > > > petls::Complex::spectra_allpairs ( )

Get all eigenvalues for all combinations of dimension and filtration values. Note: the caller does not know what spectra to expect from this.

Returns
vector of tuples (dim, a, b, eigenvalues) where "eigenvalues" is a sorted vector of real, nonnegative eigenvalues.

◆ store_L()

void petls::Complex::store_L ( int  dim,
filtration_type  a,
filtration_type  b,
std::string  filename 
)

Compute and store a persistent Laplacian matrix in a file in matrix market format.

Parameters
dimdimension
astart filtration value
bend filtration value
filenamefile to store matrix (typically .mtx extension)

◆ store_spectra()

void petls::Complex::store_spectra ( std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >>>  spectra,
std::string  out_prefix 
)

Write spectra to files.

for each dimension dim of the complex, files write "{out_prefix}_spectra_{dim}.txt". Each line of the file is a space-separated list of eigenvalues. Lines may be empty. Note the filtration values are not reported.

Parameters
spectratuples (dim, a, b, eigenvalues)
out_prefixEigenvalues will be written to "{out_prefix}_spectra_{dim}.txt"

◆ store_spectra_summary()

void petls::Complex::store_spectra_summary ( std::vector< std::tuple< int, filtration_type, filtration_type, std::vector< spectra_type >>>  spectra,
std::string  out_prefix 
)

Write spectra summary to files "{out_prefix}_spectra_summary.txt"

Each line is a space-separated list of filtrations, bettti numbers, and least nonzero eigenvalues: (filtration a) (filtration b) (betti 0) ... (betti top_dim) (lambda 0) ... (lambda top_dim)

Parameters
spectratuples (dim, a, b, eigenvalues)
out_prefixEigenvalues will be written to "{out_prefix}_spectra_summary.txt"

◆ time_to_csv()

void petls::Complex::time_to_csv ( std::string  filename)
inline

Write the profile to a csv file. This is done automatically when spectra() is called, but it can also be done here.BDCSVDEigen

Parameters
filenamename of the file to write to

Member Data Documentation

◆ eigenpairs_algorithm_func

std::function<std::pair<spectra_vec,DenseMatrix_PL>DenseMatrix_PL&)> petls::Complex::eigenpairs_algorithm_func

◆ eigs_algorithm_func

std::function<spectra_vec(DenseMatrix_PL&)> petls::Complex::eigs_algorithm_func

◆ filtered_boundaries

std::vector<FilteredBoundaryMatrix<storage> > petls::Complex::filtered_boundaries

Boundary matrix assuming real (or integer) coefficients.

◆ profile

Profile petls::Complex::profile

Profiler to track time usage of various steps.

◆ top_dim

int petls::Complex::top_dim

Top dimension of the complex.

◆ up_algorithm_func

std::function<void(FilteredBoundaryMatrix<storage>*, filtration_type, filtration_type, DenseMatrix_PL&)> petls::Complex::up_algorithm_func

◆ use_flipped

bool petls::Complex::use_flipped

Compute the top-dimensional Laplacian's eigenvalues in spectra function via the eigenvalues of the smaller of B_N B_N^T or B_N^T B_N and possible zero-padding.

◆ verbose

bool petls::Complex::verbose

Print progress if spectra() is called.


The documentation for this class was generated from the following files: