homology module

class homology.HbdscanRips(max_dimensions=2, max_radius=inf, k_core=5)

Bases: object

A simple wrapper function that applies HBDSCAN over a distance matrix before passing it through the rips() function.

Parameters
  • max_dimensions – Optional, default 2 - The upper bound of dimensions for simplexes created.

  • max_radius – Optional, default np.inf (infinity) - The maximum

  • k_core – The neighbourhood size (K) to be used to calculate the core distances.

fit(distance_matrix)

Fit the class to the distance matrix.

Parameters

distance_matrix – A distance matrix of a set of points.

Returns

This class instance.

transform(distance_matrix)

Applies the Rips algorithm over the core distances of a given distance matrix to produce a filtered simplicial complex. This algorithm terminates either when all simplexes are found, or when the maximum radius is reached.

Parameters

distance_matrix – A distance matrix of a set of points

Returns

A filtered complex matrix, and a list with the corresponding birth radii.

class homology.PersistenceImage(resolution, kernel_spread=2)

Bases: object

A class to produce Persistence Images from a filtered complex matrix.

Parameters
  • resolution – The size of the resulting matrix (Integer); result will be matrix of shape (resolution, resolution).

  • kernel_spread – Optional, default 2 - Defines the kernel-spread used to calculate density.

fit(filtered_complexes, labels, x_min=None, x_max=None, y_min=None, y_max=None)

Fits the PersistenceImage to the filtered simplicial complex. Pre-processes the filtered complex matrix and labels so a persistence image can be generated.

Parameters
  • filtered_complexes – A filtered complex matrix.

  • labels – The birth-labels corresponding to the filtered complex matrix.

  • x_min – Optional, default None - Lower bound for the x-axis, if not defined: 0.

  • x_max – Optional, default None - Upper bound for the x-axis, if not defined: Maximum x value + 0.5.

  • y_min – Optional, default None - Lower bound for the y-axis, if not defined: 0.

  • y_max – Optional, default None - Upper bound for the y-axis, if not defined: Maximum y value + 0.5.

Returns

This class instance.

gaussian_prob(point, kernel_spread, x, y)

Calculates the Gaussian probability at a given (x,y) coordinate from a kernel at a given point.

Parameters
  • point – The center of the kernel.

  • kernel_spread – Defines the kernel-spread used to calculate density.

  • x – X coordinate.

  • y – Y coordinate.

Returns

The gaussian probability at the given coordinate.

transform(filtered_complexes, labels)

Generates a persistence image with a given resolution for the dataset.

Returns

A matrix of shape (resolution, resolution) with describing the density at each pixel.

class homology.PersistenceLandscape(steps)

Bases: object

A class to produce Persistence Images from a filtered complex matrix.

Parameters

steps – The amount of steps in the discretization step.

fit(filtered_complexes, labels, x_min=None, x_max=None)

Fits the PersistenceLandscape class. Pre-processes the filtered complex matrix and labels so a persistence landscape can be generated.

Parameters
  • filtered_complexes – A filtered complex matrix.

  • labels – The birth-labels corresponding to the filtered complex matrix.

  • x_min – Optional, default None - The lower bound of the x-axis, if not specified the lowest x of the dataset is used.

  • x_max – Optional, default None - The upper bound of the x-axis, if not specified the highest x of the dataset is used.

Returns

This class instance.

transform(filtered_complexes, labels)

Generate a persistence landscape at a given resolution for the dataset.

Parameters
  • filtered_complexes – A filtered complex matrix.

  • labels – The birth-labels corresponding to the filtered complex matrix.

Returns

A 2 dimensional numpy array with the persistence landscape functions.

class homology.Rips(dimensions=2, max_radius=inf)

Bases: object

A class to apply the rips algorithm to a distance matrix.

Parameters
  • dimensions – Optional, default 2 - The upper bound of dimensions for simplexes created.

  • max_radius – Optional, default np.inf (infinity) - The maximum radius of spheres in the Rips algorithm.

fit(distance_matrix)

Fit the Rips class to the distance matrix.

Parameters

distance_matrix – A distance matrix of a set of points.

Returns

This class instance.

transform(distance_matrix)

Applies the Rips algorithm over a given distance matrix to produce a filtered simplicial complex. This algorithm terminates either when all simplexes are found, or when the maximum radius is reached.

Parameters

distance_matrix – A distance matrix of a set of points

Returns

A filtered complex matrix, and a list with the corresponding birth radii.

homology.add_complex(new_complex, filtered_simplexes)

Adds a simplex to the filtered simplex matrix, and expands the matrix to fit the new number of simplexes

Parameters
  • new_complex – A list of indices of simplexes that created this simplex.

  • filtered_simplexes – The filtered simplex matrix.

Returns

An expanded filtered simplex matrix, with the new simplex added to it.

homology.all_simplexes_found(zero_simplex_count, filtered_simplexes, max_dimensions)

Checks whether all simplexes are fount in a filtered simplex matrix, given an upper bound on dimensionality of simplexes.

Parameters
  • zero_simplex_count – The amount of 0-simplexes.

  • filtered_simplexes – The filtered simplex matrix.

  • max_dimensions – The upper bound on dimensionality for simplexes.

Returns

True the amount of possible simplexes equals the length of the filtered simplex matrix, False otherwise.

homology.filtered_complexes_to_tuples(filtered_complexes, labels)

Generate a list of [birth,death] tuples from a filtered complex matrix, and it’s corresponding birth-labels.

Parameters
  • filtered_complexes – A filtered complex matrix.

  • labels – The birth-labels corresponding to the filtered complex matrix.

Returns

A list of [birth, death] tuples.

homology.get_creator_simplex_indices(filtered_complex, dimension_filter=None)

For all n-simplexes, where n > 0, return the 0-simplex with the highest birth filtration value that makes up the original simplex.

Parameters
  • filtered_complex – A non-column reduced filtered simplicial complex (numpy nd-array)

  • dimension_filter – Optional, default None - List of Integers, only return creator simplexes for n-simplexes where n in `dimension_filter`

Returns

A list of indices of creator 0-simplexes.

homology.is_valid_simplex(index_tuples)

Check whether a set of simplexes (in the form of lists of indices) are a valid simplex

Parameters

index_tuples – A list of lists of indices that make up the simplexes.

Returns

True if the combination of tuples is a valid simplex, False otherwise.

homology.new_complexes_created(added_complex, filtered_simplexes, max_dimensions)

Checks if complexes are created because of the birth of a simplex.

Parameters
  • added_complex – The newly added complex; list of indices of simplexes that created it.

  • filtered_simplexes – The filtered simplex matrix.

  • max_dimensions – The upper bound of dimensions for complexes.

Returns

A list of complexes that are created by the birth of added_complex; A list of lists of indices.

homology.reduce_columns(filtered_complex_matrix)

Applies column reduction over a filtered complex matrix.

Parameters

filtered_complex_matrix – A filtered complex matrix. (2 dimensional numpy array)

Returns

A column-reduced filtered complex matrix

homology.simplex_exists(simplex, filtered_simplexes)

Checks whether a given simplex exists in a filtered simplex matrix.

Parameters
  • simplex – A list of indices that created the simplex.

  • filtered_simplexes – A filtered simplex matrix.

Returns

True if the simplex exists in the matrix, False if not.

homology.to_index_tuples(filtered_simplexes, dimension_filter=None)

Get all simplexes from a filtered simplex matrix as tuples of indices of the simplexes that created them.

Parameters
  • filtered_simplexes – A filtered simplex matrix.

  • dimension_filter – Optional, default None - An optional filter to only select simplexes of a given dimensionality

Returns

A list of (tuples with shape [index of simplex in filtered_simplexes, ..indices of simplexes that make up this simplex])

homology.transform_to_birth_persistence(birth_death_tuples, infinity_replacement)

Transform a list of [birth, death] tuples to a list of [birth, persistence] tuples.

Parameters
  • birth_death_tuples – A list of [birth, death] tuples.

  • infinity_replacement – If persistence of a simplex is infinity its persistence will be replaced with this value.

Returns

A list of [birth, persistence] tuples.

homology.transform_to_mid_half_life(birth_death_tuples, infinity_replacement)

Transform a list of [birth, death] tuples to a list of [mid-life, half-life] tuples.

Parameters
  • birth_death_tuples – A list of [birth, death] tuples.

  • infinity_replacement – If death of a simplex is infinity its death will be replaced with this value.

Returns

A list of [mid-life, half-life] tuples.