{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:04:23.868989Z", "start_time": "2020-12-04T07:04:22.919278Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import physbo" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:04:23.873360Z", "start_time": "2020-12-04T07:04:23.870570Z" } }, "outputs": [], "source": [ "def load_data():\n", " A = np.asarray(np.loadtxt(\"data/s5-210.csv\", skiprows=1, delimiter=\",\"))\n", " X = A[:, 0:3]\n", " t = -A[:, 3]\n", " return X, t" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:04:23.991615Z", "start_time": "2020-12-04T07:04:23.877046Z" } }, "outputs": [], "source": [ "# Load the data.\n", "# X is the N x d dimensional matrix. Each row of X denotes the d-dimensional feature vector of search candidate.\n", "# t is the N-dimensional vector that represents the corresponding negative energy of search candidates.\n", "# ( It is of course unknown in practice. )\n", "X, t = load_data()\n", "\n", "# Normalize the mean and standard deviation along the each column of X to 0 and 1, respectively\n", "X = physbo.misc.centering(X)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:04:23.995316Z", "start_time": "2020-12-04T07:04:23.992854Z" } }, "outputs": [], "source": [ "# Declare the class for calling the simulator.\n", "# In this tutorial, we simply refer to the value of t.\n", "# If you want to apply physbo to other problems, you have to customize this class.\n", "class simulator:\n", " def __init__(self):\n", " _, self.t = load_data()\n", "\n", " def __call__(self, action):\n", " return self.t[action]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:04:23.999352Z", "start_time": "2020-12-04T07:04:23.996511Z" } }, "outputs": [], "source": [ "# Design of policy\n", "\n", "# Declaring the policy by\n", "policy = physbo.search.discrete.policy(test_X=X)\n", "# test_X is the set of candidates which is represented by numpy.array.\n", "# Each row vector represents the feature vector of the corresponding candidate\n", "\n", "# set the seed parameter\n", "policy.set_seed(0)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:05:30.829655Z", "start_time": "2020-12-04T07:04:24.000442Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0001-th step: f(x) = -1.070602 (action=15673)\n", " current best f(x) = -1.070602 (best action=15673) \n", "\n", "0002-th step: f(x) = -1.153410 (action=16489)\n", " current best f(x) = -1.070602 (best action=15673) \n", "\n", "0003-th step: f(x) = -0.981899 (action=7792)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0004-th step: f(x) = -1.066080 (action=13752)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0005-th step: f(x) = -1.043272 (action=9023)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0006-th step: f(x) = -1.125822 (action=1470)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0007-th step: f(x) = -1.070720 (action=14404)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0008-th step: f(x) = -1.091624 (action=14031)\n", " current best f(x) = -0.981899 (best action=7792) \n", "\n", "0009-th step: f(x) = -0.963795 (action=5734)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0010-th step: f(x) = -0.989538 (action=3111)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0011-th step: f(x) = -1.135007 (action=1192)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0012-th step: f(x) = -1.003954 (action=8912)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0013-th step: f(x) = -0.994601 (action=1941)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0014-th step: f(x) = -0.971108 (action=4051)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0015-th step: f(x) = -1.096091 (action=14468)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0016-th step: f(x) = -0.982784 (action=8562)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0017-th step: f(x) = -1.052590 (action=16185)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0018-th step: f(x) = -1.079737 (action=17654)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0019-th step: f(x) = -1.025116 (action=4470)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0020-th step: f(x) = -1.048733 (action=1022)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "Start the initial hyper parameter searching ...\n", "Done\n", "\n", "Start the hyper parameter learning ...\n", "0 -th epoch marginal likelihood -26.92509954754724\n", "50 -th epoch marginal likelihood -28.116900149263117\n", "100 -th epoch marginal likelihood -28.7170482808381\n", "150 -th epoch marginal likelihood -29.03724064450991\n", "200 -th epoch marginal likelihood -29.243814308007238\n", "250 -th epoch marginal likelihood -29.404990527484884\n", "300 -th epoch marginal likelihood -29.543375062782726\n", "350 -th epoch marginal likelihood -29.66433788563113\n", "400 -th epoch marginal likelihood -29.768631164012973\n", "450 -th epoch marginal likelihood -29.85669678455538\n", "500 -th epoch marginal likelihood -29.929612908422673\n", "Done\n", "\n", "0021-th step: f(x) = -1.163543 (action=15502)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0022-th step: f(x) = -1.115291 (action=5468)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0023-th step: f(x) = -1.209434 (action=17785)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0024-th step: f(x) = -1.052777 (action=2744)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0025-th step: f(x) = -1.069404 (action=15133)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0026-th step: f(x) = -1.005694 (action=2996)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0027-th step: f(x) = -1.280940 (action=12010)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0028-th step: f(x) = -1.040693 (action=7092)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0029-th step: f(x) = -0.969117 (action=8879)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0030-th step: f(x) = -1.056882 (action=9663)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0031-th step: f(x) = -0.978277 (action=7732)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0032-th step: f(x) = -0.992851 (action=368)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0033-th step: f(x) = -1.046641 (action=6511)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0034-th step: f(x) = -1.063484 (action=7559)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0035-th step: f(x) = -2.716337 (action=8991)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0036-th step: f(x) = -1.064335 (action=9924)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0037-th step: f(x) = -1.009942 (action=114)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0038-th step: f(x) = -1.132489 (action=15657)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0039-th step: f(x) = -1.052640 (action=11273)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0040-th step: f(x) = -1.029932 (action=8153)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "Start the initial hyper parameter searching ...\n", "Done\n", "\n", "Start the hyper parameter learning ...\n", "0 -th epoch marginal likelihood 57.27443995742372\n", "50 -th epoch marginal likelihood 39.61996417095699\n", "100 -th epoch marginal likelihood 28.75843642947389\n", "150 -th epoch marginal likelihood 21.904482272567265\n", "200 -th epoch marginal likelihood 17.37533326894912\n", "250 -th epoch marginal likelihood 14.2779779855206\n", "300 -th epoch marginal likelihood 12.105710146208324\n", "350 -th epoch marginal likelihood 10.550790094511335\n", "400 -th epoch marginal likelihood 9.41741995795864\n", "450 -th epoch marginal likelihood 8.576755872035882\n", "500 -th epoch marginal likelihood 7.941737514349171\n", "Done\n", "\n", "0041-th step: f(x) = -0.986440 (action=6997)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0042-th step: f(x) = -0.991094 (action=3048)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0043-th step: f(x) = -1.146469 (action=28)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0044-th step: f(x) = -1.474650 (action=14994)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0045-th step: f(x) = -1.040936 (action=6486)\n", " current best f(x) = -0.963795 (best action=5734) \n", "\n", "0046-th step: f(x) = -0.957557 (action=8658)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0047-th step: f(x) = -0.990559 (action=1554)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0048-th step: f(x) = -1.112963 (action=16435)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0049-th step: f(x) = -0.996640 (action=2980)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0050-th step: f(x) = -0.983457 (action=11972)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0051-th step: f(x) = -2.497145 (action=17981)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0052-th step: f(x) = -1.046715 (action=17963)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0053-th step: f(x) = -1.034998 (action=8965)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0054-th step: f(x) = -1.121553 (action=3543)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0055-th step: f(x) = -0.970354 (action=5071)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0056-th step: f(x) = -1.000414 (action=13504)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0057-th step: f(x) = -1.105581 (action=3450)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0058-th step: f(x) = -1.157715 (action=17034)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0059-th step: f(x) = -1.195993 (action=6014)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0060-th step: f(x) = -1.008763 (action=13357)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "Start the initial hyper parameter searching ...\n", "Done\n", "\n", "Start the hyper parameter learning ...\n", "0 -th epoch marginal likelihood 95.64584307596252\n", "50 -th epoch marginal likelihood 66.35048123357063\n", "100 -th epoch marginal likelihood 47.31866223555388\n", "150 -th epoch marginal likelihood 34.99052624000419\n", "200 -th epoch marginal likelihood 26.852103068210674\n", "250 -th epoch marginal likelihood 21.378391902446452\n", "300 -th epoch marginal likelihood 17.634634928059192\n", "350 -th epoch marginal likelihood 15.037465120793513\n", "400 -th epoch marginal likelihood 13.214200445071874\n", "450 -th epoch marginal likelihood 11.92081527956428\n", "500 -th epoch marginal likelihood 10.994026735196492\n", "Done\n", "\n", "0061-th step: f(x) = -1.042869 (action=10245)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0062-th step: f(x) = -1.091613 (action=5966)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0063-th step: f(x) = -1.152803 (action=1859)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "0064-th step: f(x) = -0.997708 (action=3033)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0065-th step: f(x) = -1.071346 (action=12024)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0066-th step: f(x) = -0.996107 (action=4218)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0067-th step: f(x) = -0.996148 (action=4254)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0068-th step: f(x) = -2.497328 (action=17945)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0069-th step: f(x) = -1.144047 (action=13010)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0070-th step: f(x) = -1.051960 (action=17059)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0071-th step: f(x) = -1.181294 (action=17398)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0072-th step: f(x) = -0.994355 (action=2886)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0073-th step: f(x) = -0.968925 (action=4681)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0074-th step: f(x) = -0.972985 (action=11027)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0075-th step: f(x) = -0.963759 (action=5698)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0076-th step: f(x) = -0.964398 (action=5975)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0077-th step: f(x) = -1.018063 (action=2974)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0078-th step: f(x) = -0.992400 (action=740)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0079-th step: f(x) = -1.020451 (action=5989)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0080-th step: f(x) = -1.074223 (action=2804)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "Start the initial hyper parameter searching ...\n", "Done\n", "\n", "Start the hyper parameter learning ...\n", "0 -th epoch marginal likelihood 171.03306059563727\n", "50 -th epoch marginal likelihood 127.11391202528407\n", "100 -th epoch marginal likelihood 97.86972980514525\n", "150 -th epoch marginal likelihood 76.72198878519796\n", "200 -th epoch marginal likelihood 63.66870436920041\n", "250 -th epoch marginal likelihood 54.3007049773918\n", "300 -th epoch marginal likelihood 45.57502605325236\n", "350 -th epoch marginal likelihood 39.54814143645811\n", "400 -th epoch marginal likelihood 35.48162280619671\n", "450 -th epoch marginal likelihood 32.44895962894607\n", "500 -th epoch marginal likelihood 30.243937817044753\n", "Done\n", "\n", "0081-th step: f(x) = -1.062190 (action=15725)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0082-th step: f(x) = -1.008143 (action=6030)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0083-th step: f(x) = -0.997863 (action=2536)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0084-th step: f(x) = -1.013053 (action=36)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0085-th step: f(x) = -1.052591 (action=8980)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0086-th step: f(x) = -1.052411 (action=14960)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0087-th step: f(x) = -0.972223 (action=11135)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0088-th step: f(x) = -1.011104 (action=11359)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0089-th step: f(x) = -0.995949 (action=2294)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0090-th step: f(x) = -1.013012 (action=0)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0091-th step: f(x) = -1.035765 (action=4537)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0092-th step: f(x) = -0.968059 (action=8287)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0093-th step: f(x) = -1.136152 (action=16238)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0094-th step: f(x) = -1.554029 (action=15014)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0095-th step: f(x) = -1.009086 (action=13949)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0096-th step: f(x) = -0.964418 (action=5068)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0097-th step: f(x) = -0.992852 (action=7807)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0098-th step: f(x) = -1.276674 (action=6006)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0099-th step: f(x) = -1.053327 (action=11364)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n", "0100-th step: f(x) = -1.014598 (action=12764)\n", " current best f(x) = -0.957557 (best action=8658) \n", "\n" ] } ], "source": [ "# If you want to perform the initial random search before starting the Bayesian optimization,\n", "# the random sampling is performed by\n", "\n", "res = policy.random_search(max_num_probes=20, simulator=simulator())\n", "# Input:\n", "# max_num_probes: number of random search\n", "# simulator = simulator\n", "# output: physbo.search.discreate.results (class)\n", "\n", "\n", "# single query Bayesian search\n", "# The single query version of COMBO is performed by\n", "res = policy.bayes_search(\n", " max_num_probes=80,\n", " simulator=simulator(),\n", " score=\"TS\",\n", " interval=20,\n", " num_rand_basis=5000,\n", ")\n", "\n", "# Input\n", "# max_num_probes: number of searching by Bayesian optimization\n", "# simulator: the class of simulator which is defined above\n", "# score: the type of aquision funciton. TS, EI and PI are available\n", "# interval: the timing for learning the hyper parameter.\n", "# In this case, the hyper parameter is learned at each 20 steps\n", "# If you set the negative value to interval, the hyper parameter learning is not performed\n", "# If you set zero to interval, the hyper parameter learning is performed only at the first step\n", "# num_rand_basis: the number of basis function. If you choose 0, ordinary Gaussian process runs" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:05:30.850232Z", "start_time": "2020-12-04T07:05:30.831607Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "f(x)= [-1.07060214 -1.15340978 -0.98189856 -1.0660804 -1.04327156 -1.12582192\n", " -1.07071983 -1.09162401 -0.96379539 -0.98953771 -1.13500669 -1.00395435\n", " -0.99460129 -0.97110762 -1.09609145 -0.98278381 -1.05258966 -1.07973688\n", " -1.02511608 -1.04873284 -1.16354262 -1.1152908 -1.20943435 -1.05277671\n", " -1.06940391 -1.00569357 -1.2809399 -1.04069258 -0.96911653 -1.05688198\n", " -0.97827713 -0.99285126 -1.04664055 -1.06348437 -2.71633654 -1.06433493\n", " -1.00994212 -1.13248855 -1.05263969 -1.02993177 -0.98644049 -0.99109357\n", " -1.14646882 -1.47465017 -1.04093649 -0.95755746 -0.99055856 -1.11296313\n", " -0.99663985 -0.98345726 -2.4971452 -1.04671475 -1.03499762 -1.12155347\n", " -0.97035371 -1.00041394 -1.10558125 -1.15771547 -1.19599307 -1.0087635\n", " -1.0428693 -1.09161349 -1.15280256 -0.99770846 -1.07134639 -0.9961074\n", " -0.99614833 -2.49732771 -1.14404676 -1.05195998 -1.18129385 -0.99435453\n", " -0.96892464 -0.97298528 -0.96375929 -0.96439778 -1.0180634 -0.99239983\n", " -1.02045078 -1.07422272 -1.06219033 -1.00814263 -0.99786253 -1.0130527\n", " -1.05259136 -1.05241056 -0.97222313 -1.01110425 -0.99594877 -1.01301176\n", " -1.03576489 -0.96805929 -1.13615205 -1.55402855 -1.00908644 -0.96441796\n", " -0.9928524 -1.27667372 -1.05332708 -1.01459832]\n", "current best [-1.07060214 -1.07060214 -0.98189856 -0.98189856 -0.98189856 -0.98189856\n", " -0.98189856 -0.98189856 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539 -0.96379539\n", " -0.96379539 -0.96379539 -0.96379539 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746 -0.95755746\n", " -0.95755746 -0.95755746 -0.95755746 -0.95755746]\n", "current best action= [15673. 15673. 7792. 7792. 7792. 7792. 7792. 7792. 5734. 5734.\n", " 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734.\n", " 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734.\n", " 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734. 5734.\n", " 5734. 5734. 5734. 5734. 5734. 8658. 8658. 8658. 8658. 8658.\n", " 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658.\n", " 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658.\n", " 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658.\n", " 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658.\n", " 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658. 8658.]\n", "history of chosen actions= [15673 16489 7792 13752 9023 1470 14404 14031 5734 3111 1192 8912\n", " 1941 4051 14468 8562 16185 17654 4470 1022 15502 5468 17785 2744\n", " 15133 2996 12010 7092 8879 9663 7732 368 6511 7559 8991 9924\n", " 114 15657 11273 8153 6997 3048 28 14994 6486 8658 1554 16435\n", " 2980 11972 17981 17963 8965 3543 5071 13504 3450 17034 6014 13357\n", " 10245 5966 1859 3033 12024 4218 4254 17945 13010 17059 17398 2886\n", " 4681 11027 5698 5975 2974 740 5989 2804 15725 6030 2536 36\n", " 8980 14960 11135 11359 2294 0 4537 8287 16238 15014 13949 5068\n", " 7807 6006 11364 12764]\n" ] } ], "source": [ "# The result of searching is summarized in the class physbo.search.discrete.results.history()\n", "# res.fx: observed negative energy at each step\n", "# res.chosen_actions: history of choosed actions\n", "# fbest, best_action= res.export_all_sequence_best_fx(): current best fx and current best action\n", "# that has been observed until each step\n", "# res.total_num_search: total number of search\n", "print(\"f(x)=\", res.fx[0 : res.total_num_search])\n", "best_fx, best_action = res.export_all_sequence_best_fx()\n", "print(\"current best\", best_fx)\n", "print(\"current best action=\", best_action)\n", "print(\"history of chosen actions=\", res.chosen_actions[0 : res.total_num_search])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:05:30.860757Z", "start_time": "2020-12-04T07:05:30.851873Z" } }, "outputs": [], "source": [ "# save the results\n", "res.save(\"test.npz\")" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:05:30.867057Z", "start_time": "2020-12-04T07:05:30.862535Z" } }, "outputs": [], "source": [ "del res" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-12-04T07:05:30.876430Z", "start_time": "2020-12-04T07:05:30.869026Z" } }, "outputs": [], "source": [ "# load the results\n", "res = physbo.search.discrete.results.history()\n", "res.load(\"test.npz\")" ] }, { "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.8.5" } }, "nbformat": 4, "nbformat_minor": 1 }