Skip to content

Commit

Permalink
ring example: check that DFT is an eigenbasis (by Nathanaël)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeff committed Mar 29, 2019
1 parent 9eb2b1d commit 3707266
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/eigenvalue_concentration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
graph becomes full.
"""

import numpy as np
from matplotlib import pyplot as plt
import pygsp as pg

n_neighbors = [1, 2, 5, 8]
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])
Expand All @@ -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()

0 comments on commit 3707266

Please sign in to comment.