sum_preserving_matrix_partition: Sum preserving matrix partition

View source: R/multiscaleSVDxpts.R

sum_preserving_matrix_partitionR Documentation

Sum preserving matrix partition

Description

This function takes a matrix as input and partitions each column such that only one entry in each row is non-zero, and the sums of each row are roughly equivalent.

Usage

sum_preserving_matrix_partition(X, option = 2, tol = 0.001)

Arguments

X

A matrix of size p x k

option

An integer indicating whether to allow +/- values (option 1) or only + values (option 2). Default is 1.

tol

A numeric value indicating the tolerance for the row sums. Default is 0.1.

Details

The function uses a greedy algorithm to select the entry with the maximum absolute value (or maximum positive value) in each column. The rows are then normalized to ensure that the sums are roughly equivalent.

Value

A matrix with segmented rows

Examples

X <- matrix(rnorm(3000), nrow = 1000)
Y <- sum_preserving_matrix_partition(X, option = 1)
Y <- sum_preserving_matrix_partition(X, option = 2)


stnava/ANTsR documentation built on April 13, 2025, 4:10 a.m.