epfl-lts2 / pygsp

Graph Signal Processing in Python
https://pygsp.rtfd.io
BSD 3-Clause "New" or "Revised" License
483 stars 93 forks source link

inverse method not working for any filter #101

Open mfarazi1991 opened 3 years ago

mfarazi1991 commented 3 years ago

Hi,

I cannot use the inverse method of filterbanks. I did use the exact codes in the commented part of the inverse method in python files and still get the following error:

AttributeError: 'Abspline' object has no attribute 'inverse'

mdeff commented 3 years ago

Hi, thanks for your interest! You may be using an older version. Try to install the latest from github with pip install git+https://github.com/epfl-lts2/pygsp. (Discussion in #69.)

chiragvshukla commented 2 years ago

I'm on the latest version and also facing the same issue.

I'm also a little confused with the way the package works. If I understand correctly, given a wavelet filter g, g.filter(signal) should give the wavelet coefficients c, and g.inverse(c) should reconstruct the signal, right?

nperraud commented 2 years ago

To inverse coefficient, you have to use the synthesize function. Synthesis is actually the inverse of analysis (analyze is actually the same as filter). The inverse function returns another filter, and does not inverse the coefficients.

Here is untested pseudo code:

signal = np.random.randn(G.N,1)
inverse_filter = g.inverse()
coefs = g.analyze(signal)
reconstructed_signal = inverse_filter.synthesize(coefs)
np.linalg.norm(reconstructed_signal-signal)

Good luck

chiragvshukla commented 2 years ago

Thanks for the pseudo-code and the explanation! The problem still remains in calculating in inverse filter though, since it gives the "object has no attribute 'inverse' " error. Is there a workaround for this?