From de70c3fb6869c6ba41e1206c1a705fba78b677eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:26:18 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black-pre-commit-mirror: 23.7.0 → 23.9.1](https://github.com/psf/black-pre-commit-mirror/compare/23.7.0...23.9.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8973106..a4db56c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black-pre-commit-mirror - rev: "23.7.0" + rev: "23.9.1" hooks: - id: black-jupyter From db8a29add4004e362bd3e7dbcd1cd80ac9384b7f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:26:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../notebooks/2.1-dense-keras.ipynb | 8 ++---- .../notebooks/3-conv2d.ipynb | 2 +- .../notebooks/4-gnn-cora.ipynb | 25 +++++++++++-------- .../notebooks/6-gan-mnist.ipynb | 5 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/machine-learning-hats/notebooks/2.1-dense-keras.ipynb b/machine-learning-hats/notebooks/2.1-dense-keras.ipynb index 32b5180..c873a2b 100644 --- a/machine-learning-hats/notebooks/2.1-dense-keras.ipynb +++ b/machine-learning-hats/notebooks/2.1-dense-keras.ipynb @@ -198,9 +198,7 @@ "\n", "NDIM = len(VARS)\n", "inputs = Input(shape=(NDIM,), name=\"input\")\n", - "outputs = Dense(1, name=\"output\", kernel_initializer=\"normal\", activation=\"sigmoid\")(\n", - " inputs\n", - ")\n", + "outputs = Dense(1, name=\"output\", kernel_initializer=\"normal\", activation=\"sigmoid\")(inputs)\n", "\n", "# creae the model\n", "model = Model(inputs=inputs, outputs=outputs)\n", @@ -244,9 +242,7 @@ "\n", "from sklearn.model_selection import train_test_split\n", "\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", + "X_train_val, X_test, Y_train_val, Y_test = train_test_split(X, Y, test_size=0.2, random_state=7)\n", "\n", "# preprocessing: standard scalar\n", "from sklearn.preprocessing import StandardScaler\n", diff --git a/machine-learning-hats/notebooks/3-conv2d.ipynb b/machine-learning-hats/notebooks/3-conv2d.ipynb index c20f62d..551c399 100644 --- a/machine-learning-hats/notebooks/3-conv2d.ipynb +++ b/machine-learning-hats/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/machine-learning-hats/notebooks/4-gnn-cora.ipynb b/machine-learning-hats/notebooks/4-gnn-cora.ipynb index a7bed93..180f253 100644 --- a/machine-learning-hats/notebooks/4-gnn-cora.ipynb +++ b/machine-learning-hats/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()\n" + "plt.title(\"Visualization of a Subset of the Cora Graph\")\n", + "plt.show()" ] }, { @@ -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,6 +437,7 @@ "train_loss_history = []\n", "test_accuracy_history = []\n", "\n", + "\n", "def train():\n", " model.train()\n", " optimizer.zero_grad()\n", @@ -446,6 +447,7 @@ " optimizer.step()\n", " return loss.item()\n", "\n", + "\n", "def test():\n", " model.eval()\n", " out = model(data.x, data.edge_index)\n", @@ -454,13 +456,14 @@ " 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/machine-learning-hats/notebooks/6-gan-mnist.ipynb b/machine-learning-hats/notebooks/6-gan-mnist.ipynb index 25b1cfc..a327ba1 100644 --- a/machine-learning-hats/notebooks/6-gan-mnist.ipynb +++ b/machine-learning-hats/notebooks/6-gan-mnist.ipynb @@ -98,7 +98,8 @@ "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", - "# temporarily importing legacy optimizer because of \n", + "\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", @@ -310,7 +311,7 @@ " )\n", " plt.text(5, 37, val, fontsize=12)\n", " plt.axis(\"off\")\n", - " \n", + "\n", " plt.show()" ] },