Skip to content

Commit 6a095a4

Browse files
0.21.2
1 parent f7311f7 commit 6a095a4

11 files changed

Lines changed: 925 additions & 406 deletions

File tree

RELEASE_NOTES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
spotpython 0.21.2:
2+
3+
- pytests added
4+
- spot.py:
5+
- removed method print_results_old()
6+
- update.py and cifar10datamodule.py removed
7+
18
spotpython 0.20.2:
29

310
- lightdatamodule handles data_val

notebooks/00_spotPython_tests.ipynb

Lines changed: 258 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,7 +6928,7 @@
69286928
" - c = l1 * _L_in\n",
69296929
"\n",
69306930
" Examples:\n",
6931-
" >>> from spotpython.hyperparameters.architecture import get_three_layers\n",
6931+
" from spotpython.hyperparameters.architecture import get_three_layers\n",
69326932
" _L_in = 10\n",
69336933
" l1 = 20\n",
69346934
" get_three_layers(_L_in, l1)\n",
@@ -6942,35 +6942,275 @@
69426942
},
69436943
{
69446944
"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,
69467135
"metadata": {},
69477136
"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+
},
69487156
{
69497157
"data": {
69507158
"text/plain": [
6951-
"[240, 160, 240, 160, 160, 40, 40]"
7159+
"<spotpython.spot.spot.Spot at 0x177589760>"
69527160
]
69537161
},
6954-
"execution_count": 4,
7162+
"execution_count": 1,
69557163
"metadata": {},
69567164
"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-
]
69687165
}
69697166
],
69707167
"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()"
69747214
]
69757215
},
69767216
{

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.20.4"
10+
version = "0.21.2"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/hyperparameters/architecture.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from math import ceil
22

3+
34
def generate_div2_list(input_size, n_min, max_repeats=2) -> list:
45
"""
56
Generates a list of integers starting from `n` and repeatedly dividing by 2 until `n_min` is reached.
@@ -107,5 +108,5 @@ def get_three_layers(_L_in, l1) -> list:
107108
"""
108109
a = 2 * l1 * _L_in
109110
b = l1 * _L_in
110-
c = ceil(l1/2) * _L_in
111-
return [a, b, a, b, b, c, c]
111+
c = ceil(l1 / 2) * _L_in
112+
return [a, b, a, b, b, c, c]

0 commit comments

Comments
 (0)