Skip to content

Commit f1a0d3b

Browse files
0.24.14
pytests kriging
1 parent 6b478cb commit f1a0d3b

10 files changed

Lines changed: 805 additions & 415 deletions

notebooks/00_spotPython_tests.ipynb

Lines changed: 204 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9199,18 +9199,9 @@
91999199
},
92009200
{
92019201
"cell_type": "code",
9202-
"execution_count": 2,
9202+
"execution_count": null,
92039203
"metadata": {},
9204-
"outputs": [
9205-
{
9206-
"name": "stdout",
9207-
"output_type": "stream",
9208-
"text": [
9209-
"(3, 3)\n",
9210-
"3\n"
9211-
]
9212-
}
9213-
],
9204+
"outputs": [],
92149205
"source": [
92159206
"from spotpython.build import Kriging\n",
92169207
"import numpy as np\n",
@@ -9237,17 +9228,9 @@
92379228
},
92389229
{
92399230
"cell_type": "code",
9240-
"execution_count": 8,
9231+
"execution_count": null,
92419232
"metadata": {},
9242-
"outputs": [
9243-
{
9244-
"name": "stdout",
9245-
"output_type": "stream",
9246-
"text": [
9247-
"[[-3.0, 2.0]]\n"
9248-
]
9249-
}
9250-
],
9233+
"outputs": [],
92519234
"source": [
92529235
"from spotpython.build import Kriging\n",
92539236
"S = Kriging()\n",
@@ -9257,17 +9240,9 @@
92579240
},
92589241
{
92599242
"cell_type": "code",
9260-
"execution_count": 5,
9243+
"execution_count": null,
92619244
"metadata": {},
9262-
"outputs": [
9263-
{
9264-
"name": "stdout",
9265-
"output_type": "stream",
9266-
"text": [
9267-
"[[-3.0, 2.0], [-3.0, 2.0], [1, 2], [1, 2]]\n"
9268-
]
9269-
}
9270-
],
9245+
"outputs": [],
92719246
"source": [
92729247
"from spotpython.build import Kriging\n",
92739248
"S = Kriging(n_theta=2, n_p=2, optim_p=True)\n",
@@ -9277,17 +9252,9 @@
92779252
},
92789253
{
92799254
"cell_type": "code",
9280-
"execution_count": 6,
9255+
"execution_count": null,
92819256
"metadata": {},
9282-
"outputs": [
9283-
{
9284-
"name": "stdout",
9285-
"output_type": "stream",
9286-
"text": [
9287-
"[[-3.0, 2.0], [-3.0, 2.0], [1, 2], [1, 2], [1e-09, 1.0]]\n"
9288-
]
9289-
}
9290-
],
9257+
"outputs": [],
92919258
"source": [
92929259
"from spotpython.build import Kriging\n",
92939260
"S = Kriging(n_theta=2, n_p=2, optim_p=True, noise=True)\n",
@@ -9297,22 +9264,213 @@
92979264
},
92989265
{
92999266
"cell_type": "code",
9300-
"execution_count": 9,
9267+
"execution_count": null,
9268+
"metadata": {},
9269+
"outputs": [],
9270+
"source": [
9271+
"from spotpython.build import Kriging\n",
9272+
"S = Kriging(n_theta=2, n_p=2, noise=True)\n",
9273+
"S.set_de_bounds()\n",
9274+
"print(S.de_bounds)"
9275+
]
9276+
},
9277+
{
9278+
"cell_type": "code",
9279+
"execution_count": null,
9280+
"metadata": {},
9281+
"outputs": [],
9282+
"source": [
9283+
"from spotpython.build import Kriging\n",
9284+
"import numpy as np\n",
9285+
"nat_X = np.array([[1, 2], [3, 4]])\n",
9286+
"nat_y = np.array([1, 2])\n",
9287+
"n_theta=2\n",
9288+
"n_p=2\n",
9289+
"S=Kriging(seed=124, n_theta=n_theta, n_p=n_p, optim_p=True, noise=True)\n",
9290+
"S._initialize_variables(nat_X, nat_y)\n",
9291+
"S._set_variable_types()\n",
9292+
"S._set_theta_values()\n",
9293+
"S._initialize_matrices()\n",
9294+
"S._set_de_bounds()\n",
9295+
"new_theta_p_Lambda = S.optimize_model()\n",
9296+
"assert len(new_theta_p_Lambda) == n_theta + n_p + 1\n",
9297+
"from spotpython.build import Kriging\n",
9298+
"import numpy as np\n",
9299+
"nat_X = np.array([[1, 2], [3, 4]])\n",
9300+
"nat_y = np.array([1, 2])\n",
9301+
"n_theta=2\n",
9302+
"n_p=2\n",
9303+
"S=Kriging(seed=124, n_theta=n_theta, n_p=n_p, optim_p=True, noise=False)\n",
9304+
"S._initialize_variables(nat_X, nat_y)\n",
9305+
"S._set_variable_types()\n",
9306+
"S._set_theta_values()\n",
9307+
"S._initialize_matrices()\n",
9308+
"S._set_de_bounds()\n",
9309+
"new_theta_p_Lambda = S.optimize_model()\n",
9310+
"assert len(new_theta_p_Lambda) == n_theta + n_p\n",
9311+
"from spotpython.build import Kriging\n",
9312+
"import numpy as np\n",
9313+
"nat_X = np.array([[1, 2], [3, 4]])\n",
9314+
"nat_y = np.array([1, 2])\n",
9315+
"n_theta=2\n",
9316+
"n_p=1\n",
9317+
"S=Kriging(seed=124, n_theta=n_theta, n_p=n_p, optim_p=True, noise=False)\n",
9318+
"S._initialize_variables(nat_X, nat_y)\n",
9319+
"S._set_variable_types()\n",
9320+
"S._set_theta_values()\n",
9321+
"S._initialize_matrices()\n",
9322+
"S._set_de_bounds()\n",
9323+
"new_theta_p_Lambda = S.optimize_model()\n",
9324+
"assert len(new_theta_p_Lambda) == n_theta + n_p\n",
9325+
"from spotpython.build import Kriging\n",
9326+
"import numpy as np\n",
9327+
"nat_X = np.array([[1, 2], [3, 4]])\n",
9328+
"nat_y = np.array([1, 2])\n",
9329+
"n_theta=1\n",
9330+
"n_p=1\n",
9331+
"S=Kriging(seed=124, n_theta=n_theta, n_p=n_p, optim_p=False, noise=False)\n",
9332+
"S._initialize_variables(nat_X, nat_y)\n",
9333+
"S._set_variable_types()\n",
9334+
"S._set_theta_values()\n",
9335+
"S._initialize_matrices()\n",
9336+
"S._set_de_bounds()\n",
9337+
"new_theta_p_Lambda = S.optimize_model()\n",
9338+
"assert len(new_theta_p_Lambda) == 1"
9339+
]
9340+
},
9341+
{
9342+
"cell_type": "markdown",
9343+
"metadata": {},
9344+
"source": [
9345+
"## extract_from_bounds()"
9346+
]
9347+
},
9348+
{
9349+
"cell_type": "code",
9350+
"execution_count": 13,
9351+
"metadata": {},
9352+
"outputs": [],
9353+
"source": [
9354+
"import numpy as np\n",
9355+
"from spotpython.build import Kriging\n",
9356+
"num_theta = 2\n",
9357+
"num_p = 3\n",
9358+
"S = Kriging(\n",
9359+
" seed=124,\n",
9360+
" n_theta=num_theta,\n",
9361+
" n_p=num_p,\n",
9362+
" optim_p=True,\n",
9363+
" noise=True\n",
9364+
")\n",
9365+
"bounds_array = np.array([1, 2, 3, 4, 5, 6])\n",
9366+
"S.extract_from_bounds(new_theta_p_Lambda=bounds_array)\n",
9367+
"assert np.array_equal(S.theta,\n",
9368+
" [1, 2]), f\"Expected theta to be [1, 2] but got {S.theta}\"\n",
9369+
"assert np.array_equal(S.p,\n",
9370+
" [3, 4, 5]), f\"Expected p to be [3, 4, 5] but got {S.p}\"\n",
9371+
"assert S.Lambda == 6, f\"Expected Lambda to be 6 but got {S.Lambda}\""
9372+
]
9373+
},
9374+
{
9375+
"cell_type": "code",
9376+
"execution_count": 17,
9377+
"metadata": {},
9378+
"outputs": [],
9379+
"source": [
9380+
"import numpy as np\n",
9381+
"from spotpython.build import Kriging\n",
9382+
"num_theta = 1\n",
9383+
"num_p = 1\n",
9384+
"S = Kriging(\n",
9385+
" seed=124,\n",
9386+
" n_theta=num_theta,\n",
9387+
" n_p=num_p,\n",
9388+
" optim_p=False,\n",
9389+
" noise=False\n",
9390+
")\n",
9391+
"bounds_array = np.array([1])\n",
9392+
"S.extract_from_bounds(new_theta_p_Lambda=bounds_array)\n",
9393+
"assert np.array_equal(S.theta,\n",
9394+
" [1]), f\"Expected theta to be [1] but got {S.theta}\""
9395+
]
9396+
},
9397+
{
9398+
"cell_type": "code",
9399+
"execution_count": 18,
9400+
"metadata": {},
9401+
"outputs": [],
9402+
"source": [
9403+
"import numpy as np\n",
9404+
"from spotpython.build import Kriging\n",
9405+
"num_theta = 1\n",
9406+
"num_p = 2\n",
9407+
"S = Kriging(\n",
9408+
" seed=124,\n",
9409+
" n_theta=num_theta,\n",
9410+
" n_p=num_p,\n",
9411+
" optim_p=True,\n",
9412+
" noise=True\n",
9413+
")\n",
9414+
"bounds_array = np.array([1, 2, 3, 4])\n",
9415+
"S.extract_from_bounds(new_theta_p_Lambda=bounds_array)\n",
9416+
"assert np.array_equal(S.theta,\n",
9417+
" [1]), f\"Expected theta to be [1, 2] but got {S.theta}\"\n",
9418+
"assert np.array_equal(S.p,\n",
9419+
" [2, 3]), f\"Expected p to be [3, 4, 5] but got {S.p}\"\n",
9420+
"assert S.Lambda == 4, f\"Expected Lambda to be 6 but got {S.Lambda}\""
9421+
]
9422+
},
9423+
{
9424+
"cell_type": "markdown",
9425+
"metadata": {},
9426+
"source": [
9427+
"## build_Psi()"
9428+
]
9429+
},
9430+
{
9431+
"cell_type": "code",
9432+
"execution_count": 1,
93019433
"metadata": {},
93029434
"outputs": [
93039435
{
93049436
"name": "stdout",
93059437
"output_type": "stream",
93069438
"text": [
9307-
"[[-3.0, 2.0], [-3.0, 2.0], [1e-09, 1.0]]\n"
9439+
"[[0]\n",
9440+
" [1]]\n",
9441+
"[0 1]\n",
9442+
"S.theta: [0.02]\n",
9443+
"S.theta: [np.float64(1.7322201179287893)]\n",
9444+
"S.Psi: [[1.00000001 1. ]\n",
9445+
" [1. 1.00000001]]\n",
9446+
"S.cnd_Psi: 134217728.18584064\n",
9447+
"S.inf_Psi: False\n"
93089448
]
93099449
}
93109450
],
93119451
"source": [
93129452
"from spotpython.build import Kriging\n",
9313-
"S = Kriging(n_theta=2, n_p=2, noise=True)\n",
9314-
"S.set_de_bounds()\n",
9315-
"print(S.de_bounds)"
9453+
"import numpy as np\n",
9454+
"nat_X = np.array([[0], [1]])\n",
9455+
"nat_y = np.array([0, 1])\n",
9456+
"n=1\n",
9457+
"p=1\n",
9458+
"S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=False)\n",
9459+
"S._initialize_variables(nat_X, nat_y)\n",
9460+
"S._set_variable_types()\n",
9461+
"print(S.nat_X)\n",
9462+
"print(S.nat_y)\n",
9463+
"S._set_theta_values()\n",
9464+
"print(f\"S.theta: {S.theta}\")\n",
9465+
"S._initialize_matrices()\n",
9466+
"S._set_de_bounds()\n",
9467+
"new_theta_p_Lambda = S._optimize_model()\n",
9468+
"S._extract_from_bounds(new_theta_p_Lambda)\n",
9469+
"print(f\"S.theta: {S.theta}\")\n",
9470+
"S.build_Psi()\n",
9471+
"print(f\"S.Psi: {S.Psi}\")\n",
9472+
"print(f\"S.cnd_Psi: {S.cnd_Psi}\")\n",
9473+
"print(f\"S.inf_Psi: {S.inf_Psi}\")"
93169474
]
93179475
},
93189476
{

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.24.13"
10+
version = "0.24.14"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

0 commit comments

Comments
 (0)