create_cv_folds: Create Cross-Validation Folds for a Dissimilarity Matrix

View source: R/utils.R

create_cv_foldsR Documentation

Create Cross-Validation Folds for a Dissimilarity Matrix

Description

Creates k-fold cross-validation splits from a dissimilarity matrix while maintaining symmetry. Each fold in the output consists of a training matrix (with some values masked as NA) and a corresponding ground truth matrix for validation.

Usage

create_cv_folds(
  dissimilarity_matrix,
  ground_truth_matrix = NULL,
  n_folds = 10,
  random_seed = NULL
)

Arguments

dissimilarity_matrix

The input dissimilarity matrix, which may contain noise.

ground_truth_matrix

An optional, noise-free dissimilarity matrix to be used as the ground truth for evaluation. If NULL, the input dissimilarity_matrix is used as the truth.

n_folds

The integer number of folds to create.

random_seed

An optional integer to set the random seed for reproducibility.

Value

A list of length n_folds. Each element of the list is itself a list containing two matrices: truth (the ground truth for that fold) and train (the training matrix with NA values for validation).

Note

This function has breaking changes from previous versions:

  • Parameter truth_matrix renamed to dissimilarity_matrix

  • Parameter no_noise_truth renamed to ground_truth_matrix

  • Return structure now uses named elements ($truth, $train)

Examples

# Create a sample dissimilarity matrix
d_mat <- matrix(runif(100), 10, 10)
diag(d_mat) <- 0

# Create 5-fold cross-validation splits
folds <- create_cv_folds(d_mat, n_folds = 5, random_seed = 123)

topolow documentation built on Aug. 31, 2025, 1:07 a.m.