zen_mapper.adapters

Adapters for converting between zen-mapper types and 3rd party types

Functions

to_networkx(komplex)

Converts a zen-mapper komplex to a networkx graph

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

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

Module Contents

zen_mapper.adapters.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.

zen_mapper.adapters.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]