Closed EnLAI111 closed 2 years ago
try this:
import numpy as np
A = np.random.rand(10, 10)
A = A.T @ A
lc = np.linalg.norm(A, ord=2)
print(lc)
def power_iteration(A, n_iter=500):
x = np.random.randn(A.shape[0])
for _ in range(n_iter):
x = A @ x
x /= np.linalg.norm(x)
return np.linalg.norm(A @ x)
ls_pow = power_iteration(A, n_iter=10)
print(ls_pow)
Some algorithms need the l2-norm of A to calculate their step size. When A is used to convolve, I get its norm by
np.linalg.norm(np.A @ np.identity(A.shape[1]), ord=2)
. We wonder if there is a way of calculation without densifing A.