-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GATSimplex2Vec for betti numbers and name tasks.
- Loading branch information
Showing
3 changed files
with
183 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import torch | ||
import torchvision.transforms as transforms | ||
from torch_geometric.transforms import FaceToEdge | ||
|
||
from experiments.experiment_utils import perform_experiment | ||
from experiments.lightning_modules.GraphCommonModuleBettiNumbers import ( | ||
GraphCommonModuleBettiNumbers, | ||
) | ||
from mantra.simplicial import SimplicialDataset | ||
from mantra.transforms import ( | ||
TriangulationToFaceTransform, | ||
SetNumNodesTransform, | ||
DegreeTransform, | ||
Simplex2VecTransform, | ||
) | ||
from models.graphs.GAT import GATNetwork | ||
|
||
|
||
class GATSimplexToVecModule(GraphCommonModuleBettiNumbers): | ||
def __init__( | ||
self, | ||
hidden_channels, | ||
num_node_features, | ||
out_channels, | ||
num_heads, | ||
num_hidden_layers, | ||
learning_rate=0.0001, | ||
): | ||
base_model = GATNetwork( | ||
hidden_channels=hidden_channels, | ||
num_node_features=num_node_features, | ||
out_channels=out_channels, | ||
num_heads=num_heads, | ||
num_hidden_layers=num_hidden_layers, | ||
) | ||
super().__init__(base_model=base_model) | ||
self.learning_rate = learning_rate | ||
|
||
def configure_optimizers(self): | ||
optimizer = torch.optim.Adam(self.parameters(), lr=self.learning_rate) | ||
return optimizer | ||
|
||
|
||
def load_dataset_with_transformations(): | ||
tr = transforms.Compose( | ||
[ | ||
TriangulationToFaceTransform(), | ||
SetNumNodesTransform(), | ||
FaceToEdge(remove_faces=False), | ||
DegreeTransform(), | ||
Simplex2VecTransform(), | ||
] | ||
) | ||
dataset = SimplicialDataset(root="./data", transform=tr) | ||
return dataset | ||
|
||
|
||
def single_experiment_betti_numbers_gat_simplex2vec(): | ||
# =============================== | ||
# Training parameters | ||
# =============================== | ||
hidden_channels = 64 | ||
num_hidden_layers = 2 | ||
num_heads = 4 | ||
batch_size = 32 | ||
max_epochs = 100 | ||
learning_rate = 0.0001 | ||
num_workers = 0 | ||
# =============================== | ||
dataset = load_dataset_with_transformations() | ||
model = GATSimplexToVecModule( | ||
hidden_channels=hidden_channels, | ||
num_node_features=dataset.num_node_features, | ||
out_channels=3, # Three different Betti numbers | ||
num_heads=num_heads, | ||
num_hidden_layers=num_hidden_layers, | ||
learning_rate=learning_rate, | ||
) | ||
perform_experiment( | ||
task="betti_numbers", | ||
model=model, | ||
model_name="GATSimplex2Vec", | ||
dataset=dataset, | ||
batch_size=batch_size, | ||
max_epochs=max_epochs, | ||
num_workers=num_workers, | ||
) |
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,89 @@ | ||
import torch | ||
import torchvision.transforms as transforms | ||
from torch_geometric.transforms import FaceToEdge | ||
|
||
from experiments.experiment_utils import perform_experiment | ||
from experiments.lightning_modules.GraphCommonModuleName import ( | ||
GraphCommonModuleName, | ||
) | ||
from mantra.simplicial import SimplicialDataset | ||
from mantra.transforms import ( | ||
TriangulationToFaceTransform, | ||
SetNumNodesTransform, | ||
DegreeTransform, | ||
Simplex2VecTransform, | ||
NameToClassTransform, | ||
) | ||
from models.graphs.GAT import GATNetwork | ||
|
||
|
||
class GATSimplexToVecModule(GraphCommonModuleName): | ||
def __init__( | ||
self, | ||
hidden_channels, | ||
num_node_features, | ||
out_channels, | ||
num_heads, | ||
num_hidden_layers, | ||
learning_rate=0.0001, | ||
): | ||
base_model = GATNetwork( | ||
hidden_channels=hidden_channels, | ||
num_node_features=num_node_features, | ||
out_channels=out_channels, | ||
num_heads=num_heads, | ||
num_hidden_layers=num_hidden_layers, | ||
) | ||
super().__init__(base_model=base_model) | ||
self.learning_rate = learning_rate | ||
|
||
def configure_optimizers(self): | ||
optimizer = torch.optim.Adam(self.parameters(), lr=self.learning_rate) | ||
return optimizer | ||
|
||
|
||
def load_dataset_with_transformations(): | ||
tr = transforms.Compose( | ||
[ | ||
TriangulationToFaceTransform(), | ||
SetNumNodesTransform(), | ||
FaceToEdge(remove_faces=False), | ||
DegreeTransform(), | ||
NameToClassTransform(), | ||
Simplex2VecTransform(), | ||
] | ||
) | ||
dataset = SimplicialDataset(root="./data", transform=tr) | ||
return dataset | ||
|
||
|
||
def single_experiment_name_gat_simplex2vec(): | ||
# =============================== | ||
# Training parameters | ||
# =============================== | ||
hidden_channels = 64 | ||
num_hidden_layers = 2 | ||
num_heads = 4 | ||
batch_size = 32 | ||
max_epochs = 100 | ||
learning_rate = 0.0001 | ||
num_workers = 0 | ||
# =============================== | ||
dataset = load_dataset_with_transformations() | ||
model = GATSimplexToVecModule( | ||
hidden_channels=hidden_channels, | ||
num_node_features=dataset.num_node_features, | ||
out_channels=5, # Five different name classes | ||
num_heads=num_heads, | ||
num_hidden_layers=num_hidden_layers, | ||
learning_rate=learning_rate, | ||
) | ||
perform_experiment( | ||
task="name", | ||
model=model, | ||
model_name="GATSimplex2Vec", | ||
dataset=dataset, | ||
batch_size=batch_size, | ||
max_epochs=max_epochs, | ||
num_workers=num_workers, | ||
) |
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