|
6928 | 6928 | " - c = l1 * _L_in\n", |
6929 | 6929 | "\n", |
6930 | 6930 | " Examples:\n", |
6931 | | - " >>> from spotpython.hyperparameters.architecture import get_three_layers\n", |
| 6931 | + " from spotpython.hyperparameters.architecture import get_three_layers\n", |
6932 | 6932 | " _L_in = 10\n", |
6933 | 6933 | " l1 = 20\n", |
6934 | 6934 | " get_three_layers(_L_in, l1)\n", |
|
6942 | 6942 | }, |
6943 | 6943 | { |
6944 | 6944 | "cell_type": "code", |
6945 | | - "execution_count": 4, |
| 6945 | + "execution_count": null, |
| 6946 | + "metadata": {}, |
| 6947 | + "outputs": [], |
| 6948 | + "source": [ |
| 6949 | + "_L_in = 20\n", |
| 6950 | + "l1 = 4\n", |
| 6951 | + "get_three_layers(_L_in, l1)" |
| 6952 | + ] |
| 6953 | + }, |
| 6954 | + { |
| 6955 | + "cell_type": "markdown", |
| 6956 | + "metadata": {}, |
| 6957 | + "source": [ |
| 6958 | + "# Tests for 0.20.5" |
| 6959 | + ] |
| 6960 | + }, |
| 6961 | + { |
| 6962 | + "cell_type": "markdown", |
| 6963 | + "metadata": {}, |
| 6964 | + "source": [ |
| 6965 | + "## get_spot_attributes_as_df()" |
| 6966 | + ] |
| 6967 | + }, |
| 6968 | + { |
| 6969 | + "cell_type": "code", |
| 6970 | + "execution_count": null, |
| 6971 | + "metadata": {}, |
| 6972 | + "outputs": [], |
| 6973 | + "source": [ |
| 6974 | + "import numpy as np\n", |
| 6975 | + "from math import inf\n", |
| 6976 | + "from spotpython.fun.objectivefunctions import Analytical\n", |
| 6977 | + "from spotpython.spot import spot\n", |
| 6978 | + "from spotpython.utils.init import (\n", |
| 6979 | + " fun_control_init, design_control_init\n", |
| 6980 | + " )\n", |
| 6981 | + "# number of initial points:\n", |
| 6982 | + "ni = 7\n", |
| 6983 | + "# number of points\n", |
| 6984 | + "n = 10\n", |
| 6985 | + "fun = Analytical().fun_sphere\n", |
| 6986 | + "fun_control = fun_control_init(\n", |
| 6987 | + " lower = np.array([-1]),\n", |
| 6988 | + " upper = np.array([1]),\n", |
| 6989 | + " fun_evals=n)\n", |
| 6990 | + "design_control=design_control_init(init_size=ni)\n", |
| 6991 | + "spot_1 = spot.Spot(fun=fun,\n", |
| 6992 | + " fun_control=fun_control,\n", |
| 6993 | + " design_control=design_control,)\n", |
| 6994 | + "spot_1.run()\n", |
| 6995 | + "df = spot_1.get_spot_attributes_as_df()\n", |
| 6996 | + "df[\"Attribute Name\"].to_list()" |
| 6997 | + ] |
| 6998 | + }, |
| 6999 | + { |
| 7000 | + "cell_type": "markdown", |
| 7001 | + "metadata": {}, |
| 7002 | + "source": [ |
| 7003 | + "## to_red_dim()" |
| 7004 | + ] |
| 7005 | + }, |
| 7006 | + { |
| 7007 | + "cell_type": "code", |
| 7008 | + "execution_count": null, |
| 7009 | + "metadata": {}, |
| 7010 | + "outputs": [], |
| 7011 | + "source": [ |
| 7012 | + "import numpy as np\n", |
| 7013 | + "from spotpython.fun.objectivefunctions import Analytical\n", |
| 7014 | + "from spotpython.spot import spot\n", |
| 7015 | + "from spotpython.utils.init import (\n", |
| 7016 | + " fun_control_init, design_control_init\n", |
| 7017 | + " )\n", |
| 7018 | + "# number of initial points:\n", |
| 7019 | + "ni = 3\n", |
| 7020 | + "# number of points\n", |
| 7021 | + "n = 10\n", |
| 7022 | + "fun = Analytical().fun_sphere\n", |
| 7023 | + "fun_control = fun_control_init(\n", |
| 7024 | + " lower = np.array([-1, -1]),\n", |
| 7025 | + " upper = np.array([1, 1]),\n", |
| 7026 | + " fun_evals = n)\n", |
| 7027 | + "design_control=design_control_init(init_size=ni)\n", |
| 7028 | + "spot_1 = spot.Spot(fun=fun,\n", |
| 7029 | + " fun_control=fun_control,\n", |
| 7030 | + " design_control=design_control,)\n", |
| 7031 | + "spot_1.run()\n", |
| 7032 | + "assert spot_1.lower.size == 2\n", |
| 7033 | + "assert spot_1.upper.size == 2\n", |
| 7034 | + "assert len(spot_1.var_type) == 2\n", |
| 7035 | + "assert spot_1.red_dim == False\n", |
| 7036 | + "spot_1.lower = np.array([-1, -1])\n", |
| 7037 | + "spot_1.upper = np.array([-1, -1])\n", |
| 7038 | + "spot_1.to_red_dim()\n", |
| 7039 | + "assert spot_1.lower.size == 0\n", |
| 7040 | + "assert spot_1.upper.size == 0\n", |
| 7041 | + "assert len(spot_1.var_type) == 0\n", |
| 7042 | + "assert spot_1.red_dim == True" |
| 7043 | + ] |
| 7044 | + }, |
| 7045 | + { |
| 7046 | + "cell_type": "markdown", |
| 7047 | + "metadata": {}, |
| 7048 | + "source": [ |
| 7049 | + "## to_all_dim()" |
| 7050 | + ] |
| 7051 | + }, |
| 7052 | + { |
| 7053 | + "cell_type": "code", |
| 7054 | + "execution_count": null, |
| 7055 | + "metadata": {}, |
| 7056 | + "outputs": [], |
| 7057 | + "source": [ |
| 7058 | + "import numpy as np\n", |
| 7059 | + "from spotpython.fun.objectivefunctions import Analytical\n", |
| 7060 | + "from spotpython.spot import spot\n", |
| 7061 | + "from spotpython.utils.init import fun_control_init, surrogate_control_init, design_control_init\n", |
| 7062 | + "lower = np.array([-1, -1, 0, 0])\n", |
| 7063 | + "upper = np.array([1, -1, 0, 5]) # Second and third dimensions are fixed\n", |
| 7064 | + "fun_evals = 10\n", |
| 7065 | + "var_type = ['float', 'int', 'float', 'int']\n", |
| 7066 | + "var_name = ['x1', 'x2', 'x3', 'x4']\n", |
| 7067 | + "spot_instance = spot.Spot(\n", |
| 7068 | + " fun = Analytical().fun_sphere, \n", |
| 7069 | + " fun_control=fun_control_init(lower=lower, upper=upper, fun_evals=fun_evals)\n", |
| 7070 | + ")\n", |
| 7071 | + "X0 = np.array([[2.5, 3.5], [4.5, 5.5]])\n", |
| 7072 | + "X_full_dim = spot_instance.to_all_dim(X0)\n", |
| 7073 | + "print(X_full_dim)" |
| 7074 | + ] |
| 7075 | + }, |
| 7076 | + { |
| 7077 | + "cell_type": "markdown", |
| 7078 | + "metadata": {}, |
| 7079 | + "source": [ |
| 7080 | + "## get_new_X0()" |
| 7081 | + ] |
| 7082 | + }, |
| 7083 | + { |
| 7084 | + "cell_type": "code", |
| 7085 | + "execution_count": null, |
| 7086 | + "metadata": {}, |
| 7087 | + "outputs": [], |
| 7088 | + "source": [ |
| 7089 | + "import numpy as np\n", |
| 7090 | + "from spotpython.fun.objectivefunctions import Analytical\n", |
| 7091 | + "from spotpython.utils.init import (\n", |
| 7092 | + " fun_control_init, design_control_init\n", |
| 7093 | + " )\n", |
| 7094 | + "from spotpython.spot import spot\n", |
| 7095 | + "from spotpython.utils.init import fun_control_init\n", |
| 7096 | + "# number of initial points:\n", |
| 7097 | + "ni = 3\n", |
| 7098 | + "X_start = np.array([[0, 1], [1, 0], [1, 1], [1, 1]])\n", |
| 7099 | + "fun = Analytical().fun_sphere\n", |
| 7100 | + "fun_control = fun_control_init(\n", |
| 7101 | + " n_points=10,\n", |
| 7102 | + " ocba_delta=0,\n", |
| 7103 | + " lower = np.array([-1, -1]),\n", |
| 7104 | + " upper = np.array([1, 1])\n", |
| 7105 | + ")\n", |
| 7106 | + "design_control=design_control_init(init_size=ni)\n", |
| 7107 | + "S = spot.Spot(fun=fun,\n", |
| 7108 | + " fun_control=fun_control,\n", |
| 7109 | + " design_control=design_control,\n", |
| 7110 | + ")\n", |
| 7111 | + "S.initialize_design(X_start=X_start)\n", |
| 7112 | + "S.update_stats()\n", |
| 7113 | + "S.fit_surrogate()\n", |
| 7114 | + "X0 = S.get_new_X0()\n", |
| 7115 | + "assert X0.shape[0] == S.n_points\n", |
| 7116 | + "assert X0.shape[1] == S.lower.size\n", |
| 7117 | + "# assert new points are in the interval [lower, upper]\n", |
| 7118 | + "assert np.all(X0 >= S.lower)\n", |
| 7119 | + "assert np.all(X0 <= S.upper)\n", |
| 7120 | + "# print using 20 digits precision\n", |
| 7121 | + "np.set_printoptions(precision=20)\n", |
| 7122 | + "print(f\"X0: {X0}\")" |
| 7123 | + ] |
| 7124 | + }, |
| 7125 | + { |
| 7126 | + "cell_type": "markdown", |
| 7127 | + "metadata": {}, |
| 7128 | + "source": [ |
| 7129 | + "## run()" |
| 7130 | + ] |
| 7131 | + }, |
| 7132 | + { |
| 7133 | + "cell_type": "code", |
| 7134 | + "execution_count": 1, |
6946 | 7135 | "metadata": {}, |
6947 | 7136 | "outputs": [ |
| 7137 | + { |
| 7138 | + "name": "stderr", |
| 7139 | + "output_type": "stream", |
| 7140 | + "text": [ |
| 7141 | + "Seed set to 123\n", |
| 7142 | + "Seed set to 123\n" |
| 7143 | + ] |
| 7144 | + }, |
| 7145 | + { |
| 7146 | + "name": "stdout", |
| 7147 | + "output_type": "stream", |
| 7148 | + "text": [ |
| 7149 | + "spotpython tuning: 0.0 [########--] 80.00% \n", |
| 7150 | + "spotpython tuning: 0.0 [#########-] 86.67% \n", |
| 7151 | + "spotpython tuning: 0.0 [#########-] 93.33% \n", |
| 7152 | + "spotpython tuning: 0.0 [##########] 100.00% Done...\n", |
| 7153 | + "\n" |
| 7154 | + ] |
| 7155 | + }, |
6948 | 7156 | { |
6949 | 7157 | "data": { |
6950 | 7158 | "text/plain": [ |
6951 | | - "[240, 160, 240, 160, 160, 40, 40]" |
| 7159 | + "<spotpython.spot.spot.Spot at 0x177589760>" |
6952 | 7160 | ] |
6953 | 7161 | }, |
6954 | | - "execution_count": 4, |
| 7162 | + "execution_count": 1, |
6955 | 7163 | "metadata": {}, |
6956 | 7164 | "output_type": "execute_result" |
6957 | | - }, |
6958 | | - { |
6959 | | - "ename": "", |
6960 | | - "evalue": "", |
6961 | | - "output_type": "error", |
6962 | | - "traceback": [ |
6963 | | - "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n", |
6964 | | - "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n", |
6965 | | - "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n", |
6966 | | - "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details." |
6967 | | - ] |
6968 | 7165 | } |
6969 | 7166 | ], |
6970 | 7167 | "source": [ |
6971 | | - "_L_in = 20\n", |
6972 | | - "l1 = 4\n", |
6973 | | - "get_three_layers(_L_in, l1)" |
| 7168 | + "import numpy as np\n", |
| 7169 | + "from spotpython import Analytical\n", |
| 7170 | + "from spotpython import Spot\n", |
| 7171 | + "from spotpython.utils.init import (\n", |
| 7172 | + " fun_control_init, design_control_init\n", |
| 7173 | + " )\n", |
| 7174 | + "# number of initial points:\n", |
| 7175 | + "ni = 7\n", |
| 7176 | + "# start point X_0\n", |
| 7177 | + "X_start = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])\n", |
| 7178 | + "fun = Analytical().fun_sphere\n", |
| 7179 | + "fun_control = fun_control_init(\n", |
| 7180 | + " lower = np.array([-1, -1]),\n", |
| 7181 | + " upper = np.array([1, 1]))\n", |
| 7182 | + "design_control=design_control_init(init_size=ni)\n", |
| 7183 | + "S = Spot(fun=fun,\n", |
| 7184 | + " fun_control=fun_control,\n", |
| 7185 | + " design_control=design_control,)\n", |
| 7186 | + "S.run(X_start=X_start)" |
| 7187 | + ] |
| 7188 | + }, |
| 7189 | + { |
| 7190 | + "cell_type": "code", |
| 7191 | + "execution_count": null, |
| 7192 | + "metadata": {}, |
| 7193 | + "outputs": [], |
| 7194 | + "source": [ |
| 7195 | + "S.X" |
| 7196 | + ] |
| 7197 | + }, |
| 7198 | + { |
| 7199 | + "cell_type": "code", |
| 7200 | + "execution_count": null, |
| 7201 | + "metadata": {}, |
| 7202 | + "outputs": [], |
| 7203 | + "source": [ |
| 7204 | + "S.y" |
| 7205 | + ] |
| 7206 | + }, |
| 7207 | + { |
| 7208 | + "cell_type": "code", |
| 7209 | + "execution_count": null, |
| 7210 | + "metadata": {}, |
| 7211 | + "outputs": [], |
| 7212 | + "source": [ |
| 7213 | + "S.print_results()" |
6974 | 7214 | ] |
6975 | 7215 | }, |
6976 | 7216 | { |
|
0 commit comments