diff --git a/_sources/notebooks/2.1-dense-keras.ipynb b/_sources/notebooks/2.1-dense-keras.ipynb index c873a2b..32b5180 100644 --- a/_sources/notebooks/2.1-dense-keras.ipynb +++ b/_sources/notebooks/2.1-dense-keras.ipynb @@ -198,7 +198,9 @@ "\n", "NDIM = len(VARS)\n", "inputs = Input(shape=(NDIM,), name=\"input\")\n", - "outputs = Dense(1, name=\"output\", kernel_initializer=\"normal\", activation=\"sigmoid\")(inputs)\n", + "outputs = Dense(1, name=\"output\", kernel_initializer=\"normal\", activation=\"sigmoid\")(\n", + " inputs\n", + ")\n", "\n", "# creae the model\n", "model = Model(inputs=inputs, outputs=outputs)\n", @@ -242,7 +244,9 @@ "\n", "from sklearn.model_selection import train_test_split\n", "\n", - "X_train_val, X_test, Y_train_val, Y_test = train_test_split(X, Y, test_size=0.2, random_state=7)\n", + "X_train_val, X_test, Y_train_val, Y_test = train_test_split(\n", + " X, Y, test_size=0.2, random_state=7\n", + ")\n", "\n", "# preprocessing: standard scalar\n", "from sklearn.preprocessing import StandardScaler\n", diff --git a/_sources/notebooks/3-conv2d.ipynb b/_sources/notebooks/3-conv2d.ipynb index 551c399..c20f62d 100644 --- a/_sources/notebooks/3-conv2d.ipynb +++ b/_sources/notebooks/3-conv2d.ipynb @@ -448,7 +448,7 @@ " save_best_only=True,\n", " save_weights_only=False,\n", " mode=\"auto\",\n", - " save_freq=\"epoch\",\n", + " save_freq=\"epoch\"\n", ")" ] }, diff --git a/_sources/notebooks/4-gnn-cora.ipynb b/_sources/notebooks/4-gnn-cora.ipynb index 180f253..a7bed93 100644 --- a/_sources/notebooks/4-gnn-cora.ipynb +++ b/_sources/notebooks/4-gnn-cora.ipynb @@ -184,7 +184,7 @@ ], "source": [ "# Load Cora dataset\n", - "dataset = Planetoid(root=\"/tmp/Cora\", name=\"Cora\")\n", + "dataset = Planetoid(root='/tmp/Cora', name='Cora')\n", "data = dataset[0]" ] }, @@ -269,13 +269,13 @@ } ], "source": [ - "print(\"node vectors: \\n\", data.x, \"\\n\")\n", - "print(\"node classes: \\n\", data.y, \"\\n\")\n", - "print(\"edge indeces: \\n\", data.edge_index, \"\\n\\n\\n\")\n", + "print(\"node vectors: \\n\", data.x, '\\n')\n", + "print(\"node classes: \\n\", data.y, '\\n')\n", + "print(\"edge indeces: \\n\", data.edge_index, '\\n\\n\\n')\n", "\n", - "print(\"train_mask: \\n\", data.train_mask, \"\\n\")\n", - "print(\"val_mask: \\n\", data.val_mask, \"\\n\")\n", - "print(\"test_mask: \\n\", data.test_mask, \"\\n\")" + "print(\"train_mask: \\n\", data.train_mask, '\\n')\n", + "print(\"val_mask: \\n\", data.val_mask, '\\n')\n", + "print(\"test_mask: \\n\", data.test_mask, '\\n')" ] }, { @@ -316,8 +316,8 @@ "\n", "plt.figure(figsize=(12, 12))\n", "nx.draw(subset_graph, with_labels=False, node_size=10)\n", - "plt.title(\"Visualization of a Subset of the Cora Graph\")\n", - "plt.show()" + "plt.title('Visualization of a Subset of the Cora Graph')\n", + "plt.show()\n" ] }, { @@ -374,7 +374,7 @@ "outputs": [], "source": [ "# Training and evaluation\n", - "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", + "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n", "model = GNN(hidden_channels=16).to(device)\n", "data = data.to(device)\n", "optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)" @@ -437,7 +437,6 @@ "train_loss_history = []\n", "test_accuracy_history = []\n", "\n", - "\n", "def train():\n", " model.train()\n", " optimizer.zero_grad()\n", @@ -447,7 +446,6 @@ " optimizer.step()\n", " return loss.item()\n", "\n", - "\n", "def test():\n", " model.eval()\n", " out = model(data.x, data.edge_index)\n", @@ -456,14 +454,13 @@ " acc = int(correct.sum()) / int(data.test_mask.sum())\n", " return acc\n", "\n", - "\n", "for epoch in range(300):\n", " loss = train()\n", " train_loss_history.append(loss)\n", " accuracy = test()\n", " test_accuracy_history.append(accuracy)\n", " if epoch % 10 == 0:\n", - " print(f\"Epoch: {epoch:03d}, Loss: {loss:.4f}, Accuracy: {accuracy:.4f}\")\n", + " print(f'Epoch: {epoch:03d}, Loss: {loss:.4f}, Accuracy: {accuracy:.4f}')\n", "\n", "print(\"Test Accuracy:\", test())" ] diff --git a/_sources/notebooks/6-gan-mnist.ipynb b/_sources/notebooks/6-gan-mnist.ipynb index a327ba1..25b1cfc 100644 --- a/_sources/notebooks/6-gan-mnist.ipynb +++ b/_sources/notebooks/6-gan-mnist.ipynb @@ -98,8 +98,7 @@ "from tensorflow.keras.layers import Input, Reshape, Dense, Dropout, LeakyReLU\n", "from tensorflow.keras.models import Model, Sequential\n", "from tensorflow.keras.datasets import mnist\n", - "\n", - "# temporarily importing legacy optimizer because of\n", + "# temporarily importing legacy optimizer because of \n", "# https://github.com/keras-team/keras-io/issues/1241#issuecomment-1442383703\n", "from tensorflow.keras.optimizers.legacy import Adam\n", "from tensorflow.keras import backend as K\n", @@ -311,7 +310,7 @@ " )\n", " plt.text(5, 37, val, fontsize=12)\n", " plt.axis(\"off\")\n", - "\n", + " \n", " plt.show()" ] }, diff --git a/notebooks/2.1-dense-keras.html b/notebooks/2.1-dense-keras.html index fdfdebe..2602e4c 100644 --- a/notebooks/2.1-dense-keras.html +++ b/notebooks/2.1-dense-keras.html @@ -549,7 +549,9 @@
# Load Cora dataset
-dataset = Planetoid(root="/tmp/Cora", name="Cora")
+dataset = Planetoid(root='/tmp/Cora', name='Cora')
data = dataset[0]
print("node vectors: \n", data.x, "\n")
-print("node classes: \n", data.y, "\n")
-print("edge indeces: \n", data.edge_index, "\n\n\n")
+print("node vectors: \n", data.x, '\n')
+print("node classes: \n", data.y, '\n')
+print("edge indeces: \n", data.edge_index, '\n\n\n')
-print("train_mask: \n", data.train_mask, "\n")
-print("val_mask: \n", data.val_mask, "\n")
-print("test_mask: \n", data.test_mask, "\n")
+print("train_mask: \n", data.train_mask, '\n')
+print("val_mask: \n", data.val_mask, '\n')
+print("test_mask: \n", data.test_mask, '\n')
# Training and evaluation
-device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
+device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = GNN(hidden_channels=16).to(device)
data = data.to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)
@@ -690,7 +690,6 @@ 4.4. Step 4: Training and Evaluationtrain_loss_history = []
test_accuracy_history = []
-
def train():
model.train()
optimizer.zero_grad()
@@ -700,7 +699,6 @@ 4.4. Step 4: Training and Evaluationoptimizer.step()
return loss.item()
-
def test():
model.eval()
out = model(data.x, data.edge_index)
@@ -709,14 +707,13 @@ 4.4. Step 4: Training and Evaluationacc = int(correct.sum()) / int(data.test_mask.sum())
return acc
-
for epoch in range(300):
loss = train()
train_loss_history.append(loss)
accuracy = test()
test_accuracy_history.append(accuracy)
if epoch % 10 == 0:
- print(f"Epoch: {epoch:03d}, Loss: {loss:.4f}, Accuracy: {accuracy:.4f}")
+ print(f'Epoch: {epoch:03d}, Loss: {loss:.4f}, Accuracy: {accuracy:.4f}')
print("Test Accuracy:", test())