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

[Model] Add c&s and SAGN, modify SIGN #258

Merged
merged 4 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions cogdl/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
},
},
"ppnp": {
"general": {},
"flickr": {
"lr": 0.005,
"weight_decay": 0.001,
Expand Down Expand Up @@ -209,6 +210,57 @@
# 96.26
},
},
"correct_smooth_mlp": {
"general": {},
"ogbn_arxiv": {
"correct_norm": "row",
"smooth_norm": "col",
"correct_alpha": 0.9791632871592579,
"smooth_alpha": 0.7564990804200602,
"num_correct_prop": 50,
"num_smooth_prop": 50,
"autoscale": True,
"norm": "batchnorm",
},
"ogbn_products": {
"correct_norm": "sym",
"smooth_norm": "row",
"correct_alpha": 1.0,
"smooth_alpha": 0.8,
"num_correct_prop": 50,
"num_smooth_prop": 50,
"autoscale": False,
"scale": 10.0,
"norm": "batchnorm",
"act_first": True,
},
},
"sagn": {
"general": {
"data_gpu": True,
"lr": 0.001,
"hidden-size": 512,
"attn-drop": 0.0,
"dropout": 0.7,
},
"flickr": {
"threshold": 0.5,
"label-hop": 2,
"weight-decay": 3e-6,
"nstage": [50, 50, 50],
"nhop": 2,
"batch-size": 256,
},
"reddit": {
"threshold": 0.9,
"lr": 0.0001,
"batch-size": 1000,
"nhop": 2,
"label-nhop": 4,
"weight-decay": 0.0,
"nstage": [500, 500, 500],
},
},
},
"unsupervised_node_classification": {
"deepwalk": {
Expand Down
41 changes: 41 additions & 0 deletions cogdl/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ def row_norm(self):
self.normalize_adj("row")
self.__symmetric__ = False

def col_norm(self):
if self.row is None:
self.generate_normalization("col")
else:
self.normalize_adj("col")
self.__symmetric__ = False

def generate_normalization(self, norm="sym"):
if self.__normed__:
return
Expand All @@ -209,6 +216,9 @@ def generate_normalization(self, norm="sym"):
edge_norm[torch.isinf(edge_norm)] = 0
self.__out_norm__ = None
self.__in_norm__ = edge_norm.view(-1, 1)
elif norm == "col":
self.row, _, _ = csr2coo(self.row_ptr, self.col, self.weight)
self.weight = row_normalization(self.num_nodes, self.col, self.row, self.weight)
else:
raise NotImplementedError
self.__normed__ = norm
Expand All @@ -223,6 +233,8 @@ def normalize_adj(self, norm="sym"):
self.weight = symmetric_normalization(self.num_nodes, self.row, self.col, self.weight)
elif norm == "row":
self.weight = row_normalization(self.num_nodes, self.row, self.col, self.weight)
elif norm == "col":
self.weight = row_normalization(self.num_nodes, self.col, self.row, self.weight)
else:
raise NotImplementedError
self.__normed__ = norm
Expand Down Expand Up @@ -450,9 +462,16 @@ def remove_self_loops(self):
def row_norm(self):
self._adj.row_norm()

def col_norm(self):
self._adj.col_norm()

def sym_norm(self):
self._adj.sym_norm()

def normalize(self, key="sym"):
assert key in ["row", "sym", "col"], "Support row/col/sym normalization"
getattr(self, f"{key}_norm")()

def is_symmetric(self):
return self._adj.is_symmetric()

Expand All @@ -462,6 +481,28 @@ def set_symmetric(self):
def set_asymmetric(self):
self._adj.set_symmetric(False)

def is_inductive(self):
return self._adj_train is not None

def mask2nid(self, split):
mask = getattr(self, f"{split}_mask")
if mask is not None:
if mask.dtype is torch.bool:
return torch.where(mask)[0]
return mask

@property
def train_nid(self):
return self.mask2nid("train")

@property
def val_nid(self):
return self.mask2nid("val")

@property
def test_nid(self):
return self.mask2nid("test")

@contextmanager
def local_graph(self, key=None):
self.__temp_adj_stack__.append(self._adj)
Expand Down
6 changes: 6 additions & 0 deletions cogdl/datasets/ogb.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class OGBArxivDataset(OGBNDataset):
def __init__(self, data_path="data"):
dataset = "ogbn-arxiv"
super(OGBArxivDataset, self).__init__(data_path, dataset)
self.preprocessing()

def preprocessing(self):
row, col = self.data.edge_index
edge_index = to_undirected(torch.stack([row, col]))
self.data.edge_index = edge_index

def get_evaluator(self):
evaluator = NodeEvaluator(name="ogbn-arxiv")
Expand Down
2 changes: 2 additions & 0 deletions cogdl/match.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ node_classification:
- mvgrl
- grace
- self_auxiliary_task
- correct_smooth_mlp
- sagn
dataset:
- cora
- citeseer
Expand Down
3 changes: 3 additions & 0 deletions cogdl/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@ def build_model(args):
"self_auxiliary_task": "cogdl.models.nn.self_auxiliary_task",
"moe_gcn": "cogdl.models.nn.moe_gcn",
"lightgcn": "cogdl.models.nn.lightgcn",
"correct_smooth": "cogdl.models.nn.correct_smooth",
"correct_smooth_mlp": "cogdl.models.nn.correct_smooth",
"sagn": "cogdl.models.nn.sagn",
}
2 changes: 1 addition & 1 deletion cogdl/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def graph_classification_loss(self, batch):
return self.loss_fn(pred, batch.y)

@staticmethod
def get_trainer(task: Any, args: Any) -> Optional[Type[BaseTrainer]]:
def get_trainer(args=None) -> Optional[Type[BaseTrainer]]:
return None

def set_device(self, device):
Expand Down
3 changes: 2 additions & 1 deletion cogdl/models/nn/agc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def __init__(self, num_clusters, max_iter):
self.k = 0
self.features_matrix = None

def get_trainer(self, task, args):
@staticmethod
def get_trainer(args):
return AGCTrainer

def get_features(self, data):
Expand Down
Loading