I would like to perform a matrix balancing in python. I thought to use linalg.matrix_balance
in order to make the input matrix a doubly stochastic matrix:
from scipy import linalg
import numpy as np
x = np.array([[1,2,7], [9,1,1], [1,2,10*np.pi]])
y, permscale = linalg.matrix_balance(x)
np.abs(x).sum(axis=0) / np.abs(x).sum(axis=1)
np.abs(y).sum(axis=0) / np.abs(y).sum(axis=1)
permscale
array([[ 1., 0., 0.],
[ 0., 2., 0.],
[ 0., 0., 1.]])
It doesn't look that it actually balancing the rows and cols of the matrix. Any idea what should I do?
If I do: y, permscale = linalg.matrix_balance(x, scale=False)
The result isn't normalized either:
array([[ 1. , 2. , 7. ], [ 9. , 1. , 1. ], [ 1. , 2. , 31.41592654]])