MCPcopy Create free account
hub / github.com/DropEdge/DropEdge / Sampler

Class Sampler

src/sample.py:8–174  ·  view source on GitHub ↗

Sampling the input graph data.

Source from the content-addressed store, hash-verified

6from normalization import fetch_normalization
7
8class Sampler:
9 """Sampling the input graph data."""
10 def __init__(self, dataset, data_path="data", task_type="full"):
11 self.dataset = dataset
12 self.data_path = data_path
13 (self.adj,
14 self.train_adj,
15 self.features,
16 self.train_features,
17 self.labels,
18 self.idx_train,
19 self.idx_val,
20 self.idx_test,
21 self.degree,
22 self.learning_type) = data_loader(dataset, data_path, "NoNorm", False, task_type)
23
24 #convert some data to torch tensor ---- may be not the best practice here.
25 self.features = torch.FloatTensor(self.features).float()
26 self.train_features = torch.FloatTensor(self.train_features).float()
27 # self.train_adj = self.train_adj.tocsr()
28
29 self.labels_torch = torch.LongTensor(self.labels)
30 self.idx_train_torch = torch.LongTensor(self.idx_train)
31 self.idx_val_torch = torch.LongTensor(self.idx_val)
32 self.idx_test_torch = torch.LongTensor(self.idx_test)
33
34 # vertex_sampler cache
35 # where return a tuple
36 self.pos_train_idx = np.where(self.labels[self.idx_train] == 1)[0]
37 self.neg_train_idx = np.where(self.labels[self.idx_train] == 0)[0]
38 # self.pos_train_neighbor_idx = np.where
39
40
41 self.nfeat = self.features.shape[1]
42 self.nclass = int(self.labels.max().item() + 1)
43 self.trainadj_cache = {}
44 self.adj_cache = {}
45 #print(type(self.train_adj))
46 self.degree_p = None
47
48 def _preprocess_adj(self, normalization, adj, cuda):
49 adj_normalizer = fetch_normalization(normalization)
50 r_adj = adj_normalizer(adj)
51 r_adj = sparse_mx_to_torch_sparse_tensor(r_adj).float()
52 if cuda:
53 r_adj = r_adj.cuda()
54 return r_adj
55
56 def _preprocess_fea(self, fea, cuda):
57 if cuda:
58 return fea.cuda()
59 else:
60 return fea
61
62 def stub_sampler(self, normalization, cuda):
63 """
64 The stub sampler. Return the original data.
65 """

Callers 1

train_new.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected