-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
anpolol
committed
Dec 18, 2023
1 parent
8bcdd70
commit 495768c
Showing
3 changed files
with
89 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
import pytest | ||
import torch_geometric.transforms as T | ||
from stable_gnn.model_link_predict import ModelLinkPrediction | ||
from torch_geometric.datasets import Planetoid | ||
from sklearn.ensemble import GradientBoostingClassifier | ||
import pytest | ||
from sklearn.neural_network import MLPClassifier | ||
from torch_geometric.datasets import Planetoid | ||
|
||
from stable_gnn.model_link_predict import ModelLinkPrediction | ||
|
||
|
||
@pytest.mark.parametrize("conv", ["SAGE", "GAT", "GCN"]) | ||
@pytest.mark.parametrize("loss_name", ["APP", "LINE", "HOPE_AA", "VERSE_Adj"]) | ||
def test_linkpredict(loss_name: str, conv: str) -> None: | ||
root = '../tmp/' | ||
name = 'Cora' | ||
# @pytest.mark.parametrize("conv", ["SAGE", "GAT", "GCN"]) | ||
# @pytest.mark.parametrize("loss_name", ["APP", "LINE", "HOPE_AA", "VERSE_Adj"]) | ||
def test_linkpredict(): # loss_name: str, conv: str) -> None: | ||
root = "../tmp/" | ||
name = "Cora" | ||
dataset = Planetoid(root=root + str(name), name=name, transform=T.NormalizeFeatures()) | ||
|
||
model = ModelLinkPrediction(number_of_trials=50, loss_name=loss_name, emb_conv_name=conv) | ||
model_before = ModelLinkPrediction(number_of_trials=0) # , loss_name=loss_name, emb_conv_name=conv) | ||
model_after = ModelLinkPrediction(number_of_trials=10) # , loss_name=loss_name, emb_conv_name=conv) | ||
|
||
train_edges, train_negative, test_edges, test_negative = model.train_test_edges(dataset) | ||
train_edges_b, train_negative_b, test_edges_b, test_negative_b = model_before.train_test_edges(dataset) | ||
train_edges, train_negative, test_edges, test_negative = model_after.train_test_edges(dataset) | ||
|
||
cl_before = GradientBoostingClassifier(n_estimators=100, learning_rate=0.2, max_depth=5, random_state=0) | ||
cl_after = model.train_cl(train_edges, train_negative) | ||
assert (model.test(cl_before, test_edges, test_negative)) < (model.test(cl_after, test_edges, test_negative)) | ||
cl_before = model_before.train_cl( | ||
train_edges_b, train_negative_b | ||
) # MLPClassifier()#GradientBoostingClassifier(n_estimators=100, learning_rate=0.2, max_depth=5, random_state=0) | ||
cl_after = model_after.train_cl(train_edges, train_negative) | ||
assert (model_before.test(cl_before, test_edges_b, test_negative_b)) < ( | ||
model_after.test(cl_after, test_edges, test_negative) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |