Learn R Programming

topolow (version 1.0.0)

create_cv_folds: Create Cross-validation Folds for Distance Matrix

Description

Creates k-fold cross-validation splits of a distance matrix while maintaining symmetry. Each fold has a training matrix with some values masked for validation.

Usage

create_cv_folds(
  truth_matrix,
  no_noise_truth = NULL,
  n_folds = 10,
  random_seed = NULL
)

Value

A list of length n_folds. Each element is a list containing two matrices:

truth

The truth matrix for that fold.

train

The training matrix with some values replaced by NA for validation.

Arguments

truth_matrix

Matrix of true distances

no_noise_truth

Optional matrix of noise-free distances. If provided, used as truth.

n_folds

Integer number of folds to create

random_seed

Integer random seed for reproducibility

Examples

Run this code
# Create a sample distance matrix
dist_matrix <- matrix(runif(100), 10, 10)
diag(dist_matrix) <- 0
# Create 5-fold CV splits
folds <- create_cv_folds(dist_matrix, n_folds = 5, random_seed = 123)

Run the code above in your browser using DataLab