Skip to content

Instantly share code, notes, and snippets.

@nzw0301
Created May 18, 2020 15:49
Show Gist options
  • Save nzw0301/f9eed6b38f6932b70ec9d7a3a5eee0dc to your computer and use it in GitHub Desktop.
Save nzw0301/f9eed6b38f6932b70ec9d7a3a5eee0dc to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparison between ConfigSpace's integer sampling in `log` space and new Optuna's `suggest_int(log=True)`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import ConfigSpace\n",
"import ConfigSpace as CS\n",
"import ConfigSpace.hyperparameters as CSH\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"low = 2\n",
"high = 64\n",
"step = 2\n",
"num_samples = 10_000"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"cs = CS.ConfigurationSpace(seed=1)\n",
"uniform_integer_hp = CSH.UniformIntegerHyperparameter(name='x', lower=low, upper=high, log=True, q=step)\n",
"cs.add_hyperparameter(uniform_integer_hp)\n",
"\n",
"\n",
"samples = [cs.sample_configuration().get('x') for _ in range(num_samples)]\n",
"samples = np.array(samples)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAO30lEQVR4nO3cb8zdZX3H8ffH1n/TzYLcGNI2uzE2G5hMIA3UsCwOHFQwlgeS1JjZmCZ90iWYmGjZkhH/kMATcWbThEh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uAK4l8EXHseqh7bOw8A5p9XG5vUE/B7wI9rFMOPUw9gc6TP9TzisXqK1LIS3VNWzAO3+3CVez0iSTAIXAw8zZj200yKPAUeBPcAPgOeq6mSbMg6vqc8CHwN+1cZvZvx6gME38f8lyb720yswXq+ntwLHgL9vp9q+mOQNjEEP4xT6c/6Eg86sJG8EvgF8pKp+ttTrma+qerGqLmJwtHwpcMF00xZ3VaNL8l7gaFXtGy5PM3XZ9jDk8qq6hMHp2u1J/mSpFzRPK4FLgC9U1cXA/7AcT+VMY5xC/5X2Ew4/SXIeQLs/usTrmVWSVzMI/K9W1Tdbeax6OKWqngMeYvD5xKokp76kuNxfU5cD70tymMEv1F7B4Mh/nHoAoKqeafdHgX9k8CY8Tq+nI8CRqnq4je9m8Caw7HsYp9B/pf2Ew25gS9vewuA8+bKUJMAdwIGq+szQrnHqYSLJqrb9euDdDD54exB4f5u2rHuoqhurak1VTTJ4/T9QVR9kjHoASPKGJL97ahu4CniCMXo9VdV/AU8n+YNWuhJ4knHoYak/VJjnhyfXAP/B4FzsXy31euax7q8BzwL/x+AIYSuDc7F7gYPt/uylXucs6/9jBqcMHgcea7drxqyHPwIebT08Afx1q78VeAQ4BPwD8NqlXuuI/bwLuHcce2jr/V677T/1b3mcXk9tvRcBU+019U/AWePQgz/DIEkdGafTO5Kkl8nQl6SOGPqS1BFDX5I6YuhLUkcMfUnqiKEvSR35f6R8oecCHf4FAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.hist(samples, bins=8);"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"assert np.sum(samples % 2) == 0 # no odd numebrs."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 0, 1826, 0, 1428, 0, 830, 0, 645, 0, 557,\n",
" 0, 493, 0, 388, 0, 318, 0, 295, 0, 285, 0,\n",
" 235, 0, 225, 0, 212, 0, 181, 0, 174, 0, 172,\n",
" 0, 137, 0, 153, 0, 138, 0, 144, 0, 139, 0,\n",
" 101, 0, 114, 0, 113, 0, 107, 0, 90, 0, 95,\n",
" 0, 75, 0, 90, 0, 99, 0, 87, 0, 54])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2, 4, 6, ..., 64 generated\n",
"np.bincount(samples)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Optuna"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import optuna\n",
"from optuna import samplers\n",
"from optuna.study import create_study\n",
"from optuna.trial import Trial\n",
"from optuna.distributions import IntLogUniformDistribution"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"sampler = samplers.RandomSampler(seed=1)\n",
"study = create_study(sampler=sampler)\n",
"distribuion = IntLogUniformDistribution(low=low, high=high, step=step)\n",
"\n",
"samples = []\n",
"for i in range(num_samples):\n",
" trial = Trial(study, study._storage.create_new_trial(study._study_id)) \n",
" \n",
" samples.append(trial._suggest(\"x\", distribuion))\n",
"\n",
"samples = np.array(samples)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD4CAYAAAAAczaOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAO30lEQVR4nO3cb8zdZX3H8ffH1n/TzYLcGNI2uzE2G5hMIA3UsCwOHFQwlgeS1JjZmCZ90iWYmGjZkhH/kMATcWbThEhnNUZk6EYDZqwpkGUPBO8KIqVjrdpJA7M1LThnZCt+9+BcNcd6/zk33L3v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IS3VNWzAO3+3CVez0iSTAIXAw8zZj200yKPAUeBPcAPgOeq6mSbMg6vqc8CHwN+1cZvZvx6gME38f8lyb720yswXq+ntwLHgL9vp9q+mOQNjEEP4xT6c/6Eg86sJG8EvgF8pKp+ttTrma+qerGqLmJwtHwpcMF00xZ3VaNL8l7gaFXtGy5PM3XZ9jDk8qq6hMHp2u1J/mSpFzRPK4FLgC9U1cXA/7AcT+VMY5xC/5X2Ew4/SXIeQLs/usTrmVWSVzMI/K9W1Tdbeax6OKWqngMeYvD5xKokp76kuNxfU5cD70tymMEv1F7B4Mh/nHoAoKqeafdHgX9k8CY8Tq+nI8CRqnq4je9m8Caw7HsYp9B/pf2Ew25gS9vewuA8+bKUJMAdwIGq+szQrnHqYSLJqrb9euDdDD54exB4f5u2rHuoqhurak1VTTJ4/T9QVR9kjHoASPKGJL97ahu4CniCMXo9VdV/AU8n+YNWuhJ4knHoYak/VJjnhyfXAP/B4FzsXy31euax7q8BzwL/x+AIYSuDc7F7gYPt/uylXucs6/9jBqcMHgcea7drxqyHPwIebT08Afx1q78VeAQ4BPwD8NqlXuuI/bwLuHcce2jr/V677T/1b3mcXk9tvRcBU+019U/AWePQgz/DIEkdGafTO5Kkl8nQl6SOGPqS1BFDX5I6YuhLUkcMfUnqiKEvSR35f6R8oecCHf4FAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.hist(samples, bins=8);"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"assert np.sum(samples % 2) == 0 # no odd numebrs."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 0, 1826, 0, 1428, 0, 830, 0, 645, 0, 557,\n",
" 0, 493, 0, 388, 0, 318, 0, 295, 0, 285, 0,\n",
" 235, 0, 225, 0, 212, 0, 181, 0, 174, 0, 172,\n",
" 0, 137, 0, 153, 0, 138, 0, 144, 0, 139, 0,\n",
" 101, 0, 114, 0, 113, 0, 107, 0, 90, 0, 95,\n",
" 0, 75, 0, 90, 0, 99, 0, 87, 0, 54])"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2, 4, 6, ..., 64 generated\n",
"np.bincount(samples)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"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.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment