pygsp
pygsp copied to clipboard
Bug in `interpolate()` when graph has no `mr` attribute
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.
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
.
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)