()
| 19 | from torch_geometric.utils.undirected import is_undirected, to_undirected |
| 20 | |
| 21 | def generate_signal_data(): |
| 22 | data = io.loadmat('node_raw_data/2Dgrid.mat') |
| 23 | A = data['A'] |
| 24 | x = data['F'].astype(np.float32) |
| 25 | m = data['mask'] |
| 26 | |
| 27 | A = sp.sparse.coo_matrix(A).todense() |
| 28 | |
| 29 | D_vec = np.sum(A, axis=1).A1 |
| 30 | D_vec_invsqrt_corr = 1 / np.sqrt(D_vec) |
| 31 | D_invsqrt_corr = np.diag(D_vec_invsqrt_corr) |
| 32 | L = np.eye(10000) - D_invsqrt_corr @ A @ D_invsqrt_corr |
| 33 | |
| 34 | e, u = eigh(L) |
| 35 | |
| 36 | y_low = u @ np.diag(np.array([math.exp(-10*(ee-0)**2) for ee in e])) @ u.T @ x |
| 37 | y_high = u @ np.diag(np.array([1 - math.exp(-10*(ee-0)**2) for ee in e])) @ u.T @ x |
| 38 | y_band = u @ np.diag(np.array([math.exp(-10*(ee-1)**2) for ee in e])) @ u.T @ x |
| 39 | y_rej = u @ np.diag(np.array([1 - math.exp(-10*(ee-1)**2) for ee in e])) @ u.T @ x |
| 40 | y_comb = u @ np.diag(np.array([abs(np.sin(ee*math.pi)) for ee in e])) @ u.T @ x |
| 41 | |
| 42 | e = torch.FloatTensor(e) |
| 43 | u = torch.FloatTensor(u) |
| 44 | x = torch.FloatTensor(x) |
| 45 | m = torch.LongTensor(m).squeeze() |
| 46 | y_low = torch.FloatTensor(y_low) |
| 47 | y_high = torch.FloatTensor(y_high) |
| 48 | y_band = torch.FloatTensor(y_band) |
| 49 | y_rej = torch.FloatTensor(y_rej) |
| 50 | y_comb = torch.FloatTensor(y_comb) |
| 51 | |
| 52 | torch.save([e, u, x, y_low, m], 'data/signal_low.pt') |
| 53 | torch.save([e, u, x, y_high, m], 'data/signal_high.pt') |
| 54 | torch.save([e, u, x, y_band, m], 'data/signal_band.pt') |
| 55 | torch.save([e, u, x, y_rej, m], 'data/signal_rej.pt') |
| 56 | torch.save([e, u, x, y_comb, m], 'data/signal_comb.pt') |
| 57 | |
| 58 | |
| 59 | def normalize_graph(g): |
nothing calls this directly
no outgoing calls
no test coverage detected