Skip to contents

similarity_matrix is a helper function used within rips_similarity_matrix to construct a pairwise similarity matrix comparing pairs of persistence diagrams.

Usage

similarity_matrix(rips.list, n.sample, PIDs, print.progress = FALSE)

Arguments

rips.list

A list of persistence diagrams for each sample

n.sample

The number of samples in the dataset (the length of rips.list)

PIDs

Unique identifiers for each sample. This will be used to name the resulting similarity matrix.

print.progress

Should a progress bar be printed?

Value

Returns a list of kernel (similarity matrices) for each homology group.

Examples

require(magrittr)
require(TDAstats)
#> Loading required package: TDAstats

# Save the PIDs
PIDs <- unique(data1.df$PID)

# Save the number of samples
n.sample <- length(PIDs)

# Initialize a list to store the Rips filtrations
rips.list <- lapply(1:n.sample, function(i) list()); names(rips.list) <- PIDs

# Iterate through the samples to construct Rips filtration
for (i in PIDs) {


 # Subset the data to just this PID
 data.i <- data1.df %>%
   dplyr::filter(PID == i) %>%
   dplyr::select(x,y)

 # Construct a Rips filtration using TDAstats
 rips.i <- TDAstats::calculate_homology(data.i, dim = 1, threshold = 10)

 # Save
 rips.list[[i]] <- rips.i
}
 K.list <- similarity_matrix(rips.list, n.sample, PIDs)