scott.topology.distances¶
- class scott.topology.distances.TopologicalDistance(diagram1, diagram2, norm=2)[source]¶
Bases:
ABC
Abstract base class for computing topological distances.
Takes in two persistence diagrams (or lists of persistence diagrams) and handles necessary transformations to compute a specific distance function.
- diagram 1
The List[PersistenceDiagram] to be compared with diagram2.
- Type:
List[PersistenceDiagram]
- diagram 2
The List[PersistenceDiagram] to be compared with diagram1.
- Type:
List[PersistenceDiagram]
- norm¶
Defines what norm will be used for calculations. Default is 2.
- Type:
int, default=2.
- __init__(diagram1, diagram2, norm=2) None [source]¶
Initializes an instance of the TopologicalDistance class, and converts diagram1 and diagram2 to lists if they are not already.
- Parameters:
diagram1 (PersistenceDiagram or List[PersistenceDiagram]) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram2.
2 (diagram) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram1.
norm (int, default=2.) – Defines what norm will be used for calculations. Default is 2.
- Return type:
None
- class scott.topology.distances.ImageDistance(diagram1, diagram2, norm=2, bandwidth=1.0, weight=<function ImageDistance.<lambda>>, resolution=[20, 20])[source]¶
Bases:
TopologicalDistance
Takes in persistence diagrams, converts them to persistence images, and computes the distance between them. This TopologicalDistance subclass supports comparison of distributions (i.e. input of lists of persistence diagrams).
- diagram 1
The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram2.
- Type:
PersistenceDiagram or List[PersistenceDiagram]
- diagram 2
The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram1.
- Type:
PersistenceDiagram or List[PersistenceDiagram]
- norm¶
Defines what norm will be used for calculations. Default is 2.
- Type:
int, default=2.
- bandwidth¶
Controls the Gaussian kernel for the probability distribution calculated for each point on the birth/persistence diagram. See gudhi documentation for more information.
- Type:
double, default = 1.0
- weight¶
Defines the weight function used to compute the weighted sum of the probability distributions for each point on the bith/persistence diagram, i.e. the persistence surface. Default is a constant function. Other common choices are a linear function or a bump function, which put greater emphasis on points with longer persistence. See gudhi documentation for more information.
- Type:
function, default = lambda x: 1
- resolution¶
The dimensions of the persistence image in pixels.
- Type:
List[int, int], default = [20,20]
- image_transformer¶
The object that powers the transformation of persistence diagrams into persistence images.
- Type:
gudhi package object
- __init__(diagram1, diagram2, norm=2, bandwidth=1.0, weight=<function ImageDistance.<lambda>>, resolution=[20, 20]) None [source]¶
Initializes an instance of the TopologicalDistance class, and converts diagram1 and diagram2 to lists if they are not already.
- Parameters:
diagram1 (PersistenceDiagram or List[PersistenceDiagram]) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram2.
2 (diagram) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram1.
norm (int, default=2.) – Defines what norm will be used for calculations. Default is 2.
- Return type:
None
- fit()[source]¶
Computes and returns persistence images from the persistence diagrams, diagram1 and diagram2 (or the average persistence images, if diagram1 and/or diagram2 are distributions.
- Returns:
avg1 (PersistenceImage) – A wrapper object for the (average) persistence landscape for diagram1. Attribute called ‘pixels’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array that stores image data.
avg2 (PersistenceImage) – A wrapper object for the (average) persistence landscape for diagram1. Attribute called ‘pixels’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array that stores image data.
- transform(image1, image2) float [source]¶
Computes the norm-based distance between two persistence images. Cannot be executed before fit() method has been run to generate persistence images.
- Parameters:
image1 (PersistenceImage) – A wrapper object for the first persistence image to be compared. Attribute called ‘pixels’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (resolution[0] * resolution[1], 1), which contains the values of the persistence surface at each pixel.
image2 (PersistenceImage) – A wrapper object for the second persistence image to be compared. Attribute called ‘pixels’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (resolution[0] * resolution[1], 1), which contains the values of the persistence surface at each pixel.
- Returns:
The norm-based distance between the two given persistence landscapes.
- Return type:
float
- class scott.topology.distances.LandscapeDistance(diagram1, diagram2, norm=2, resolution=1000, num_functions=5)[source]¶
Bases:
TopologicalDistance
Takes in persistence diagrams, converts them to persistence landscapes, and computes the distance between them. This TopologicalDistance subclass supports comparison of distributions (i.e. input of lists of persistence diagrams).
- diagram 1
The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram2.
- Type:
PersistenceDiagram or List[PersistenceDiagram]
- diagram 2
The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram1.
- Type:
PersistenceDiagram or List[PersistenceDiagram]
- norm¶
Defines what norm will be used for calculations. Default is 2.
- Type:
int, default=2.
- resolution¶
The resolution/number of samples in each landscape function.
- Type:
int, default=1000
- num_functions¶
The number of landscape functions to be computed.
- Type:
int, default=5.
- landscape_transformer¶
The object that powers the transformation of persistence diagrams to persistence landscapes.
- Type:
gudhi package object
- __init__(diagram1, diagram2, norm=2, resolution=1000, num_functions=5) None [source]¶
Creates a LandscapeDistance object for two persistence diagrams (or lists of persistence diagrams).
- Parameters:
1 (diagram) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram2.
2 (diagram) – The PersistenceDiagram or List[PersistenceDiagram] to be compared with diagram1.
norm (int, default=2.) – Defines what norm will be used for calculations. Default is 2.
resolution (int, default=1000) – The resolution/number of samples in each landscape function.
num_functions (int, default=5.) – The number of landscape functions to be computed.
- fit()[source]¶
Computes and returns persistence landscapes from the persistence diagrams, diagram1 and diagram2 (or the average persistence landscapes, if diagram1 and/or diagram2 are distributions.
- Returns:
avg1 (PersistenceLandscape) – A wrapper object for the (average) persistence landscape for diagram1. Attribute called ‘functions’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (num_functions * resolution, 1) which concatenates the samples from all landscape functions.
avg2 (PersistenceLandscape) – A wrapper object for the (average) persistence landscape for diagram1. Attribute called ‘functions’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (num_functions * resolution, 1) which concatenates the samples from all landscape functions.
- transform(landscape1: PersistenceLandscape, landscape2: PersistenceLandscape) float [source]¶
Computes the norm-based distance between two persistence landscapes. Cannot be executed before fit() method has been run to generate persistence landscapes.
- Parameters:
landscape1 (PersistenceLandscape) – A wrapper object for the first persistence landscape to be compared. Attribute called ‘functions’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (num_functions * resolution, 1) which concatenates the samples from all landscape functions.
landscape1 – A wrapper object for the second persistence landscape to be compared. Attribute called ‘functions’ stores a Dict[int, np.array] that a maps homology dimension key to a np.array with shape (num_functions * resolution, 1) which concatenates the samples from all landscape functions.
- Returns:
The norm-based distance between the two given persistence landscapes.
- Return type:
float