Skip to content

Commit 476ba8e

Browse files
0.33.10
cleanup kriging
1 parent dd36775 commit 476ba8e

5 files changed

Lines changed: 537 additions & 219 deletions

File tree

notebooks/00_spotPython_tests.ipynb

Lines changed: 91 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14477,41 +14477,61 @@
1447714477
},
1447814478
{
1447914479
"cell_type": "code",
14480-
"execution_count": 1,
14480+
"execution_count": null,
14481+
"metadata": {},
14482+
"outputs": [],
14483+
"source": [
14484+
"import numpy as np\n",
14485+
"from spotpython.surrogate.kriging import Kriging\n",
14486+
"# Training data\n",
14487+
"X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
14488+
"y_train = np.array([0.1, 0.2, 0.3])\n",
14489+
"# Initialize and fit the Kriging model\n",
14490+
"model = Kriging()\n",
14491+
"model.fit(X_train, y_train)\n",
14492+
"for param, value in model.get_params(deep=True).items():\n",
14493+
" print(f\"{param} -> {value}\")\n",
14494+
"theta_values = model.get_params()[\"theta\"]\n",
14495+
"print(\"Fitted theta values:\", theta_values)"
14496+
]
14497+
},
14498+
{
14499+
"cell_type": "code",
14500+
"execution_count": null,
14501+
"metadata": {},
14502+
"outputs": [],
14503+
"source": [
14504+
"import numpy as np\n",
14505+
"from spotpython.surrogate.kriging import Kriging\n",
14506+
"# Training data\n",
14507+
"X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
14508+
"y_train = np.array([0.1, 0.2, 0.3])\n",
14509+
"# Fit the Kriging model\n",
14510+
"model = Kriging().fit(X_train, y_train)\n",
14511+
"# Build the correlation matrix Psi\n",
14512+
"Psi = model.build_Psi()\n",
14513+
"print(\"Correlation matrix Psi:\\n\", Psi)"
14514+
]
14515+
},
14516+
{
14517+
"cell_type": "code",
14518+
"execution_count": 2,
1448114519
"metadata": {},
1448214520
"outputs": [
1448314521
{
1448414522
"name": "stdout",
1448514523
"output_type": "stream",
1448614524
"text": [
1448714525
"Anisotropic model: n_theta set to 2\n",
14488-
"Lambda -> [-8.98453674]\n",
14489-
"counter -> None\n",
14490-
"eps -> 1.4901161193847656e-08\n",
14491-
"isotropic -> False\n",
14492-
"log_level -> 50\n",
14493-
"max_Lambda -> 0.0\n",
14494-
"max_p -> 2.0\n",
14495-
"max_theta -> 2.0\n",
14496-
"method -> regression\n",
14497-
"metric_factorial -> canberra\n",
14498-
"min_Lambda -> -9.0\n",
14499-
"min_p -> 1.0\n",
14500-
"min_theta -> -3.0\n",
14501-
"model_fun_evals -> 100\n",
14502-
"model_optimizer -> <function differential_evolution at 0x1173237e0>\n",
14503-
"n_p -> 1\n",
14504-
"n_theta -> 2\n",
14505-
"name -> Kriging\n",
14506-
"optim_p -> False\n",
14507-
"p_val -> 2.0\n",
14508-
"penalty -> 10000.0\n",
14509-
"seed -> 124\n",
14510-
"spot_writer -> None\n",
14511-
"theta -> [-2.73827427 -2.74539395]\n",
14512-
"theta_init_zero -> False\n",
14513-
"var_type -> ['num', 'num']\n",
14514-
"Fitted theta values: [-2.73827427 -2.74539395]\n"
14526+
"Negative Log-Likelihood: -7.829213113186723\n",
14527+
"Correlation matrix Psi:\n",
14528+
" [[1.000001 0.60653066 0.13533528]\n",
14529+
" [0.60653066 1.000001 0.60653066]\n",
14530+
" [0.13533528 0.60653066 1.000001 ]]\n",
14531+
"Cholesky factor U:\n",
14532+
" [[1.0000005 0. 0. ]\n",
14533+
" [0.60653036 0.79506096 0. ]\n",
14534+
" [0.13533522 0.6596296 0.73930655]]\n"
1451514535
]
1451614536
}
1451714537
],
@@ -14521,14 +14541,50 @@
1452114541
"# Training data\n",
1452214542
"X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
1452314543
"y_train = np.array([0.1, 0.2, 0.3])\n",
14524-
"# Initialize and fit the Kriging model\n",
14525-
"model = Kriging()\n",
14526-
"model.fit(X_train, y_train)\n",
14527-
"for param, value in model.get_params(deep=True).items():\n",
14528-
" print(f\"{param} -> {value}\")\n",
14529-
"theta_values = model.get_params()[\"theta\"]\n",
14530-
"print(\"Fitted theta values:\", theta_values)"
14544+
"# Fit the Kriging model\n",
14545+
"model = Kriging().fit(X_train, y_train)\n",
14546+
"# Example log(theta) parameters\n",
14547+
"log_theta = np.array([0.0, 0.0, -6.0]) # -6 => 10**(-6) = 1e-6\n",
14548+
"negLnLike, Psi, U = model.likelihood(log_theta)\n",
14549+
"print(\"Negative Log-Likelihood:\", negLnLike)\n",
14550+
"print(\"Correlation matrix Psi:\\n\", Psi)\n",
14551+
"print(\"Cholesky factor U:\\n\", U)"
14552+
]
14553+
},
14554+
{
14555+
"cell_type": "code",
14556+
"execution_count": 13,
14557+
"metadata": {},
14558+
"outputs": [
14559+
{
14560+
"name": "stdout",
14561+
"output_type": "stream",
14562+
"text": [
14563+
"Anisotropic model: n_theta set to 2\n",
14564+
"Psi vector for new point:\n",
14565+
" [0.99975896 0.99975896 0.99783273]\n"
14566+
]
14567+
}
14568+
],
14569+
"source": [
14570+
"import numpy as np\n",
14571+
"from spotpython.surrogate.kriging import Kriging\n",
14572+
"# Training data\n",
14573+
"X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
14574+
"y_train = np.array([0.1, 0.2, 0.3])\n",
14575+
"# Fit the Kriging model\n",
14576+
"model = Kriging().fit(X_train, y_train)\n",
14577+
"x_new = np.array([0.25, 0.25])\n",
14578+
"psi_vector = model.build_psi_vec(x_new)\n",
14579+
"print(\"Psi vector for new point:\\n\", psi_vector)"
1453114580
]
14581+
},
14582+
{
14583+
"cell_type": "code",
14584+
"execution_count": null,
14585+
"metadata": {},
14586+
"outputs": [],
14587+
"source": []
1453214588
}
1453314589
],
1453414590
"metadata": {

0 commit comments

Comments
 (0)