tda
This module contains for topological data analysis (TDA) of loss landscapes.
bottleneck_distance(p1, p2)
Calculates the bottleneck distance between two persistence diagrams.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
p1
|
ArrayLike
|
The first persistence diagram, represented as a 1D array of persistence values. |
required |
p2
|
ArrayLike
|
The second persistence diagram, represented as a 1D array of persistence values. |
required |
Returns:
Type | Description |
---|---|
float
|
A float representing the bottleneck distance between the two diagrams. |
Source code in src/landscaper/tda.py
digraph_mt(mt)
Converts a merge tree to a directed graph representation that makes it easy to navigate the hierarchy.
The root is the maximum which points down the tree towards saddles and minima. The 'partition' edge attributes list the members of the integral line from node a->b, while 'counts' contains the number of members along that line.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mt
|
MergeTree
|
The merge tree to convert. |
required |
Returns:
Type | Description |
---|---|
DiGraph
|
A networkx DiGraph representation of the merge tree hierarchy. |
Source code in src/landscaper/tda.py
get_persistence_dict(msc)
Returns the persistence of the given Morse-Smale complex as a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msc
|
MorseSmaleComplex
|
A Morse-Smale complex from Topopy. |
required |
Returns:
Type | Description |
---|---|
The values of the Morse-Smale Complex as a dictionary of nodes to persistence values. |
Source code in src/landscaper/tda.py
merge_tree(loss, coords, graph, direction=1)
Helper function used to generate a merge tree for a loss landscape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss
|
ArrayLike
|
Function values for each point in the space. |
required |
coords
|
ArrayLike
|
N-dimensional array of ranges for each dimension in the space. |
required |
graph
|
nglGraph
|
nglpy graph of the space (usually filled out by topopy). |
required |
direction
|
Literal[-1, 1]
|
The direction to generate a merge tree for. -1 generates a merge tree for maxima, while the default value (1) is for minima. |
1
|
Returns:
Type | Description |
---|---|
MergeTree
|
Merge tree for the space. |
Source code in src/landscaper/tda.py
merge_tree_to_nx(mt)
Converts a Topopy MergeTree to a networkx representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mt
|
MergeTree
|
The merge tree to convert. |
required |
Returns:
Type | Description |
---|---|
Graph
|
A networkx Graph representation of the merge tree. Can be used for visualization and analysis. |
Source code in src/landscaper/tda.py
topological_index(msc, idx)
Gets the topological index of a given point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msc
|
MorseSmaleComplex
|
The Morse-Smale complex that represents the space being analyzed. |
required |
idx
|
int
|
The index of the point to get a topological index for. |
required |
Returns:
Type | Description |
---|---|
Literal[0, 1, 2]
|
Either 0, 1, or 2. This indicates that the point is either a minima (0), saddle point (1) or a maxima (2). |