zen_mapper

Submodules

Classes

Width_Balanced_Cover

A cover comprised of equally sized rectangular elements

Functions

sk_learn(→ zen_mapper.types.Clusterer[C])

Wraps a scikit-learn clusterer for use with zen-mapper.

to_networkx(komplex)

Converts a zen-mapper komplex to a networkx graph

precomputed_cover(→ zen_mapper.types.CoverScheme)

A precomputed cover

rectangular_cover(centers, widths, data[, tol])

mapper(→ zen_mapper.types.MapperResult[M])

Constructs a simplicial complex representation of the data.

Package Contents

zen_mapper.sk_learn(base_clusterer: C) zen_mapper.types.Clusterer[C]

Wraps a scikit-learn clusterer for use with zen-mapper.

This function acts as an adapter, allowing scikit-learn’s clustering algorithms to be integrated into the zen-mapper pipeline. Note: any datapoints which are considered noise by the base clusterer are ignored.

Parameters:

base_clusterer (C) – An instance of a scikit-learn compatible clustering algorithm. This object should have a fit_predict method and a labels_ attribute after fitting, which is standard for scikit-learn clusterers.

Returns:

An object conforming to the zen-mapper Clusterer protocol, which wraps the provided clusterer. This allows zen-mapper to use the scikit-learn clusterer’s fit_predict methods within its pipeline. A copy of the fitted base clusterer is also returned as metadata allowing for inspection of the fitted model (e.g., centroids, parameters, dendrograms) after the mapper pipeline.

Return type:

Clusterer[C]

zen_mapper.to_networkx(komplex: zen_mapper.types.Komplex)

Converts a zen-mapper komplex to a networkx graph

This function takes a Komplex object, which represents a simplicial complex, and converts it into a networkx.Graph object. The vertices of the Komplex become the nodes in the networkx graph, and the 1-simplices (edges) of the Komplex become the edges in the networkx graph.

Parameters:

komplex (Komplex) – The Komplex object to convert. This object is expected to have a vertices attribute and support indexing for its simplices (e.g., komplex[1] for 1-simplices).

Returns:

A networkx.Graph object representing the 0- and 1-dimensional structure of the input Komplex.

Return type:

networkx.Graph

Raises:

ImportError – If the networkx library is not installed.

class zen_mapper.Width_Balanced_Cover(n_elements: numpy.typing.ArrayLike, percent_overlap: float)

A cover comprised of equally sized rectangular elements

Parameters:
  • n_elements (ArrayLike) – the number of covering elements along each dimension. If the data is dimension d this results in d^n covering elements.

  • percent_overlap (float) – a number between 0 and 1 representing the ammount of overlap between adjacent covering elements.

Raises:
  • Value Error – if n_elements < 1

  • Value Error – if percent_overlap is not in (0,1)

n_elements
percent_overlap
__call__(data)
zen_mapper.precomputed_cover(cover: zen_mapper.types.Cover) zen_mapper.types.CoverScheme

A precomputed cover

Parameters:

cover (Cover) – the precomputed cover to use

zen_mapper.rectangular_cover(centers, widths, data, tol=1e-09)
zen_mapper.mapper(data: numpy.ndarray, projection: numpy.ndarray, cover_scheme: zen_mapper.types.CoverScheme, clusterer: zen_mapper.types.Clusterer[M], dim: int | None, min_intersection: int = 1) zen_mapper.types.MapperResult[M]

Constructs a simplicial complex representation of the data.

Parameters:
  • data (np.ndarray)

  • projection (np.ndarray) – The output of the lens/filter function on the data. Must have the same number of elements as data.

  • cover_scheme (CoverScheme) – For cover generation. Should be a callable object that takes a numpy array and returns a list of list(indices).

  • clusterer (Clusterer) – A callable object that takes in a dataset and returns an iterator of numpy arrays which contain indices for clustered points.

  • dim (int) – The highest dimension of the mapper complex to compute.

  • min_intersection (int) – The minimum intersection required between clusters to make a simplex.

Returns:

An object containing: - nodes: List of clusters where each cluster is a list of data indices. - nerve: A complete list of simplices. - cover: List of list(indices) corresponding to elements of the cover.

Return type:

MapperResult