|
|
@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cells": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 1,
|
|
|
|
|
|
|
|
"id": "b8e97ab8-4f81-4e8b-9b71-7076a11e9280",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "stderr",
|
|
|
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
|
|
|
"text": [
|
|
|
|
|
|
|
|
"/home/vlpr/.local/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
|
|
|
|
|
|
|
" from .autonotebook import tqdm as notebook_tqdm\n"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"from scipy.io import loadmat\n",
|
|
|
|
|
|
|
|
"import pandas as pd\n",
|
|
|
|
|
|
|
|
"import numpy as np\n",
|
|
|
|
|
|
|
|
"import matplotlib.pyplot as plt\n",
|
|
|
|
|
|
|
|
"from matplotlib import cm\n",
|
|
|
|
|
|
|
|
"import seaborn as sns\n",
|
|
|
|
|
|
|
|
"plt.rcParams['figure.figsize'] = [9, 5]\n",
|
|
|
|
|
|
|
|
"from cycler import cycler\n",
|
|
|
|
|
|
|
|
"from IPython.display import display, clear_output\n",
|
|
|
|
|
|
|
|
"import optuna\n",
|
|
|
|
|
|
|
|
"import time \n",
|
|
|
|
|
|
|
|
"import ray\n",
|
|
|
|
|
|
|
|
"import torch\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"# import joblib\n",
|
|
|
|
|
|
|
|
"# from ray.util.joblib import register_ray\n",
|
|
|
|
|
|
|
|
"# register_ray()"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
|
|
|
"id": "95472450-29ba-4f4a-8641-a623b6d6d76f",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"В этой книге подбираются гиперпараметры синтетической модели движения головы в фмр томографе с помощью библиотеки optuna. \n",
|
|
|
|
|
|
|
|
"В качестве базовой модели взят классификатор из 3х свёрточных и двух полносвязных слоёв. \n",
|
|
|
|
|
|
|
|
"Решается задача максимизации точности классификатора, расчитанной для данных записанных с реального томографа. \n",
|
|
|
|
|
|
|
|
"Классификатор обучен на синтетических данных для варьируемых гипераметров. "
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 2,
|
|
|
|
|
|
|
|
"id": "2b5d4395-2896-4254-9dd2-a00d5b599e5e",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"window_size = 3"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "137610a1-fd50-465c-a366-8727f8172fbe",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"from synthetic_dataset_utils import gen_Xy \n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"X_train, y_train, X_val, y_val = gen_Xy(sample_num=20, timesteps=340, channels=6, window_size=window_size)"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 5,
|
|
|
|
|
|
|
|
"id": "9413e010-4084-4970-ad6f-abbaba2c7ff8",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"# Use one of \"Prepare\" in generate_real_data.ipynb\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"X_test = np.load(f\"../assets/X_test_{window_size}.npy\")\n",
|
|
|
|
|
|
|
|
"y_test = np.load(f\"../assets/y_test_{window_size}.npy\")"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 6,
|
|
|
|
|
|
|
|
"id": "7dfd59a0-4b38-4172-977d-0bc9a15575a6",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"import torch\n",
|
|
|
|
|
|
|
|
"import torch.nn as nn\n",
|
|
|
|
|
|
|
|
"from torch_train_utils import print_results, train\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"class Model1D(nn.Module):\n",
|
|
|
|
|
|
|
|
" def __init__(self, input_shape):\n",
|
|
|
|
|
|
|
|
" super(Model1D, self).__init__()\n",
|
|
|
|
|
|
|
|
" self.instance_norm = nn.InstanceNorm1d(input_shape[0])\n",
|
|
|
|
|
|
|
|
" self.conv1 = nn.Sequential(nn.Conv1d(input_shape[0], 128, kernel_size=3, padding='same'), nn.ELU())\n",
|
|
|
|
|
|
|
|
" self.dense1 = nn.Sequential(nn.Flatten(), nn.Linear(128*input_shape[1], 128), nn.ELU())\n",
|
|
|
|
|
|
|
|
" self.dense2 = nn.Sequential(nn.Linear(128, 128), nn.ELU())\n",
|
|
|
|
|
|
|
|
" self.classifier = nn.Linear(128, 1)\n",
|
|
|
|
|
|
|
|
" self.sigmoid = nn.Sigmoid()\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
" def forward(self, x):\n",
|
|
|
|
|
|
|
|
" x = self.instance_norm(x)\n",
|
|
|
|
|
|
|
|
" x = self.conv1(x)\n",
|
|
|
|
|
|
|
|
" x = self.dense1(x)\n",
|
|
|
|
|
|
|
|
" x = self.dense2(x)\n",
|
|
|
|
|
|
|
|
" x = self.sigmoid(self.classifier(x))\n",
|
|
|
|
|
|
|
|
" return x.squeeze(1)"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "220e60bf-2d43-4bfd-8026-a12e0f448c61",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"# check that model trains\n",
|
|
|
|
|
|
|
|
"model = Model1D(X_train.shape[1:])\n",
|
|
|
|
|
|
|
|
"train(X_train, y_train, X_test, y_test, model, epochs=100, lr=1e-1, verbose=True);"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 8,
|
|
|
|
|
|
|
|
"id": "69aadbd5-30d5-42d2-8089-f0c75fbeca1f",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"def objective(trial):\n",
|
|
|
|
|
|
|
|
" clear_output(wait=True)\n",
|
|
|
|
|
|
|
|
" noise_std_min = trial.suggest_float('noise_std_min', 0.000001, 0.0001)\n",
|
|
|
|
|
|
|
|
" noise_std_max = trial.suggest_float('noise_std_max', 0.0001, 0.1)\n",
|
|
|
|
|
|
|
|
" noise_std_stp = 6.643190903827471e-05\n",
|
|
|
|
|
|
|
|
" harm_ampl_min = trial.suggest_float('harm_ampl_min', 0.001, 0.005)\n",
|
|
|
|
|
|
|
|
" harm_ampl_max = trial.suggest_float('harm_ampl_max', 0.005, 0.1)\n",
|
|
|
|
|
|
|
|
" harm_ampl_step = 0.0006277917832562148\n",
|
|
|
|
|
|
|
|
" probability_steps = 0.01\n",
|
|
|
|
|
|
|
|
" step_ampl_min = trial.suggest_float('step_ampl_min', 0.00001, 0.0001)\n",
|
|
|
|
|
|
|
|
" step_ampl_max = trial.suggest_float('step_ampl_max', 0.0001, 0.8)\n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
" X_train, y_train, X_val, y_val = gen_Xy(\n",
|
|
|
|
|
|
|
|
" sample_num=100, \n",
|
|
|
|
|
|
|
|
" timesteps=340, \n",
|
|
|
|
|
|
|
|
" channels=6, \n",
|
|
|
|
|
|
|
|
" window_size=window_size,\n",
|
|
|
|
|
|
|
|
" noise_std_min=noise_std_min,\n",
|
|
|
|
|
|
|
|
" noise_std_max=noise_std_max,\n",
|
|
|
|
|
|
|
|
" noise_std_stp=noise_std_stp,\n",
|
|
|
|
|
|
|
|
" harm_ampl_min=harm_ampl_min,\n",
|
|
|
|
|
|
|
|
" harm_ampl_max=harm_ampl_max,\n",
|
|
|
|
|
|
|
|
" harm_ampl_step=harm_ampl_step,\n",
|
|
|
|
|
|
|
|
" probability_steps=probability_steps,\n",
|
|
|
|
|
|
|
|
" step_ampl_min=step_ampl_min,\n",
|
|
|
|
|
|
|
|
" step_ampl_max=step_ampl_max\n",
|
|
|
|
|
|
|
|
" )\n",
|
|
|
|
|
|
|
|
" model = Model1D(X_train.shape[1:])\n",
|
|
|
|
|
|
|
|
" results, history = train(X_train, y_train, X_test, y_test, model, epochs=100, lr=1e-1)\n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
" return results['val_accuracy']\n"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 9,
|
|
|
|
|
|
|
|
"id": "df871ce2-01ed-470a-b7fc-2f371af2cbd7",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "stderr",
|
|
|
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
|
|
|
"text": [
|
|
|
|
|
|
|
|
"\u001b[32m[I 2023-04-19 15:01:21,126]\u001b[0m A new study created in RDB with name: ray\u001b[0m\n"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"study = optuna.create_study(direction=\"maximize\", storage=f'sqlite:///../results/hyperparameter_study_{window_size}.db', study_name='ray')#, sampler=optuna.samplers.CmaEsSampler())"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 10,
|
|
|
|
|
|
|
|
"id": "4bbe0684-702d-4cb3-92bd-86123505c0f0",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "stderr",
|
|
|
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
|
|
|
"text": [
|
|
|
|
|
|
|
|
"2023-04-19 15:01:23,341\tWARNING services.py:1780 -- WARNING: The object store is using /tmp instead of /dev/shm because /dev/shm has only 67084288 bytes available. This will harm performance! You may be able to free up space by deleting files in /dev/shm. If you are inside a Docker container, you can increase /dev/shm size by passing '--shm-size=10.24gb' to 'docker run' (or add it to the run_options list in a Ray cluster config). Make sure to set this to more than 30% of available RAM.\n",
|
|
|
|
|
|
|
|
"2023-04-19 15:01:24,578\tINFO worker.py:1553 -- Started a local Ray instance.\n"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
|
|
"text/html": [
|
|
|
|
|
|
|
|
"<div>\n",
|
|
|
|
|
|
|
|
" <div style=\"margin-left: 50px;display: flex;flex-direction: row;align-items: center\">\n",
|
|
|
|
|
|
|
|
" <h3 style=\"color: var(--jp-ui-font-color0)\">Ray</h3>\n",
|
|
|
|
|
|
|
|
" <svg version=\"1.1\" id=\"ray\" width=\"3em\" viewBox=\"0 0 144.5 144.6\" style=\"margin-left: 3em;margin-right: 3em\">\n",
|
|
|
|
|
|
|
|
" <g id=\"layer-1\">\n",
|
|
|
|
|
|
|
|
" <path fill=\"#00a2e9\" class=\"st0\" d=\"M97.3,77.2c-3.8-1.1-6.2,0.9-8.3,5.1c-3.5,6.8-9.9,9.9-17.4,9.6S58,88.1,54.8,81.2c-1.4-3-3-4-6.3-4.1\n",
|
|
|
|
|
|
|
|
" c-5.6-0.1-9.9,0.1-13.1,6.4c-3.8,7.6-13.6,10.2-21.8,7.6C5.2,88.4-0.4,80.5,0,71.7c0.1-8.4,5.7-15.8,13.8-18.2\n",
|
|
|
|
|
|
|
|
" c8.4-2.6,17.5,0.7,22.3,8c1.3,1.9,1.3,5.2,3.6,5.6c3.9,0.6,8,0.2,12,0.2c1.8,0,1.9-1.6,2.4-2.8c3.5-7.8,9.7-11.8,18-11.9\n",
|
|
|
|
|
|
|
|
" c8.2-0.1,14.4,3.9,17.8,11.4c1.3,2.8,2.9,3.6,5.7,3.3c1-0.1,2,0.1,3,0c2.8-0.5,6.4,1.7,8.1-2.7s-2.3-5.5-4.1-7.5\n",
|
|
|
|
|
|
|
|
" c-5.1-5.7-10.9-10.8-16.1-16.3C84,38,81.9,37.1,78,38.3C66.7,42,56.2,35.7,53,24.1C50.3,14,57.3,2.8,67.7,0.5\n",
|
|
|
|
|
|
|
|
" C78.4-2,89,4.7,91.5,15.3c0.1,0.3,0.1,0.5,0.2,0.8c0.7,3.4,0.7,6.9-0.8,9.8c-1.7,3.2-0.8,5,1.5,7.2c6.7,6.5,13.3,13,19.8,19.7\n",
|
|
|
|
|
|
|
|
" c1.8,1.8,3,2.1,5.5,1.2c9.1-3.4,17.9-0.6,23.4,7c4.8,6.9,4.6,16.1-0.4,22.9c-5.4,7.2-14.2,9.9-23.1,6.5c-2.3-0.9-3.5-0.6-5.1,1.1\n",
|
|
|
|
|
|
|
|
" c-6.7,6.9-13.6,13.7-20.5,20.4c-1.8,1.8-2.5,3.2-1.4,5.9c3.5,8.7,0.3,18.6-7.7,23.6c-7.9,5-18.2,3.8-24.8-2.9\n",
|
|
|
|
|
|
|
|
" c-6.4-6.4-7.4-16.2-2.5-24.3c4.9-7.8,14.5-11,23.1-7.8c3,1.1,4.7,0.5,6.9-1.7C91.7,98.4,98,92.3,104.2,86c1.6-1.6,4.1-2.7,2.6-6.2\n",
|
|
|
|
|
|
|
|
" c-1.4-3.3-3.8-2.5-6.2-2.6C99.8,77.2,98.9,77.2,97.3,77.2z M72.1,29.7c5.5,0.1,9.9-4.3,10-9.8c0-0.1,0-0.2,0-0.3\n",
|
|
|
|
|
|
|
|
" C81.8,14,77,9.8,71.5,10.2c-5,0.3-9,4.2-9.3,9.2c-0.2,5.5,4,10.1,9.5,10.3C71.8,29.7,72,29.7,72.1,29.7z M72.3,62.3\n",
|
|
|
|
|
|
|
|
" c-5.4-0.1-9.9,4.2-10.1,9.7c0,0.2,0,0.3,0,0.5c0.2,5.4,4.5,9.7,9.9,10c5.1,0.1,9.9-4.7,10.1-9.8c0.2-5.5-4-10-9.5-10.3\n",
|
|
|
|
|
|
|
|
" C72.6,62.3,72.4,62.3,72.3,62.3z M115,72.5c0.1,5.4,4.5,9.7,9.8,9.9c5.6-0.2,10-4.8,10-10.4c-0.2-5.4-4.6-9.7-10-9.7\n",
|
|
|
|
|
|
|
|
" c-5.3-0.1-9.8,4.2-9.9,9.5C115,72.1,115,72.3,115,72.5z M19.5,62.3c-5.4,0.1-9.8,4.4-10,9.8c-0.1,5.1,5.2,10.4,10.2,10.3\n",
|
|
|
|
|
|
|
|
" c5.6-0.2,10-4.9,9.8-10.5c-0.1-5.4-4.5-9.7-9.9-9.6C19.6,62.3,19.5,62.3,19.5,62.3z M71.8,134.6c5.9,0.2,10.3-3.9,10.4-9.6\n",
|
|
|
|
|
|
|
|
" c0.5-5.5-3.6-10.4-9.1-10.8c-5.5-0.5-10.4,3.6-10.8,9.1c0,0.5,0,0.9,0,1.4c-0.2,5.3,4,9.8,9.3,10\n",
|
|
|
|
|
|
|
|
" C71.6,134.6,71.7,134.6,71.8,134.6z\"/>\n",
|
|
|
|
|
|
|
|
" </g>\n",
|
|
|
|
|
|
|
|
" </svg>\n",
|
|
|
|
|
|
|
|
" <table>\n",
|
|
|
|
|
|
|
|
" <tr>\n",
|
|
|
|
|
|
|
|
" <td style=\"text-align: left\"><b>Python version:</b></td>\n",
|
|
|
|
|
|
|
|
" <td style=\"text-align: left\"><b>3.10.6</b></td>\n",
|
|
|
|
|
|
|
|
" </tr>\n",
|
|
|
|
|
|
|
|
" <tr>\n",
|
|
|
|
|
|
|
|
" <td style=\"text-align: left\"><b>Ray version:</b></td>\n",
|
|
|
|
|
|
|
|
" <td style=\"text-align: left\"><b> 2.3.1</b></td>\n",
|
|
|
|
|
|
|
|
" </tr>\n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
" </table>\n",
|
|
|
|
|
|
|
|
" </div>\n",
|
|
|
|
|
|
|
|
"</div>\n"
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"text/plain": [
|
|
|
|
|
|
|
|
"RayContext(dashboard_url='', python_version='3.10.6', ray_version='2.3.1', ray_commit='5f14cee8dfc6d61ec4fd3bc2c440f9944e92b33a', address_info={'node_ip_address': '172.17.0.3', 'raylet_ip_address': '172.17.0.3', 'redis_address': None, 'object_store_address': '/tmp/ray/session_2023-04-19_15-01-21_178597_339730/sockets/plasma_store', 'raylet_socket_name': '/tmp/ray/session_2023-04-19_15-01-21_178597_339730/sockets/raylet', 'webui_url': '', 'session_dir': '/tmp/ray/session_2023-04-19_15-01-21_178597_339730', 'metrics_export_port': 54619, 'gcs_address': '172.17.0.3:41322', 'address': '172.17.0.3:41322', 'dashboard_agent_listen_port': 52365, 'node_id': '57bf2181b750b2a14b11cae95b0e7be64561e3a69a817a7c7645f4b1'})"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"execution_count": 10,
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"output_type": "execute_result"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"ray.init(num_gpus=1, \n",
|
|
|
|
|
|
|
|
" ignore_reinit_error=True,\n",
|
|
|
|
|
|
|
|
" resources={\"cpu\": 32, \"gpu\": 32} )"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "21977c0d-29ce-42f6-80c0-942654d5df51",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"@ray.remote(num_gpus=0.01)\n",
|
|
|
|
|
|
|
|
"def optimize(n_trials):\n",
|
|
|
|
|
|
|
|
" study = optuna.load_study(study_name='ray', storage=f'sqlite:///../results/hyperparameter_study_{window_size}.db')\n",
|
|
|
|
|
|
|
|
" study.optimize(objective, n_trials=n_trials)\n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
"results = []\n",
|
|
|
|
|
|
|
|
"for i in range(12):\n",
|
|
|
|
|
|
|
|
" time.sleep(1)\n",
|
|
|
|
|
|
|
|
" results.append(optimize.remote(1000)) \n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
"for i in range(10000):\n",
|
|
|
|
|
|
|
|
" time.sleep(2)\n",
|
|
|
|
|
|
|
|
" clear_output(wait=True)\n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
" \n",
|
|
|
|
|
|
|
|
"# [ray.get(x) for x in results] \n",
|
|
|
|
|
|
|
|
"# study.best_trial, study.best_params "
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 13,
|
|
|
|
|
|
|
|
"id": "35d60e56-1028-4428-a69d-d4e217efe11c",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
|
|
"text/plain": [
|
|
|
|
|
|
|
|
"(FrozenTrial(number=8316, state=TrialState.COMPLETE, values=[0.7329734219269103], datetime_start=datetime.datetime(2023, 4, 19, 17, 5, 3, 109691), datetime_complete=datetime.datetime(2023, 4, 19, 17, 5, 14, 306688), params={'harm_ampl_max': 0.05141408658277873, 'harm_ampl_min': 0.004216894373183093, 'noise_std_max': 0.04576914309029287, 'noise_std_min': 4.005219535133996e-05, 'step_ampl_max': 0.2241382196779908, 'step_ampl_min': 8.371016275499698e-05}, user_attrs={}, system_attrs={}, intermediate_values={}, distributions={'harm_ampl_max': FloatDistribution(high=0.1, log=False, low=0.005, step=None), 'harm_ampl_min': FloatDistribution(high=0.005, log=False, low=0.001, step=None), 'noise_std_max': FloatDistribution(high=0.1, log=False, low=0.0001, step=None), 'noise_std_min': FloatDistribution(high=0.0001, log=False, low=1e-06, step=None), 'step_ampl_max': FloatDistribution(high=0.8, log=False, low=0.0001, step=None), 'step_ampl_min': FloatDistribution(high=0.0001, log=False, low=1e-05, step=None)}, trial_id=8317, value=None),\n",
|
|
|
|
|
|
|
|
" {'harm_ampl_max': 0.05141408658277873,\n",
|
|
|
|
|
|
|
|
" 'harm_ampl_min': 0.004216894373183093,\n",
|
|
|
|
|
|
|
|
" 'noise_std_max': 0.04576914309029287,\n",
|
|
|
|
|
|
|
|
" 'noise_std_min': 4.005219535133996e-05,\n",
|
|
|
|
|
|
|
|
" 'step_ampl_max': 0.2241382196779908,\n",
|
|
|
|
|
|
|
|
" 'step_ampl_min': 8.371016275499698e-05})"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"execution_count": 13,
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"output_type": "execute_result"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"study.best_trial, study.best_params "
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 14,
|
|
|
|
|
|
|
|
"id": "a04877b4-defa-4730-b3ce-fa275e709ae7",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
|
|
"text/html": [
|
|
|
|
|
|
|
|
"<div>\n",
|
|
|
|
|
|
|
|
"<style scoped>\n",
|
|
|
|
|
|
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
|
|
|
|
|
|
|
" vertical-align: middle;\n",
|
|
|
|
|
|
|
|
" }\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
" .dataframe tbody tr th {\n",
|
|
|
|
|
|
|
|
" vertical-align: top;\n",
|
|
|
|
|
|
|
|
" }\n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
" .dataframe thead th {\n",
|
|
|
|
|
|
|
|
" text-align: right;\n",
|
|
|
|
|
|
|
|
" }\n",
|
|
|
|
|
|
|
|
"</style>\n",
|
|
|
|
|
|
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|
|
|
|
|
|
|
" <thead>\n",
|
|
|
|
|
|
|
|
" <tr style=\"text-align: right;\">\n",
|
|
|
|
|
|
|
|
" <th></th>\n",
|
|
|
|
|
|
|
|
" <th>harm_ampl_max</th>\n",
|
|
|
|
|
|
|
|
" <th>harm_ampl_min</th>\n",
|
|
|
|
|
|
|
|
" <th>noise_std_max</th>\n",
|
|
|
|
|
|
|
|
" <th>noise_std_min</th>\n",
|
|
|
|
|
|
|
|
" <th>step_ampl_max</th>\n",
|
|
|
|
|
|
|
|
" <th>step_ampl_min</th>\n",
|
|
|
|
|
|
|
|
" </tr>\n",
|
|
|
|
|
|
|
|
" </thead>\n",
|
|
|
|
|
|
|
|
" <tbody>\n",
|
|
|
|
|
|
|
|
" <tr>\n",
|
|
|
|
|
|
|
|
" <th>0</th>\n",
|
|
|
|
|
|
|
|
" <td>0.051414</td>\n",
|
|
|
|
|
|
|
|
" <td>0.004217</td>\n",
|
|
|
|
|
|
|
|
" <td>0.045769</td>\n",
|
|
|
|
|
|
|
|
" <td>0.00004</td>\n",
|
|
|
|
|
|
|
|
" <td>0.224138</td>\n",
|
|
|
|
|
|
|
|
" <td>0.000084</td>\n",
|
|
|
|
|
|
|
|
" </tr>\n",
|
|
|
|
|
|
|
|
" </tbody>\n",
|
|
|
|
|
|
|
|
"</table>\n",
|
|
|
|
|
|
|
|
"</div>"
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"text/plain": [
|
|
|
|
|
|
|
|
" harm_ampl_max harm_ampl_min noise_std_max noise_std_min step_ampl_max \\\n",
|
|
|
|
|
|
|
|
"0 0.051414 0.004217 0.045769 0.00004 0.224138 \n",
|
|
|
|
|
|
|
|
"\n",
|
|
|
|
|
|
|
|
" step_ampl_min \n",
|
|
|
|
|
|
|
|
"0 0.000084 "
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"execution_count": 14,
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"output_type": "execute_result"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"pd.DataFrame(data={k:[v] for k,v in study.best_params.items()})"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 15,
|
|
|
|
|
|
|
|
"id": "44564237-c95b-4e58-9646-b76059482cc9",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"data = {k:[v] for k,v in study.best_params.items()}\n",
|
|
|
|
|
|
|
|
"data['best_acc'] = study.best_trial.values\n",
|
|
|
|
|
|
|
|
"data['total_trials'] = 12*1000\n",
|
|
|
|
|
|
|
|
"pd.DataFrame(data=data).to_csv(f\"../results/{window_size}_synth_model_best_params.csv\", index=False)"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "4042fb3d-7cda-4fa4-b333-fa31122e1661",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"# 'noise_std_min': 9.502179883627595e-05,\n",
|
|
|
|
|
|
|
|
"# 'noise_std_max': 0.0018858019888194724,\n",
|
|
|
|
|
|
|
|
"# 'noise_std_stp': 6.643190903827471e-05,\n",
|
|
|
|
|
|
|
|
"# 'harm_ampl_min': 0.0038549419185346817,\n",
|
|
|
|
|
|
|
|
"# 'harm_ampl_max': 0.005978867746555492,\n",
|
|
|
|
|
|
|
|
"# 'harm_ampl_step': 0.0006277917832562148,\n",
|
|
|
|
|
|
|
|
"# 'probability_steps': 0.035397264960945196,\n",
|
|
|
|
|
|
|
|
"# 'step_ampl_min': 0.004726791192229224,\n",
|
|
|
|
|
|
|
|
"# 'step_ampl_max': 0.17299860153013677}"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": 12,
|
|
|
|
|
|
|
|
"id": "d1e416f5-6724-4b33-bc07-7d3dfa1c32da",
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"tags": []
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"outputs": [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"data": {
|
|
|
|
|
|
|
|
"text/plain": [
|
|
|
|
|
|
|
|
"[None, None, None, None, None, None, None, None, None, None, None, None]"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"execution_count": 12,
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"output_type": "execute_result"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"source": [
|
|
|
|
|
|
|
|
"[ray.cancel(a) for a in results]"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
|
|
|
"id": "04220a72-0917-4306-9ab8-b2783dbf44ad",
|
|
|
|
|
|
|
|
"metadata": {},
|
|
|
|
|
|
|
|
"outputs": [],
|
|
|
|
|
|
|
|
"source": []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
"metadata": {
|
|
|
|
|
|
|
|
"kernelspec": {
|
|
|
|
|
|
|
|
"display_name": "Python 3 (ipykernel)",
|
|
|
|
|
|
|
|
"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.6"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"nbformat": 4,
|
|
|
|
|
|
|
|
"nbformat_minor": 5
|
|
|
|
|
|
|
|
}
|