From 4ae01620a3d77c5d12f66e75f1bee17e5b17d465 Mon Sep 17 00:00:00 2001 From: tky823 Date: Mon, 9 Jan 2023 15:28:47 +0900 Subject: [PATCH] Revert "[notebooks] Add notebooks of #210" This reverts commit 13e443f164f16b1ece2cfeab1af05241514743ed. --- notebooks/ISSUE/issue210.ipynb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 notebooks/ISSUE/issue210.ipynb diff --git a/notebooks/ISSUE/issue210.ipynb b/notebooks/ISSUE/issue210.ipynb deleted file mode 100644 index b4672104..00000000 --- a/notebooks/ISSUE/issue210.ipynb +++ /dev/null @@ -1 +0,0 @@ -{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyOk+zgykinU/TIoX7Y9EwTQ"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"ZRXg3z4bwp5M"},"outputs":[],"source":["!python -m pip install --upgrade setuptools\n","!pip install git+https://github.com/tky823/ssspy.git"]},{"cell_type":"code","source":["import time"],"metadata":{"id":"7prOL4ir9Yj_","executionInfo":{"status":"ok","timestamp":1673244507326,"user_tz":-540,"elapsed":4,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":1,"outputs":[]},{"cell_type":"code","source":["import numpy as np"],"metadata":{"id":"Po3lAbNcxLeU","executionInfo":{"status":"ok","timestamp":1673244507327,"user_tz":-540,"elapsed":4,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":2,"outputs":[]},{"cell_type":"code","source":["from ssspy.linalg import invsqrtmh, sqrtmh, eigh"],"metadata":{"id":"uP9KW32GxK8-","executionInfo":{"status":"ok","timestamp":1673244507327,"user_tz":-540,"elapsed":3,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":3,"outputs":[]},{"cell_type":"code","source":["rng = np.random.default_rng(0)\n","size = (16, 100, 4, 1)"],"metadata":{"id":"qvGFsk1eyCNE","executionInfo":{"status":"ok","timestamp":1673244508268,"user_tz":-540,"elapsed":944,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":4,"outputs":[]},{"cell_type":"code","source":["def create_psd(rng):\n"," x = rng.random(size) + 1j * rng.random(size)\n"," XX = x * x.transpose(0, 1, 3, 2).conj()\n","\n"," return np.mean(XX, axis=0)"],"metadata":{"id":"zYVXoVpWx8zT","executionInfo":{"status":"ok","timestamp":1673244508269,"user_tz":-540,"elapsed":6,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":5,"outputs":[]},{"cell_type":"code","source":["def gmeanmh1(A: np.ndarray, B: np.ndarray) -> np.ndarray:\n"," A_sqrt = sqrtmh(A)\n"," A_invsqrtmh = invsqrtmh(A)\n","\n"," X = A_sqrt @ sqrtmh(A_invsqrtmh @ B @ A_invsqrtmh) @ A_sqrt\n","\n"," return X"],"metadata":{"id":"QyOFdiscxEpL","executionInfo":{"status":"ok","timestamp":1673244508269,"user_tz":-540,"elapsed":6,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":6,"outputs":[]},{"cell_type":"code","source":["def gmeanmh2(A: np.ndarray, B: np.ndarray) -> np.ndarray:\n"," lamb, Z = eigh(A, B)\n"," lamb = np.sqrt(lamb)\n"," Lamb = lamb[..., np.newaxis] * np.eye(Z.shape[-1])\n"," BA = Z @ Lamb @ np.linalg.inv(Z)\n","\n"," return B @ BA"],"metadata":{"id":"zIrzBc_765BW","executionInfo":{"status":"ok","timestamp":1673244508269,"user_tz":-540,"elapsed":6,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":7,"outputs":[]},{"cell_type":"code","source":["times1 = 0\n","times2 = 0\n","\n","for _ in range(1000):\n"," A = create_psd(rng)\n"," B = create_psd(rng)\n","\n"," t1 = time.perf_counter()\n"," G1 = gmeanmh1(A, B)\n"," t2 = time.perf_counter()\n"," G2 = gmeanmh2(A, B)\n"," t3 = time.perf_counter()\n","\n"," times1 += t2 - t1\n"," times2 += t3 - t2\n","\n"," assert np.allclose(G1, G2)\n","\n","print(times1, times2)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"k0FnlE5-yD1N","executionInfo":{"status":"ok","timestamp":1673244518180,"user_tz":-540,"elapsed":9916,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}},"outputId":"6993fdfa-809f-4296-9840-d536c9347461"},"execution_count":8,"outputs":[{"output_type":"stream","name":"stdout","text":["4.762410307000152 3.510937727999746\n"]}]},{"cell_type":"code","source":[],"metadata":{"id":"XmfU0-wa-jHm","executionInfo":{"status":"ok","timestamp":1673244518181,"user_tz":-540,"elapsed":8,"user":{"displayName":"Takuya Hasumi","userId":"03464989896668654835"}}},"execution_count":8,"outputs":[]}]} \ No newline at end of file