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

Bug in interpolate() when graph has no mr attribute #87

Open
gboaviagem opened this issue Sep 25, 2020 · 2 comments
Open

Bug in interpolate() when graph has no mr attribute #87

gboaviagem opened this issue Sep 25, 2020 · 2 comments

Comments

@gboaviagem
Copy link

gboaviagem commented Sep 25, 2020

Hi everyone. I just found myself having trouble with the pygsp.reduction.interpolate function, and the reason was in line 173 of the reduction.py file:

K_reg = getattr(G.mr, 'K_reg', kron_reduction(L_reg, keep_inds))
green_kernel = getattr(
            G.mr, 'green_kernel',
            filters.Filter(G, lambda x: 1. / (reg_eps + x)))

The error raised was claiming that G did not have any mr attribute. I assume an if-else could be added to fix it, as I have done to my local cloned version:

if hasattr(G, 'mr'):
    K_reg = getattr(G.mr, 'K_reg', kron_reduction(L_reg, keep_inds))
    green_kernel = getattr(
        G.mr, 'green_kernel',
    filters.Filter(G, lambda x: 1. / (reg_eps + x)))
else:
    K_reg = kron_reduction(L_reg, keep_inds)
    green_kernel = filters.Filter(G, lambda x: 1. / (reg_eps + x))

This solved for me. As I'm not from a computer science background and I'm not very familiar with the creation of test files, I thought of writing the problem here, instead of making a pull request. I hope this is helpful. I open this issue to raise attention to this problem and, if in fact you guys see that a fix is needed, a pull request is created.

Thanks.

@mdeff mdeff added bug and removed bug labels Oct 13, 2020
@mdeff
Copy link
Collaborator

mdeff commented Oct 13, 2020

Thanks for reporting. Can you share the code you wrote that triggered the issue? I'm not familiar with this part of the code, but the mr attribute appears to be created by the pygsp.reduction.graph_multiresolution function, which I would assume you'd call before pygsp.reduction.interpolate.

@gboaviagem
Copy link
Author

Yes, sure. And I'm sorry for the huge delay, I had to step back from this problem and just recently returned to it.

I have a graph signal stored in the 1D array s. I decimated half of its samples and I'm trying to estimate the values in the now "unknown" vertices:

from pygsp.reduction import interpolate
from pygsp import graphs
import numpy as np
import copy

frac_zero = 0.5
s_ = copy.deepcopy(s)
idx_zero = np.random.permutation(len(s))[:int(frac_zero*len(s))]
s_[idx_zero] = 0
bool_is_zero = s_ == 0

# Interpolated signal
s_intep = interpolate(
    G, f_subsampled=s[~bool_is_zero], keep_inds=np.where(~bool_is_zero)[0],
    order=100, reg_eps=0.005)

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

2 participants