sinkhorn_algorithm: Sinkhorn Algorithm for Matrix Scaling

View source: R/sinkhorn_algorithm.R

sinkhorn_algorithmR Documentation

Sinkhorn Algorithm for Matrix Scaling

Description

This function applies the Sinkhorn-Knopp algorithm to adjust the row and column sums of a matrix to match the target sums. The algorithm iteratively scales the rows and columns by updating scaling factors (alpha and beta) until convergence or the maximum number of iterations is reached.

Usage

sinkhorn_algorithm(initial_table, obj, max_iter = 500, tolerance = 1e-05)

Arguments

initial_table

A matrix to be adjusted using the Sinkhorn algorithm.

obj

An objective function to evaluate the matrix (e.g., entropy, mutual information).

max_iter

The maximum number of iterations for the algorithm (default is 500).

tolerance

The convergence tolerance. If the change in the objective function is smaller than this, the algorithm stops (default is 1e-5).

Value

A list containing:

  • updated_table: The matrix after Sinkhorn scaling.

  • new_mut: The objective function value for the scaled matrix.

  • iter: The number of iterations performed.

  • mutual_info_history: A data frame with the history of objective function values during each iteration.

Examples

initial_table <- matrix(c(5, 3, 4, 2), nrow = 2, ncol = 2)
obj <- entropy_pair  # Example entropy function
result <- sinkhorn_algorithm(initial_table, obj)


covalchemy documentation built on April 12, 2025, 2:15 a.m.