tdamapper.core Mapper Algorithm
A module containing the main implementation logic for the Mapper algorithm.
- class tdamapper.core.MapperAlgorithm(cover, clustering)
Bases:
objectMain class for performing the Mapper Algorithm.
- Parameters:
cover (A class from tdamapper.cover.) – A cover algorithm.
clustering (A class from tdamapper.clustering or a class from sklearn.cluster) – A clustering algorithm.
- fit(X, y=None)
Computes the Mapper Graph.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
y (numpy.ndarray or list-like.) – Lens values.
- Returns:
self.
- fit_transform(X, y)
Computes the Mapper Graph.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
y (numpy.ndarray or list-like.) – Lens values.
- Returns:
The Mapper graph.
- Return type:
networkx.Graph
- tdamapper.core.aggregate_graph(y, graph, agg)
Computes an aggregation on the nodes of a graph.
- Parameters:
y (numpy.ndarray or list-like.) – A dataset.
graph (networkx.Graph.) – A graph.
agg (Callable.) – An aggregation function.
- Returns:
A dict of values, where each node is mapped to its aggregation.
- Return type:
dict
- tdamapper.core.mapper_connected_components(X, y, cover, clustering)
Computes the connected components of the Mapper graph.
The algorithm computes the connected components using a union-find data structure. This approach should be faster than computing the Mapper graph by first calling mapper_graph and then calling networkx.connected_components on it.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
y (numpy.ndarray or list-like.) – Lens values.
cover (A class from tdamapper.cover.) – A cover algorithm.
clustering (A class from tdamapper.clustering or a class from sklearn.cluster.) – A clustering algorithm.
- Returns:
A list of labels, where the value at position i identifies the connected component of the point X[i].
- Return type:
list[int]
- tdamapper.core.mapper_graph(X, y, cover, clustering)
Computes the Mapper graph.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
y (numpy.ndarray or list-like.) – Lens values.
cover (A class from tdamapper.cover.) – A cover algorithm.
clustering (A class from tdamapper.clustering or a class from sklearn.cluster.) – A clustering algorithm.
- Returns:
The Mapper graph.
- Return type:
networkx.Graph
- tdamapper.core.mapper_labels(X, y, cover, clustering)
Computes the open cover, then perform local clustering on each open set from the cover.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
y (numpy.ndarray or list-like.) – Lens values.
cover (A class from tdamapper.cover.) – A cover algorithm.
clustering (A class from tdamapper.clustering or a class from sklearn.cluster.) – A clustering algorithm.
- Returns:
A list where each item is a sorted list of ints with no duplicate. The list at position i contains the cluster labels to which the point at position i in X belongs to. If i < j, the labels at position i are strictly less then those at position j.
- Return type:
list[list[int]]
tdamapper.cover Cover Algorithms
A module containing the logic for building open covers for the Mapper algorithm.
- class tdamapper.cover.BallCover(radius, metric, flat=True)
Bases:
ProximityNetCoverCreates an open cover made of overlapping open balls of fixed radius.
This class implements the Ball Proximity function: after calling fit, the search method returns all the points within a ball centered in the target point.
- Parameters:
radius (float.) – The radius of open balls
metric (Callable.) – The metric used to define open balls.
flat (bool) – Set to True to use flat vptrees.
- fit(X)
- search(x)
- class tdamapper.cover.CubicalCover(n_intervals, overlap_frac, flat=True)
Bases:
ProximityNetCoverCreates an open cover of hypercubes of evenly-sized sides and overlap.
This class implements the Cubical Proximity function: after calling fit, the search method returns the hypercube whose center is nearest to the target point. Each hypercube is the product of 1-dimensional intervals with the same lenght and overlap.
- Parameters:
n_intervals (int.) – The number of intervals on each dimension.
overlap_frac (float in (0.0, 1.0).) – The overlap fraction.
flat (bool) – Set to True to use flat vptrees.
- fit(X)
- search(x)
- class tdamapper.cover.KNNCover(neighbors, metric, flat=True)
Bases:
ProximityNetCoverCreates an open cover where each open set containes a fixed number of neighbors, using KNN.
This class implements the KNN Proximity function: after calling fit, the search method returns the k nearest points to the target point.
- Parameters:
neighbors (int.) – The number of neighbors.
metric (function.) – The metric used to search neighbors.
flat (bool) – Set to True to use flat vptrees.
- fit(X)
- search(x)
- class tdamapper.cover.Proximity
Bases:
objectThis class serves as a blueprint for proximity functions used inside proximity_net.
Subclasses are expected to override the methods fit and search.
- fit(X)
- search(x)
- class tdamapper.cover.ProximityNetCover
Bases:
ProximityThis class serves as a blueprint for cover algorithm based on proximity-net.
- apply(X)
- class tdamapper.cover.TrivialCover
Bases:
ProximityNetCoverCreates an open cover made of a single open set that contains the whole dataset.
- fit(X)
- search(x)
- tdamapper.cover.proximity_net(X, proximity)
Compute proximity-net for a given proximity function.
Returns a generator where each item is a subset of ids of points from X.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
proximity (tdamapper.cover.Proximity) – A proximity function.
tdamapper.clustering Clustering Algorithms
A module containing the logic related to clustering for the Mapper algorithm.
- class tdamapper.clustering.FailSafeClustering(clustering, verbose=True)
Bases:
objectA delegating clustering algorithm that prevents failure. When clustering fails, instead of throwing an exception, a single cluster, containing all points, is returned.
- Parameters:
clustering (Anything compatible with a sklearn.cluster class.) – A clustering algorithm to delegate to.
verbose (bool) – Set to True to log exceptions.
- fit(X, y=None)
- class tdamapper.clustering.MapperClustering(cover=None, clustering=None)
Bases:
objectA clustering algorithm based on the Mapper graph. The Mapper algorithm returns a graph where each point is eventually contained in multiple nodes. In this case all those nodes are connected in the Mapper graph, therefore they share the same connected component. For this reason the notion of connected component is well-defined for any point of the dataset. This class clusters point according to their connected component in the Mapper graph.
- Parameters:
clustering (Anything compatible with a sklearn.cluster class.) – A clustering algorithm.
- fit(X, y=None)
tdamapper.plot Mapper Plot
A module for plotting the Mapper graph.
- class tdamapper.plot.MapperPlot(X, graph, colors=None, agg=<function nanmean>, cmap='jet', **kwargs)
Bases:
objectCreates a plot for the Mapper graph, and turn it into a displayable figure.
- Parameters:
X (numpy.ndarray or list-like.) – A dataset.
graph (networkx.Graph) – The Mapper graph.
colors (numpy.ndarray or list-like.) – A dataset of values to plot as nodes color.
agg (Callable on the values of colors.) – Aggregation function that computes nodes color.
cmap (str) – A colormap, to convert values into colors.
kwargs – Additional arguments to networkx.spring_layout.
- Type:
dict
- plot(*args, style='interactive', **kwargs)
Turns the plot object into a displayable figure.
- Parameters:
args (list) – Arguments to supply.
style (str) – The type of plot, can either be ‘interactive’ or ‘static’.
kwargs (dict) – Additional arguments to supply.
- with_colors(colors, agg=<function nanmean>, cmap='jet')