Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute_fourier_basis Assertion Error #20

Closed
lucy3 opened this issue Jan 18, 2018 · 7 comments
Closed

compute_fourier_basis Assertion Error #20

lucy3 opened this issue Jan 18, 2018 · 7 comments

Comments

@lucy3
Copy link

lucy3 commented Jan 18, 2018

I'm having trouble getting past assert self._e[-1] <= 2 with a graph when I try to compute its fourier basis, so I'm wondering in why this assertion would fail? Why does the largest eigenvalue have to be <= 2?

@nperraud
Copy link
Collaborator

nperraud commented Jan 18, 2018

This assertion is only done if the Laplacian is normalized.

if self.lap_type == 'normalized':
     # Spectrum bounded by [0, 2].
     assert self._e[-1] <= 2

In this case, the spectrum has to be bounded by 2 from the theory. So if your weight matrix is non-negative and symmetric, it should always pass this test.

@lucy3
Copy link
Author

lucy3 commented Jan 26, 2018

Thank you so much for the reply; I really appreciate it.
Hmmm... this is strange, then. The minimum weight in my weight matrix is 1 and G.is_directed() returns False. Any other possible reasons this would fail?

Edit: I tried this:

Gg=pygsp.graphs.Graph(nx.adjacency_matrix(G),lap_type='normalized')
e, U = np.linalg.eigh(Gg.L.toarray())
print e[-1]
Gg.compute_fourier_basis(recompute=True)

This printed 2.0 followed by the assertion error assert self._e[-1] <= 2

Also, I have the following:

print "largest eigenvalue:", Gg._e[-1]
print "Gg._e[-1] == 2.0", Gg._e[-1] == 2.0
print "2.0 <= 2", 2.0 <= 2
print "Gg._e[-1] <= 2", Gg._e[-1] <= 2
print "float(Gg._e[-1]) == 2.0", float(Gg._e[-1]) == 2.0
print "float(Gg._e[-1])", float(Gg._e[-1])

The print output of the above is:
largest eigenvalue: 2.0
Gg._e[-1] == 2.0 False
2.0 <= 2 True
Gg._e[-1] <= 2 False
float(Gg._e[-1]) == 2.0 False
float(Gg._e[-1]) 2.0

I'm pretty confused now. It seems like when I print Gg._e[-1], its value is 2.0, yet the comparisons aren't working.

@nperraud
Copy link
Collaborator

It really looks like a numerical error. We should relax slightly the assertion. I will do it this afternoon.
Thanks for reporting this bug.

@nperraud
Copy link
Collaborator

Could you print for us self._e[-1]-2?

@lucy3
Copy link
Author

lucy3 commented Jan 26, 2018

It prints out 4.84057238737e-14.

@mdeff
Copy link
Collaborator

mdeff commented Jan 26, 2018

It's indeed a numerical issue then (your largest eigenvalue is marginally above 2). We'll relax the assertion. In the mean time you can just comment it. Thanks for reporting!

@mdeff
Copy link
Collaborator

mdeff commented Jan 31, 2019

That was fixed in 58421d5.

@mdeff mdeff closed this as completed Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants