-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatasets.py
56 lines (44 loc) · 1.73 KB
/
datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import tqdm
import os
import json
import scipy
import torch
from torch_geometric.utils import dense_to_sparse
from torch_geometric.data import Data
def get_datasets(datasets_path:str , label_path:str):
mats = os.listdir(datasets_path)
datasets = {}
for m in tqdm.tqdm(mats):
dataset = []
for i in tqdm.tqdm(range(1,4)):
new_path = datasets_path+m+r'/t_{}/FC/'.format(i)
if '.DS_Store' in new_path:
break
mat = os.listdir(new_path)
mat=[item for item in mat if 'mat' in item][0]
FC = scipy.io.loadmat(new_path+mat)
keys = list(FC.keys())[-1]
FC = FC[keys].astype('int64')
FC = torch.from_numpy(FC)
fcS = torch.where(torch.abs(FC)>0, 1, 0)
# S = fcS + mcS
# denseAdj = torch.where(S>0, 1, 0)
entries = torch.topk(FC.flatten(), 1216).values
denseAdj = torch.where(FC>=entries[-1],1,0)
# denseAdj = torch.where(FC>0.0,FC,0.0)
x = FC
edge_index, _ = dense_to_sparse(denseAdj)
edge_attr = torch.where(FC>=entries[-1], FC, torch.tensor(0).long())
edge_attr = edge_attr.reshape(-1,1)
edge_attr = edge_attr[edge_attr!=0]
edge_attr = (edge_attr - edge_attr.min()) / (edge_attr.max() - edge_attr.min())
dataset.append(Data(torch.nan_to_num(x,0,1,1), edge_index, edge_attr=edge_attr))
if '.DS_Store' in new_path:
continue
datasets[m] = dataset
f = open(label_path)
label = dict(json.load(f))
return datasets,label
datasets_path ="synthetic_data/"
label_path = 'synthetic_data.json'
datasets,label = get_datasets(datasets_path,label_path)