Implements the Sinkhorn--Knopp algorithm for transforming a square matrix with positive entries to a stochastic matrix with given common row and column sums (e.g., a doubly stochastic matrix).

sinkhorn_knopp(
  A,
  sums = rep(1, nrow(A)),
  niter = 100,
  tol = 1e-08,
  sym = F,
  verb = F
)

Arguments

A

input matrix

sums

desired row/column sums

niter

number of iterations

tol

convergence tolerance

sym

whether to compute symmetric scaling D A D

verb

whether to print the current change

Details

Computes diagonal matrices D1 and D2 to make D1AD2 into a matrix with given row/column sums. For a symmetric matrix A, one can set sym = T to compute a symmetric scaling DAD.