Learn R Programming

Topological Data Analysis: Mapper Algorithm

This R package implements the Mapper algorithm for topological data analysis (TDA). The Mapper algorithm facilitates visualization and analysis of high-dimensional data by constructing a simplicial complex that represents the underlying structure of the data. The package offers both the standard Mapper and Fuzzy Mapper algorithms, in addition to multiple clustering methods and visualization tools.

Document

For a more detailed explanation for this package, this document will keep update for better understanding the source code. I've written some articles on Medium, which you can find here to get familiar with topological data analysis.

Get started quickly

Step visualize from Skaf et al.

Mapper is basically a three-step process:

1. Cover: This step splits the data into overlapping intervals and creates a cover for the data.

2. Cluster: This step clusters the data points in each interval the cover creates.

3. Simplicial Complex: This step combines the two steps above, which connects the data points in the cover to create a simplicial complex.

you can know more about the basic here: Chazal, F., & Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. Frontiers in artificial intelligence, 4, 667963.

Example

data <- get(data("iris"))

time_taken <- system.time({
  Mapper <- MapperAlgo(
    data[,1:4],
    filter_values = data[,1:3],
    percent_overlap = 20,
    methods = "kmeans",
    method_params = list(max_kmeans_clusters = 2),
    cover_type = 'stride',
    interval_width = 1,
    num_cores = 12
    )
})
FMapper <- FuzzyMapperAlgo(
  original_data = data[,1:4],
  filter_values =  data[,1:2],
  cluster_n = 8,
  fcm_threshold = 0.2,
  methods = "kmeans",
  method_params = list(max_kmeans_clusters = 2)
)

MapperPlotter(Mapper, label=data$Species, original_data=data, avg=FALSE, use_embedding=FALSE)
MapperPlotter(FMapper, label=data$Species, original_data=data, avg=FALSE, use_embedding=FALSE)

Playground (Frontend Beta)

The frontend is still under testing but has been deployed to tda frontend. By integrating webR, it executes the R-based MapperAlgo algorithm directly in the browser via the package.

To visualize your own data, upload a JSON file formatted as shown below. The cc is optional; you can ignore it unless you have pre-calculated labels. The iris example may take a moment to load, so feel free to upload your own file without waiting!


library(jsonlite)

export_data <- list(
  adjacency = Mapper$adjacency,
  num_vertices = Mapper$num_vertices,
  level_of_vertex = Mapper$level_of_vertex,
  points_in_vertex = Mapper$points_in_vertex,
  original_data = as.data.frame(all_features),
  # This is the label that already calculated for each node
  cc = tibble(
    eigen_centrality = e_scores,
    betweenness = b_scores
  )
)
write(toJSON(export_data, auto_unbox = TRUE), "~/desktop/mnist.json")

Copy Link

Version

Install

install.packages('MapperAlgo')

Monthly Downloads

414

Version

1.0.9

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

ChiChien Wang

Last Published

February 3rd, 2026

Functions in MapperAlgo (1.0.9)

cluster_cutoff_at_first_empty_bin

Cut the hierarchical clustering tree to define clusters
MapperAlgo

Mapper Algorithm
GridSearch

GridSearch searched over a list of interval width and overlap, useful for visualizing the convergence of the Mapper.
simplcial_complex

Construct adjacency matrix of the simplicial complex
save_mapper_png

GridSearch searched over a list of interval width and overlap, useful for visualizing the convergence of the Mapper.
to_lsfi

Convert level set multi-index (lsmi) to flat index (lsfi)
FuzzyMapperAlgo

Fuzzy Mapper Algorithm (Fixed Adjacency Calculation)
CPEmbedding

Conditional Probability Embedding for Mapper Nodes
to_lsmi

Convert level set flat index (lsfi) to multi-index (lsmi)
mapperVertices

Create Mapper Vertices
perform_clustering

Perform clustering within a level set
MapperPlotter

Plot Mapper Result
MapperCorrelation

Visualizes the correlation between two Mapper colorings.
cover_points

Cover points based on intervals and overlap
find_best_k_for_kmeans

Find the optimal number of clusters for k-means
mapperEdges

Create Mapper Edges