Matrix structure storing a compatible base of a filtered chain complex. See [41]. The base is constructed from the boundaries of the cells in the complex. Allows the persistent homology to be computed, as well as representative cycles. Supports vineyards (see [21]) and the removal of maximal cells while maintaining a valid barcode. Provides an access to its columns and rows. More...
#include <gudhi/Persistence_matrix/Chain_matrix.h>
Public Types | |
using | Field_operators = typename Master_matrix::Field_operators |
Field operators class. Necessary only if PersistenceMatrixOptions::is_z2 is false. | |
using | Field_element = typename Master_matrix::Element |
using | Column = typename Master_matrix::Column |
using | Row = typename Master_matrix::Row |
using | Entry = typename Master_matrix::Matrix_entry |
using | Entry_constructor = typename Master_matrix::Entry_constructor |
using | Column_settings = typename Master_matrix::Column_settings |
using | Boundary = typename Master_matrix::Boundary |
using | Entry_representative = typename Master_matrix::Entry_representative |
using | Index = typename Master_matrix::Index |
using | ID_index = typename Master_matrix::ID_index |
using | Pos_index = typename Master_matrix::Pos_index |
using | Dimension = typename Master_matrix::Dimension |
Public Member Functions | |
Chain_matrix (Column_settings *colSettings) | |
Constructs an empty matrix. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided. More... | |
template<class Boundary_range = Boundary> | |
Chain_matrix (const std::vector< Boundary_range > &orderedBoundaries, Column_settings *colSettings) | |
Constructs a new matrix from the given ranges of Matrix::Entry_representative. Each range corresponds to a column (the order of the ranges are preserved). The content of the ranges is assumed to be sorted by increasing IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided. More... | |
Chain_matrix (unsigned int numberOfColumns, Column_settings *colSettings) | |
Constructs a new empty matrix and reserves space for the given number of columns. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided. More... | |
template<typename BirthComparatorFunction , typename DeathComparatorFunction > | |
Chain_matrix (Column_settings *colSettings, const BirthComparatorFunction &birthComparator, const DeathComparatorFunction &deathComparator) | |
Constructs an empty matrix and stores the given comparators. More... | |
template<typename BirthComparatorFunction , typename DeathComparatorFunction , class Boundary_range = Boundary> | |
Chain_matrix (const std::vector< Boundary_range > &orderedBoundaries, Column_settings *colSettings, const BirthComparatorFunction &birthComparator, const DeathComparatorFunction &deathComparator) | |
Constructs a new matrix from the given ranges of Matrix::Entry_representative. Each range corresponds to a column (the order of the ranges are preserved). The content of the ranges is assumed to be sorted by increasing IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. More... | |
template<typename BirthComparatorFunction , typename DeathComparatorFunction > | |
Chain_matrix (unsigned int numberOfColumns, Column_settings *colSettings, const BirthComparatorFunction &birthComparator, const DeathComparatorFunction &deathComparator) | |
Constructs a new empty matrix and reserves space for the given number of columns. More... | |
Chain_matrix (const Chain_matrix &matrixToCopy, Column_settings *colSettings=nullptr) | |
Copy constructor. If colSettings is not a null pointer, its value is kept instead of the one in the copied matrix. More... | |
Chain_matrix (Chain_matrix &&other) noexcept | |
Move constructor. More... | |
template<class Boundary_range = Boundary> | |
std::vector< Entry_representative > | insert_boundary (const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >()) |
Inserts at the end of the matrix a new ordered column corresponding to the given boundary. This means that it is assumed that this method is called on boundaries in the order of the filtration. It also assumes that the cells in the given boundary are identified by their relative position in the filtration, starting at 0. If it is not the case, use the other insert_boundary instead by indicating the cell ID used in the boundaries when the cell is inserted. More... | |
template<class Boundary_range = Boundary> | |
std::vector< Entry_representative > | insert_boundary (ID_index cellID, const Boundary_range &boundary, Dimension dim=Master_matrix::template get_null_value< Dimension >()) |
It does the same as the other version, but allows the boundary cells to be identified without restrictions except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then to use the other insertion method to avoid overwriting IDs. More... | |
Column & | get_column (Index columnIndex) |
Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type. More... | |
const Column & | get_column (Index columnIndex) const |
Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type. More... | |
void | remove_maximal_cell (ID_index cellID) |
Only available if PersistenceMatrixOptions::has_removable_columns and PersistenceMatrixOptions::has_vine_update are true, as well as, PersistenceMatrixOptions::has_map_column_container and PersistenceMatrixOptions::has_column_pairings. Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent (i.e., the matrix is still a compatible bases of the chain complex in the sense of [41]). The maximality of the cell is not verified. Also updates the barcode if it is stored. More... | |
void | remove_maximal_cell (ID_index cellID, const std::vector< ID_index > &columnsToSwap) |
Only available if PersistenceMatrixOptions::has_removable_columns, PersistenceMatrixOptions::has_vine_update and PersistenceMatrixOptions::has_map_column_container are true. Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent (i.e., it is still a compatible bases of the chain complex in the sense of [41]). The maximality of the cell is not verified. Also updates the barcode if it is stored. More... | |
void | remove_last () |
Only available if PersistenceMatrixOptions::has_removable_columns is true and, if PersistenceMatrixOptions::has_map_column_container is true or PersistenceMatrixOptions::has_vine_update is false. Removes the last cell in the filtration from the matrix and updates the barcode if it is stored. More... | |
Index | get_number_of_columns () const |
Returns the current number of columns in the matrix. More... | |
Dimension | get_column_dimension (Index columnIndex) const |
Returns the dimension of the given column. More... | |
void | add_to (Index sourceColumnIndex, Index targetColumnIndex) |
Adds column at sourceColumnIndex onto the column at targetColumnIndex in the matrix. More... | |
void | multiply_target_and_add_to (Index sourceColumnIndex, const Field_element &coefficient, Index targetColumnIndex) |
Multiplies the target column with the coefficient and then adds the source column to it. That is: targetColumn = (targetColumn * coefficient) + sourceColumn . More... | |
void | multiply_source_and_add_to (const Field_element &coefficient, Index sourceColumnIndex, Index targetColumnIndex) |
Multiplies the source column with the coefficient before adding it to the target column. That is: targetColumn += (coefficient * sourceColumn) . The source column will not be modified. More... | |
bool | is_zero_entry (Index columnIndex, ID_index rowIndex) const |
Indicates if the entry at given coordinates has value zero. More... | |
bool | is_zero_column (Index columnIndex) |
Indicates if the column at given index has value zero. Note that if the matrix is valid, this method should always return false. More... | |
Index | get_column_with_pivot (ID_index cellID) const |
Returns the column with given row index as pivot. Assumes that the pivot exists. More... | |
ID_index | get_pivot (Index columnIndex) |
Returns the row index of the pivot of the given column. More... | |
void | reset (Column_settings *colSettings) |
Resets the matrix to an empty matrix. More... | |
Chain_matrix & | operator= (const Chain_matrix &other) |
Assign operator. | |
Friends | |
void | swap (Chain_matrix &matrix1, Chain_matrix &matrix2) |
Swap operator. | |
Matrix structure storing a compatible base of a filtered chain complex. See [41]. The base is constructed from the boundaries of the cells in the complex. Allows the persistent homology to be computed, as well as representative cycles. Supports vineyards (see [21]) and the removal of maximal cells while maintaining a valid barcode. Provides an access to its columns and rows.
Master_matrix | An instantiation of Matrix from which all types and options are deduced. |
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Boundary = typename Master_matrix::Boundary |
Type of an input column.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Column = typename Master_matrix::Column |
Column type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Column_settings = typename Master_matrix::Column_settings |
Structure giving access to the columns to necessary external classes.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Dimension = typename Master_matrix::Dimension |
Dimension value type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Entry = typename Master_matrix::Matrix_entry |
Matrix entry type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Entry_constructor = typename Master_matrix::Entry_constructor |
Factory of Entry classes.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Entry_representative = typename Master_matrix::Entry_representative |
Entry content representative.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Field_element = typename Master_matrix::Element |
Type of an field element.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::ID_index = typename Master_matrix::ID_index |
IDIdx index type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Index = typename Master_matrix::Index |
MatIdx index type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Pos_index = typename Master_matrix::Pos_index |
PosIdx index type.
using Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::Row = typename Master_matrix::Row |
Row type, only necessary with row access option.
|
inline |
Constructs an empty matrix. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided.
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
|
inline |
Constructs a new matrix from the given ranges of Matrix::Entry_representative. Each range corresponds to a column (the order of the ranges are preserved). The content of the ranges is assumed to be sorted by increasing IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided.
Boundary_range | Range type for Matrix::Entry_representative ranges. Assumed to have a begin(), end() and size() method. |
orderedBoundaries | Range of boundaries: orderedBoundaries is interpreted as a boundary matrix of a filtered simplicial complex, whose boundaries are ordered by filtration order. Therefore, orderedBoundaries[i] should store the boundary of the |
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
|
inline |
Constructs a new empty matrix and reserves space for the given number of columns. Only available if PersistenceMatrixOptions::has_column_pairings is true or PersistenceMatrixOptions::has_vine_update is false. Otherwise, birth and death comparators have to be provided.
numberOfColumns | Number of columns to reserve space for. |
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
|
inline |
Constructs an empty matrix and stores the given comparators.
BirthComparatorFunction | Type of the birth comparator: (Pos_index, Pos_index) -> bool |
DeathComparatorFunction | Type of the death comparator: (Pos_index, Pos_index) -> bool |
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
birthComparator | Method taking two PosIdx indices as input and returning true if and only if the birth associated to the first position is strictly less than birth associated to the second one with respect to some self defined order. It is used while swapping two unpaired or two negative columns. |
deathComparator | Method taking two PosIdx indices as input and returning true if and only if the death associated to the first position is strictly less than death associated to the second one with respect to some self defined order. It is used while swapping two positive but paired columns. |
|
inline |
Constructs a new matrix from the given ranges of Matrix::Entry_representative. Each range corresponds to a column (the order of the ranges are preserved). The content of the ranges is assumed to be sorted by increasing IDs. The IDs of the simplices are also assumed to be consecutive, ordered by filtration value, starting with 0.
BirthComparatorFunction | Type of the birth comparator: (Pos_index, Pos_index) -> bool |
DeathComparatorFunction | Type of the death comparator: (Pos_index, Pos_index) -> bool |
Boundary_range | Range type for Matrix::Entry_representative ranges. Assumed to have a begin(), end() and size() method. |
orderedBoundaries | Range of boundaries: orderedBoundaries is interpreted as a boundary matrix of a filtered simplicial complex, whose boundaries are ordered by filtration order. Therefore, orderedBoundaries[i] should store the boundary of the |
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
birthComparator | Method taking two PosIdx indices as input and returning true if and only if the birth associated to the first position is strictly less than birth associated to the second one with respect to some self defined order. It is used while swapping two unpaired or two negative columns. |
deathComparator | Method taking two PosIdx indices as input and returning true if and only if the death associated to the first position is strictly less than death associated to the second one with respect to some self defined order. It is used while swapping two positive but paired columns. |
|
inline |
Constructs a new empty matrix and reserves space for the given number of columns.
BirthComparatorFunction | Type of the birth comparator: (Pos_index, Pos_index) -> bool |
DeathComparatorFunction | Type of the death comparator: (Pos_index, Pos_index) -> bool |
numberOfColumns | Number of columns to reserve space for. |
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |
birthComparator | Method taking two PosIdx indices as input and returning true if and only if the birth associated to the first position is strictly less than birth associated to the second one with respect to some self defined order. It is used while swapping two unpaired or two negative columns. |
deathComparator | Method taking two PosIdx indices as input and returning true if and only if the death associated to the first position is strictly less than death associated to the second one with respect to some self defined order. It is used while swapping two positive but paired columns. |
|
inline |
Copy constructor. If colSettings
is not a null pointer, its value is kept instead of the one in the copied matrix.
matrixToCopy | Matrix to copy. |
colSettings | Either a pointer to an existing setting structure for the columns or a null pointer. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. If null pointer, the pointer stored in matrixToCopy is used instead. |
|
inlinenoexcept |
Move constructor.
other | Matrix to move. |
|
inline |
Adds column at sourceColumnIndex
onto the column at targetColumnIndex
in the matrix.
|
inline |
Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type.
columnIndex | MatIdx index of the column to return. |
|
inline |
Returns the column at the given MatIdx index. The type of the column depends on the chosen options, see PersistenceMatrixOptions::column_type.
columnIndex | MatIdx index of the column to return. |
|
inline |
Returns the dimension of the given column.
columnIndex | MatIdx index of the column representing the cell. |
|
inline |
|
inline |
Returns the current number of columns in the matrix.
|
inline |
std::vector< Entry_representative > Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::insert_boundary | ( | const Boundary_range & | boundary, |
Dimension | dim = Master_matrix::template get_null_value< Dimension >() |
||
) |
Inserts at the end of the matrix a new ordered column corresponding to the given boundary. This means that it is assumed that this method is called on boundaries in the order of the filtration. It also assumes that the cells in the given boundary are identified by their relative position in the filtration, starting at 0. If it is not the case, use the other insert_boundary instead by indicating the cell ID used in the boundaries when the cell is inserted.
Different to the constructor, the boundaries do not have to come from a simplicial complex, but also from a more general entry complex. This includes cubical complexes or Morse complexes for example.
When inserted, the given boundary is reduced and from the reduction process, the column is deduced in the form of: IDIdx + linear combination of older column IDIdxs
. If the barcode is stored, it will be updated.
Boundary_range | Range of Matrix::Entry_representative. Assumed to have a begin(), end() and size() method. |
boundary | Boundary generating the new column. The content should be ordered by ID. |
dim | Dimension of the cell whose boundary is given. If the complex is simplicial, this parameter can be omitted as it can be deduced from the size of the boundary. |
std::vector< Entry_representative > Gudhi::persistence_matrix::Chain_matrix< Master_matrix >::insert_boundary | ( | ID_index | cellID, |
const Boundary_range & | boundary, | ||
Dimension | dim = Master_matrix::template get_null_value< Dimension >() |
||
) |
It does the same as the other version, but allows the boundary cells to be identified without restrictions except that all IDs have to be strictly increasing in the order of filtration. Note that you should avoid then to use the other insertion method to avoid overwriting IDs.
As a cell has to be inserted before one of its cofaces in a valid filtration (recall that it is assumed that the cells are inserted by order of filtration), it is sufficient to indicate the ID of the cell being inserted.
Boundary_range | Range of Matrix::Entry_representative. Assumed to have a begin(), end() and size() method. |
cellID | IDIdx index to use to identify the new cell. |
boundary | Boundary generating the new column. The indices of the boundary have to correspond to the cellID values of precedent calls of the method for the corresponding cells and should be ordered in increasing order. |
dim | Dimension of the cell whose boundary is given. If the complex is simplicial, this parameter can be omitted as it can be deduced from the size of the boundary. |
|
inline |
Indicates if the column at given index has value zero. Note that if the matrix is valid, this method should always return false.
columnIndex | MatIdx index of the column. |
|
inline |
|
inline |
Multiplies the source column with the coefficient before adding it to the target column. That is: targetColumn += (coefficient * sourceColumn)
. The source column will not be modified.
|
inline |
Multiplies the target column with the coefficient and then adds the source column to it. That is: targetColumn = (targetColumn * coefficient) + sourceColumn
.
|
inline |
Only available if PersistenceMatrixOptions::has_removable_columns is true and, if PersistenceMatrixOptions::has_map_column_container is true or PersistenceMatrixOptions::has_vine_update is false. Removes the last cell in the filtration from the matrix and updates the barcode if it is stored.
See also remove_maximal_cell.
|
inline |
Only available if PersistenceMatrixOptions::has_removable_columns and PersistenceMatrixOptions::has_vine_update are true, as well as, PersistenceMatrixOptions::has_map_column_container and PersistenceMatrixOptions::has_column_pairings. Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent (i.e., the matrix is still a compatible bases of the chain complex in the sense of [41]). The maximality of the cell is not verified. Also updates the barcode if it is stored.
Note that using the other version of the method could perform better depending on how the data is maintained on the side of the user, that is, if providing the second parameter is easy.
See also remove_last.
cellID | IDIdx index of the cell to remove |
|
inline |
Only available if PersistenceMatrixOptions::has_removable_columns, PersistenceMatrixOptions::has_vine_update and PersistenceMatrixOptions::has_map_column_container are true. Assumes that the cell is maximal in the current complex and removes it such that the matrix remains consistent (i.e., it is still a compatible bases of the chain complex in the sense of [41]). The maximality of the cell is not verified. Also updates the barcode if it is stored.
To maintain the compatibility, vine swaps are done to move the cell up to the end of the filtration. Once at the end, the removal is trivial. But for chain matrices, swaps do not actually swap the position of the column every time, so the cells appearing after cellID
in the filtration have to be searched first within the matrix. If the user has an easy access to the IDIdx of the cells in the order of filtration, passing them by argument with columnsToSwap
allows to skip a linear search process. Typically, if the user knows that the cell he wants to remove is already the last cell of the filtration, calling remove_maximal_cell(cellID, {}) will be faster than remove_last().
See also remove_last.
|
inline |
Resets the matrix to an empty matrix.
colSettings | Pointer to an existing setting structure for the columns. The structure should contain all the necessary external classes specifically necessary for the chosen column type, such as custom allocators. |