-
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.
- Loading branch information
1 parent
3986eba
commit 6bd0489
Showing
15 changed files
with
4,841 additions
and
819 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,203 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": { | ||
"ExecuteTime": { | ||
"end_time": "2024-04-25T17:47:32.798261Z", | ||
"start_time": "2024-04-25T17:47:19.035622Z" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from torch_geometric.loader import DataLoader, ImbalancedSampler\n", | ||
"from torch_geometric.transforms import FaceToEdge, OneHotDegree\n", | ||
"import torchvision.transforms as transforms\n", | ||
"import torch.nn.functional as F\n", | ||
"\n", | ||
"from mantra.simplicial import SimplicialDataset\n", | ||
"from mantra.transforms import (\n", | ||
" TriangulationToFaceTransform,\n", | ||
" OrientableToClassTransform,\n", | ||
" DegreeTransform,\n", | ||
")\n", | ||
"from validation.validate_homology import validate_betti_numbers\n", | ||
"\n", | ||
"import torch" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Percentage: 0.27, 0.73\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"class NameToClass: \n", | ||
" def __init__(self):\n", | ||
" self.class_dict = {'Klein bottle': 0, '': 1, 'RP^2': 2, 'T^2': 3, 'S^2': 4}\n", | ||
" \n", | ||
" def __call__(self,data):\n", | ||
" data.y = F.one_hot(torch.tensor(self.class_dict[data.name]),num_classes=5)\n", | ||
" return data\n", | ||
"\n", | ||
"tr = transforms.Compose(\n", | ||
" [\n", | ||
" TriangulationToFaceTransform(),\n", | ||
" FaceToEdge(remove_faces=False),\n", | ||
" DegreeTransform(),\n", | ||
" OrientableToClassTransform(),\n", | ||
" NameToClass()\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"dataset = SimplicialDataset(root=\"./data\", transform=tr)\n", | ||
"\n", | ||
"print(\n", | ||
" f\"Percentage: {sum(dataset.orientable) / len(dataset):.2f}, {(len(dataset) - sum(dataset.orientable)) / len(dataset):.2f}\"\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"C:\\Users\\ernst\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\torch_geometric\\data\\storage.py:450: UserWarning: Unable to accurately infer 'num_nodes' from the attribute set '{'betti_numbers', 'name', 'torsion_coefficients', 'orientable', 'n_vertices', 'genus', 'dimension', 'face'}'. Please explicitly set 'num_nodes' as an attribute of 'data' to suppress this warning\n", | ||
" warnings.warn(\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"tensor([0, 0, 0, 0, 1])" | ||
] | ||
}, | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"data = dataset[0]\n", | ||
"data.y" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 19, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "AttributeError", | ||
"evalue": "'NoneType' object has no attribute 'name'", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[1;32mIn[19], line 5\u001b[0m\n\u001b[0;32m 3\u001b[0m cnt \u001b[38;5;241m=\u001b[39m Counter()\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m data \u001b[38;5;129;01min\u001b[39;00m dataset:\n\u001b[1;32m----> 5\u001b[0m cnt[\u001b[43mdata\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m] \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[0;32m 7\u001b[0m cnt\n", | ||
"\u001b[1;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'name'" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from collections import Counter\n", | ||
"# Tally occurrences of words in a list\n", | ||
"cnt = Counter()\n", | ||
"for data in dataset:\n", | ||
" cnt[data.name] += 1\n", | ||
"\n", | ||
"cnt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 58, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Number of training graphs: 562\n", | ||
"Number of test graphs: 150\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"dataset = dataset.shuffle()\n", | ||
"\n", | ||
"train_dataset = dataset[:-150]\n", | ||
"test_dataset = dataset[-150:]\n", | ||
"\n", | ||
"print(f\"Number of training graphs: {len(train_dataset)}\")\n", | ||
"print(f\"Number of test graphs: {len(test_dataset)}\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 59, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"tensor([0, 0, 0, 1, 1, 0, 0, 1, 0, 1])" | ||
] | ||
}, | ||
"execution_count": 59, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"train_loader = DataLoader(train_dataset,batch_size=10)#,sampler=ImbalancedSampler(train_dataset))\n", | ||
"test_loader = DataLoader(test_dataset,batch_size=10)\n", | ||
"\n", | ||
"\n", | ||
"for batch in train_loader:\n", | ||
" break\n", | ||
"\n", | ||
"batch.y" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.