You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Continuing from #997, the SciPy maintainers noted that xSTEMR computes zero eigenvalues less accurately than expected for a full real symmetric 3x3 matrix with eigenvalues 3, 1, and 0. I thought that this is just a side effect of the small size but testing with random matrices shows that xSTEMR can compute an approximation as large as 20 ε max(|λ|) to the smallest eigenvalue for a 6x6 matrix with eigenvalues 3, 3, 3, 3, 1, 0 (code below). Personally, I am not sure I would consider such an eigenvalue zero anymore because it is larger than ε n max(|λ|), where n is the dimension of the matrix.
Is this approximation of a zero eigenvalue considered a bug?
Democode (requires Python3, NumPy, and Python):
#!/usr/bin/python3# The code below computes with various methods ("drivers" in SciPy lingo) the# eigenvalues of a random matrix with fixed eigenvalues and computes the# accuracy of one of the eigenvalues. A five-number summary is shown for each# method.importsysimportnumpyasnpimportnumpy.linalgaslaimportscipyfromscipy.linalgimportpinvh, pinvdefsample_smallest_ev(rng, num_samples: int, driver: str, dtype=np.float64):
assertnum_samples>5eigs=np.array([3, 3, 3, 3, 1, 0], dtype=dtype)
errors= []
foriinrange(num_samples):
n=len(eigs)
a=rng.uniform(-1, 1, size=(n, n)).astype(dtype)
q, r=np.linalg.qr(a)
d=np.diag(r)
q=q @ np.diag(d/abs(d))
eps=np.finfo(dtype).epsassertla.norm(q.T @ q-np.eye(n)) <=4*n*eps*la.norm(q)
x=q @ np.diag(eigs) @ q.Tx=np.triu(x) +np.triu(x, 1).Tassertnp.all(x==x.T)
ifdriver=="srf":
es=scipy.linalg.eigvalsh(x)
else:
es=scipy.linalg.eigh(x, driver=driver)[0]
f=minerrors.append(f(es) -f(eigs))
ifdriver=="srf":
continuey1=pinvh(x)
y2=pinv(x)
np.allclose(np.matmul(np.matmul(x, y1), x), x) # truenp.allclose(np.matmul(np.matmul(y1, x), y1), y1) # falsenp.allclose(np.conjugate(np.matmul(x, y1)), np.matmul(x, y1)) # truenp.allclose(np.conjugate(np.matmul(y1, x)), np.matmul(y1, x)) #truenp.allclose(np.matmul(np.matmul(x, y2), x), x) # truenp.allclose(np.matmul(np.matmul(y2, x), y2), y2) # truenp.allclose(np.conjugate(np.matmul(x, y2)), np.matmul(x, y2)) # truenp.allclose(np.conjugate(np.matmul(y2, x)), np.matmul(y2, x)) #trueerrors=sorted(map(lambdax: abs(x) / (max(eigs) *eps), errors))
percentiles=range(0, 101, 25)
five_number_summary=list(map(lambdap: np.percentile(errors, p),
percentiles))
returnfive_number_summarydefmain():
num_samples=1000# srf = square-root free / Pal-Walker-Kahan QR algorithm (eigenvalues only)fordriverin ["evd", "evr", "srf"]:
rng=np.random.RandomState(seed=1)
summary=sample_smallest_ev(rng, num_samples, driver=driver)
print("n=%d driver=%-3s %+8.2e %+8.2e +%8.2e %+8.2e %+8.2e"%
(num_samples, driver, *summary))
if__name__=="__main__":
sys.exit(main())
Output on my x86-64 machine (SciPy 1.10.1, OpenBLAS 0.3.21):
Continuing from #997, the SciPy maintainers noted that xSTEMR computes zero eigenvalues less accurately than expected for a full real symmetric 3x3 matrix with eigenvalues 3, 1, and 0. I thought that this is just a side effect of the small size but testing with random matrices shows that xSTEMR can compute an approximation as large as
20 ε max(|λ|)
to the smallest eigenvalue for a 6x6 matrix with eigenvalues 3, 3, 3, 3, 1, 0 (code below). Personally, I am not sure I would consider such an eigenvalue zero anymore because it is larger thanε n max(|λ|)
, wheren
is the dimension of the matrix.Is this approximation of a zero eigenvalue considered a bug?
Democode (requires Python3, NumPy, and Python):
Output on my x86-64 machine (SciPy 1.10.1, OpenBLAS 0.3.21):
The text was updated successfully, but these errors were encountered: