create_mapper_object: Mapper

View source: R/cartography_chamber.R

create_mapper_objectR Documentation

Mapper

Description

Run the Mapper algorithm on a data frame.

Usage

create_mapper_object(
  data,
  dists,
  filtered_data,
  cover_element_tests,
  clusterer = NULL
)

Arguments

data

A data frame.

dists

A distance matrix for the data frame. Can be a dist object or matrix.

filtered_data

The result of a function applied to the data frame; there should be one filter value per observation in the original data frame. These values need to be named, and the names of these values must match the names of the original data set.

cover_element_tests

A list of membership test functions for a set of cover elements. In other words, each element of cover_element_tests is a function that returns TRUE or FALSE when given a filter value.

clusterer

A function which accepts a list of distance matrices as input, and returns the results of clustering done on each distance matrix; that is, it should return a list of named vectors, whose names are the names of data points and whose values are cluster assignments (integers). If this value is omitted, then trivial clustering will be done.

Value

A list of two data frames, one with node data and one with edge data. The node data includes:

  • id: vertex ID

  • cluster_size: number of data points in cluster

  • mean_dist_to_medoid: mean distance to medoid of cluster

  • data: names of data points in cluster

  • patch: level set ID

The edge data includes:

  • source: vertex ID of edge source

  • target: vertex ID of edge target

  • weight: Jaccard index of edge; intersection divided by union

  • overlap_data: names of data points in overlap

  • overlap_size: number of data points overlap

Examples

# Create noisy data around a circle
data = data.frame(x = sapply(1:100, function(x) cos(x)), y = sapply(1:100, function(x) sin(x)))

# Apply lens function to data
projx = data$x
names(projx) = row.names(data)

# Build a width-balanced cover with 10 intervals and 25 percent overlap
num_bins = 10
percent_overlap = 25
xcover = create_width_balanced_cover(min(projx), max(projx), num_bins, percent_overlap)

# Write a function which can check if a data point lives in an interval of our lens function
check_in_interval <- function(endpoints) {
 return(function(x) (endpoints[1] - x <= 0) & (endpoints[2] - x >= 0))
}

# Each of the "cover" elements will really be a function that checks if a data point lives in it
xcovercheck = apply(xcover, 1, check_in_interval)

# Build the mapper object
xmapper = create_mapper_object(
  data = data,
  dists = dist(data),
  filtered_data = projx,
  cover_element_tests = xcovercheck
)

mappeR documentation built on June 29, 2025, 1:07 a.m.