-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Hey! Out of curiosity, what is the limitation that prevents imate from working with products of rectangular matrices?
For any real-valued matrix
from math import prod
import numpy as np
from scipy.sparse import random
from scipy.sparse.linalg import svds
from imate import schatten, trace
## Generate random semi-sparse matrix
n = 500
A = random(n, 40, density=0.050)
P = A @ A.T
## Ground truth
sv = np.sort(np.abs(svds(A, k = min(A.shape)-1)[1]))
ev = np.sort(np.linalg.eigh(P.todense())[0])
print(f"Density of P: {P.nnz/prod(P.shape)}")
print(f"(A) Schatten-1 / nuclear norm: {np.sum(sv[sv > 1e-16])}")
print(f"(A) Schatten-2 / frobenius norm: {np.sum(sv[sv > 1e-16]**2)**(1/2)}")
print(f"(P) Schatten-1 / nuclear norm: {np.sum(ev[ev > 1e-16])}")
print(f"(P) Schatten-2 / frobenius norm: {np.sum(ev[ev > 1e-16])**(1/2)}")
# Density of P: 0.096224
# (A) Schatten-1 / nuclear norm: 110.72781488837865
# (A) Schatten-2 / frobenius norm: 18.074377305479523
# (P) Schatten-1 / nuclear norm: 330.2851529166273
# (P) Schatten-2 / frobenius norm: 56.81765769772352I can get the Schatten-norms out of imate:
schatten(P, p=1.0, method="exact")*P.shape[0]
schatten(P, p=2.0, method="exact")*P.shape[0]**(1/2)
# 330.28515291662717
# 56.81765769772352sBut I also want the norms for numpy:
print(f"(A) Schatten-1 / nuclear norm, derived from P: {np.sum(np.sqrt(ev[ev > 1e-16]))}")
print(f"(A) Schatten-2 / frobenius norm, derived from P: {np.sum(ev[ev > 1e-16])**(1/2)}")
# (A) Schatten-1 / nuclear norm, derived from P: 112.62572173011456
# (A) Schatten-2 / frobenius norm, derived from P: 18.173749005547183But when I try this for A via the gramian approach I get an error:
schatten(A, gram=True, p=1.0, method="slq")
# ValueError: Input matrix should be a square matrix.EDIT: Actually the Schatten-p norm of a general matrix expressed as a trace quantity is given by 3rd equation in section 2.3 of Ubaru's paper:
This doesn't seem capturable by imate's definition of the Schatten norm. Am I missing something? Or is this particular matrix function just yet to be implemented in imate?