import numpy as np
from primate.random import symmetric
= symmetric(150, psd = True) A
Python Integration
To demonstrate the SLQ method in Python, we start with a simple symmetric matrix A \in \mathbb{R}^{n \times n}.
This generates a random positive semi-definite matrix with eigenvalues in the interval [0, 1].
from primate.trace import sl_trace
= sl_trace(A)
trace_estimate print(A.trace())
print(trace_estimate)
78.57591588717017
78.428444
# tr_est = np.mean(estimates)
# print(f"Error: {abs(tr_est - A.trace()):.5}")
# print(f"Samples std. deviation: {estimates.std(ddof=1)}")
# print(f"Estimator standard error: {estimates.std(ddof=1)/np.sqrt(len(estimates))}")