{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-09-07T12:38:15.344220Z", "start_time": "2018-09-07T12:38:15.340982Z" } }, "outputs": [], "source": [ "# we will study the hyperparamter tuning of fully connected scatternet\n", "\n", "# first find optimal number of layers and neuron numbers\n", "# second optimize the batch size and number of epochs for the best learned architecture\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-09-08T12:01:25.348660Z", "start_time": "2018-09-08T12:01:25.309257Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The autoreload extension is already loaded. To reload it, use:\n", " %reload_ext autoreload\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/home/hegder/anaconda3/envs/deep/lib/python3.6/site-packages/ipyparallel/client/client.py:459: RuntimeWarning: \n", " Controller appears to be listening on localhost, but not on this machine.\n", " If this is true, you should specify Client(...,sshserver='you@Gamma')\n", " or instruct your controller to listen on an external IP.\n", " RuntimeWarning)\n" ] }, { "data": { "text/plain": [ "[0, 1, 2, 3]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%load_ext autoreload\n", "\n", "import ipyparallel as ipp\n", "rc = ipp.Client()\n", "rc.ids" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Loading the dataset here" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-09-08T12:09:06.191974Z", "start_time": "2018-09-08T12:09:05.681850Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[stdout:0] \n", "Dataset has been loaded\n", "x-train (44999, 8)\n", "x-test (55001, 8)\n", "y-train (44999, 256)\n", "y-test (55001, 256)\n", "[stdout:1] \n", "Dataset has been loaded\n", "x-train (44999, 8)\n", "x-test (55001, 8)\n", "y-train (44999, 256)\n", "y-test (55001, 256)\n", "[stdout:2] \n", "Dataset has been loaded\n", "x-train (44999, 8)\n", "x-test (55001, 8)\n", "y-train (44999, 256)\n", "y-test (55001, 256)\n", "[stdout:3] \n", "Dataset has been loaded\n", "x-train (44999, 8)\n", "x-test (55001, 8)\n", "y-train (44999, 256)\n", "y-test (55001, 256)\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "[stderr:0] \n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "[stderr:1] \n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "[stderr:2] \n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "[stderr:3] \n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n", "/home/hegder/anaconda3/envs/deep/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88\n", " return f(*args, **kwds)\n" ] } ], "source": [ "%%px\n", "\n", "import numpy as np\n", "\n", "import h5py\n", "from sklearn.model_selection import train_test_split\n", "\n", "#now load this dataset \n", "h5f = h5py.File('./datasets/s8_sio2tio2_v2.h5','r')\n", "X = h5f['sizes'][:]\n", "Y = h5f['spectrum'][:]\n", "\n", "#get the ranges of the loaded data\n", "num_layers = X.shape[1]\n", "num_lpoints = Y.shape[1]\n", "size_max = np.amax(X)\n", "size_min = np.amin(X)\n", "size_av = 0.5*(size_max + size_min)\n", "\n", "#this information is not given in the dataset\n", "lam_min = 300\n", "lam_max = 1200\n", "lams = np.linspace(lam_min, lam_max, num_lpoints)\n", "\n", "#create a train - test split of the dataset\n", "x_train, x_test, y_train, y_test = train_test_split(X, Y, test_size=0.55, random_state=42)\n", "\n", "# normalize inputs \n", "x_train = (x_train - 50)/20 \n", "x_test = (x_test - 50)/20 \n", "\n", "print(\"Dataset has been loaded\")\n", "print(\"x-train\", x_train.shape)\n", "print(\"x-test \", x_test.shape)\n", "print(\"y-train\", y_train.shape)\n", "print(\"y-test \", y_test.shape)\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### create models here" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-09-08T12:09:43.998716Z", "start_time": "2018-09-08T12:09:43.987026Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%%px --targets 0 --noblock\n", "\n", "%autoreload 2\n", "\n", "\n", "\n", "import hyptune as htun\n", "import scnets as scn\n", "\n", "import os\n", "os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\" \n", "os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\"\n", "\n", "# #resnet\n", "func = scn.resnet\n", "param_grid = dict(num_units=[2,3,4,5,6], \n", " red_dim=[8,16],\n", " batch_size=[32],\n", " ker_size=[3, 5, 7])\n", " \n", "cvresults = htun.get_cv_grid(modelfunc=func, \n", " param_grid=param_grid,\n", " num_epochs=250,\n", " x_train=x_train,\n", " y_train=y_train)\n", "\n", "htres = htun.print_tuning_results(cvresults, func)\n", "print(htres.to_string(index=False))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "ExecuteTime": { "end_time": "2018-09-08T11:24:51.887905Z", "start_time": "2018-09-08T11:24:51.878241Z" } }, "outputs": [], "source": [ "#%%px --targets 1 --noblock\n", "\n", "%autoreload 2\n", "\n", "\n", "import hyptune as htun\n", "import scnets as scn\n", "\n", "import os\n", "os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\" \n", "os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\"\n", "\n", "# #resnet\n", "func = scn.resnet\n", "param_grid = dict(num_units=[2,3,4,5,6], \n", " red_dim=[8,16],\n", " batch_size=[64],\n", " ker_size=[3, 5, 7])\n", " \n", "cvresults = htun.get_cv_grid(modelfunc=func, \n", " param_grid=param_grid,\n", " num_epochs=250,\n", " x_train=x_train,\n", " y_train=y_train)\n", "\n", "htres = htun.print_tuning_results(cvresults, func)\n", "print(htres.to_string(index=False))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.6" } }, "nbformat": 4, "nbformat_minor": 2 }