@@ -14670,6 +14670,137 @@
1467014670 "S.surrogate.plot()"
1467114671 ]
1467214672 },
14673+ {
14674+ "cell_type": "code",
14675+ "execution_count": null,
14676+ "metadata": {},
14677+ "outputs": [
14678+ {
14679+ "name": "stdout",
14680+ "output_type": "stream",
14681+ "text": [
14682+ "Cross-correlation matrix K(A, B):\n",
14683+ " [[0.99904559 0.99144306]\n",
14684+ " [0.99904559 0.99904559]]\n"
14685+ ]
14686+ }
14687+ ],
14688+ "source": [
14689+ "import numpy as np\n",
14690+ "from spotpython.surrogate.kriging import Kriging\n",
14691+ "X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
14692+ "y_train = np.array([0.1, 0.2, 0.3])\n",
14693+ "# Fit the Kriging model\n",
14694+ "model = Kriging().fit(X_train, y_train)\n",
14695+ "# Create two sets of points A and B\n",
14696+ "A = np.array([[0.0, 0.0], [1.0, 1.0]])\n",
14697+ "B = np.array([[0.5, 0.5], [1.5, 1.5]])\n",
14698+ "# Compute the cross-correlation matrix K(A, B)\n",
14699+ "K_AB = model._kernel_cross(A, B)\n",
14700+ "print(\"Cross-correlation matrix K(A, B):\\n\", K_AB)"
14701+ ]
14702+ },
14703+ {
14704+ "cell_type": "code",
14705+ "execution_count": 5,
14706+ "metadata": {},
14707+ "outputs": [
14708+ {
14709+ "name": "stdout",
14710+ "output_type": "stream",
14711+ "text": [
14712+ "Negative Log-Likelihood: -7.829213113186723\n",
14713+ "Correlation matrix Psi:\n",
14714+ " [[1.000001 0.60653066 0.13533528]\n",
14715+ " [0.60653066 1.000001 0.60653066]\n",
14716+ " [0.13533528 0.60653066 1.000001 ]]\n",
14717+ "Cholesky factor U (lower triangular):\n",
14718+ " [[1.0000005 0. 0. ]\n",
14719+ " [0.60653036 0.79506096 0. ]\n",
14720+ " [0.13533522 0.6596296 0.73930655]]\n"
14721+ ]
14722+ }
14723+ ],
14724+ "source": [
14725+ "import numpy as np\n",
14726+ "from spotpython.surrogate.kriging import Kriging\n",
14727+ "# Training data\n",
14728+ "X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0]])\n",
14729+ "y_train = np.array([0.1, 0.2, 0.3])\n",
14730+ "# Fit the Kriging model\n",
14731+ "model = Kriging().fit(X_train, y_train)\n",
14732+ "log_theta = np.array([0.0, 0.0, -6.0]) # nugget: -6 => 10**(-6) = 1e-6\n",
14733+ "negLnLike, Psi, U = model._likelihood_exact(log_theta)\n",
14734+ "print(\"Negative Log-Likelihood:\", negLnLike)\n",
14735+ "print(\"Correlation matrix Psi:\\n\", Psi)\n",
14736+ "print(\"Cholesky factor U (lower triangular):\\n\", U)"
14737+ ]
14738+ },
14739+ {
14740+ "cell_type": "code",
14741+ "execution_count": 6,
14742+ "metadata": {},
14743+ "outputs": [
14744+ {
14745+ "name": "stdout",
14746+ "output_type": "stream",
14747+ "text": [
14748+ "Landmark indices: [4 2 3]\n",
14749+ "Landmark points (X_m_):\n",
14750+ " [[0.75 0.75]\n",
14751+ " [1. 1. ]\n",
14752+ " [0.25 0.25]]\n",
14753+ "Cholesky factor of W (W_chol_):\n",
14754+ " [[ 1. 0. 0. ]\n",
14755+ " [ 0.97810062 0.20813259 0. ]\n",
14756+ " [ 0.9152382 -0.36456734 0.17155086]]\n"
14757+ ]
14758+ }
14759+ ],
14760+ "source": [
14761+ "import numpy as np\n",
14762+ "from spotpython.surrogate.kriging import Kriging\n",
14763+ "# Training data\n",
14764+ "X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75]])\n",
14765+ "y_train = np.array([0.1, 0.2, 0.3, 0.15, 0.25])\n",
14766+ "# Fit the Kriging model with Nyström approximation\n",
14767+ "model = Kriging(use_nystrom=True, nystrom_m=3).fit(X_train, y_train)\n",
14768+ "model._nystrom_setup()\n",
14769+ "print(\"Landmark indices:\", model.landmark_idx_)\n",
14770+ "print(\"Landmark points (X_m_):\\n\", model.X_m_)\n",
14771+ "print(\"Cholesky factor of W (W_chol_):\\n\", model.W_chol_)"
14772+ ]
14773+ },
14774+ {
14775+ "cell_type": "code",
14776+ "execution_count": 7,
14777+ "metadata": {},
14778+ "outputs": [
14779+ {
14780+ "name": "stdout",
14781+ "output_type": "stream",
14782+ "text": [
14783+ "Result of R^{-1} v:\n",
14784+ " [-290115.82440447 -300201.80537958 -262514.38594912 -301405.32195489\n",
14785+ " -286648.86427461]\n"
14786+ ]
14787+ }
14788+ ],
14789+ "source": [
14790+ "import numpy as np\n",
14791+ "from spotpython.surrogate.kriging import Kriging\n",
14792+ "# Training data\n",
14793+ "X_train = np.array([[0.0, 0.0], [0.5, 0.5], [1.0, 1.0], [0.25, 0.25], [0.75, 0.75]])\n",
14794+ "y_train = np.array([0.1, 0.2, 0.3, 0.15, 0.25])\n",
14795+ "# Fit the Kriging model with Nyström approximation\n",
14796+ "model = Kriging(use_nystrom=True, nystrom_m=3).fit(X_train, y_train)\n",
14797+ "model._nystrom_setup()\n",
14798+ "v = np.array([1.0, 2.0, 3.0, 4.0, 5.0])\n",
14799+ "Rinv_v = model._woodbury_solve(v)\n",
14800+ "print(\"Result of R^{-1} v:\\n\", Rinv_v)\n",
14801+ "# Note: Ensure that model.M_chol_ is computed before calling this method."
14802+ ]
14803+ },
1467314804 {
1467414805 "cell_type": "code",
1467514806 "execution_count": null,
0 commit comments