Python Integration

To demonstrate the SLQ method in Python, we start with a simple symmetric matrix A \in \mathbb{R}^{n \times n}.

import numpy as np
from primate.random import symmetric
A = symmetric(150, psd = True)

This generates a random positive semi-definite matrix with eigenvalues in the interval [0, 1].

from primate.trace import sl_trace
trace_estimate = sl_trace(A)
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))}")