diff --git a/examples/eigenvalue_concentration.py b/examples/eigenvalue_concentration.py index d9fcdd86..e47c78cf 100644 --- a/examples/eigenvalue_concentration.py +++ b/examples/eigenvalue_concentration.py @@ -6,6 +6,7 @@ graph becomes full. """ +import numpy as np from matplotlib import pyplot as plt import pygsp as pg @@ -13,6 +14,7 @@ fig, axes = plt.subplots(4, len(n_neighbors), figsize=(15, 10)) for k, ax in zip(n_neighbors, axes.T): + graph = pg.graphs.Ring(17, k=k) graph.compute_fourier_basis() graph.plot(graph.U[:, 1], ax=ax[0]) @@ -23,4 +25,14 @@ graph.set_coordinates('line1D') graph.plot(graph.U[:, :4], ax=ax[3], title='') + # Check that the DFT matrix is an eigenbasis of the Laplacian. + U = np.fft.fft(np.identity(graph.n_vertices)) + LambdaM = (graph.L.todense().dot(U)) / (U + 1e-15) + # Eigenvalues should be real. + assert np.all(np.abs(np.imag(LambdaM)) < 1e-10) + LambdaM = np.real(LambdaM) + # Check that the eigenvectors are really eigenvectors of the laplacian. + Lambda = np.mean(LambdaM, axis=0) + assert np.all(np.abs(LambdaM - Lambda) < 1e-10) + fig.tight_layout()