|
133 | 133 | }, |
134 | 134 | { |
135 | 135 | "cell_type": "code", |
136 | | - "execution_count": 21, |
| 136 | + "execution_count": null, |
137 | 137 | "metadata": {}, |
138 | 138 | "outputs": [], |
139 | 139 | "source": [ |
|
158 | 158 | }, |
159 | 159 | { |
160 | 160 | "cell_type": "code", |
161 | | - "execution_count": 19, |
| 161 | + "execution_count": null, |
162 | 162 | "metadata": {}, |
163 | 163 | "outputs": [], |
164 | 164 | "source": [ |
|
198 | 198 | }, |
199 | 199 | { |
200 | 200 | "cell_type": "code", |
201 | | - "execution_count": 10, |
| 201 | + "execution_count": null, |
202 | 202 | "metadata": {}, |
203 | | - "outputs": [ |
204 | | - { |
205 | | - "name": "stdout", |
206 | | - "output_type": "stream", |
207 | | - "text": [ |
208 | | - "{'negLnLike': array([-1.38629436]), 'theta': array([-1.14525993, 1.6123372 ]), 'p': array([1.84444406, 1.74590865]), 'Lambda': array([0.44268472])}\n", |
209 | | - "{'negLnLike': array([-1.38629436, -1.38629436]), 'theta': array([-1.14525993, 1.6123372 , -1.14525993, 1.6123372 ]), 'p': array([1.84444406, 1.74590865, 1.84444406, 1.74590865]), 'Lambda': array([0.44268472, 0.44268472])}\n" |
210 | | - ] |
211 | | - } |
212 | | - ], |
| 203 | + "outputs": [], |
213 | 204 | "source": [ |
214 | 205 | "from spotPython.build.kriging import Kriging\n", |
215 | 206 | "import numpy as np\n", |
|
248 | 239 | }, |
249 | 240 | { |
250 | 241 | "cell_type": "code", |
251 | | - "execution_count": 6, |
| 242 | + "execution_count": null, |
252 | 243 | "metadata": {}, |
253 | | - "outputs": [ |
254 | | - { |
255 | | - "name": "stdout", |
256 | | - "output_type": "stream", |
257 | | - "text": [ |
258 | | - "[[1.00000001 1. ]\n", |
259 | | - " [1. 1.00000001]]\n" |
260 | | - ] |
261 | | - } |
262 | | - ], |
| 244 | + "outputs": [], |
263 | 245 | "source": [ |
264 | 246 | "from spotPython.build.kriging import Kriging\n", |
265 | 247 | "import numpy as np\n", |
266 | | - "nat_X = np.array([[1, 0], [1, 0]])\n", |
| 248 | + "nat_X = np.array([[.1, 0], [0, .1]])\n", |
267 | 249 | "nat_y = np.array([1, 2])\n", |
268 | 250 | "S = Kriging()\n", |
269 | 251 | "S.fit(nat_X, nat_y)\n", |
|
272 | 254 | "print(S.Psi)" |
273 | 255 | ] |
274 | 256 | }, |
| 257 | + { |
| 258 | + "cell_type": "markdown", |
| 259 | + "metadata": {}, |
| 260 | + "source": [ |
| 261 | + "## initialize_variables" |
| 262 | + ] |
| 263 | + }, |
| 264 | + { |
| 265 | + "cell_type": "code", |
| 266 | + "execution_count": null, |
| 267 | + "metadata": {}, |
| 268 | + "outputs": [], |
| 269 | + "source": [ |
| 270 | + "from spotPython.build.kriging import Kriging\n", |
| 271 | + "import numpy as np\n", |
| 272 | + "nat_X = np.array([[1, 2], [3, 4]])\n", |
| 273 | + "nat_y = np.array([1, 2])\n", |
| 274 | + "S = Kriging()\n", |
| 275 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 276 | + "assert S.nat_X.all() == nat_X.all()\n", |
| 277 | + "assert S.nat_y.all() == nat_y.all()\n", |
| 278 | + "assert S.cod_X.shape == (2, 2)\n", |
| 279 | + "assert S.cod_y.shape == (2,)" |
| 280 | + ] |
| 281 | + }, |
| 282 | + { |
| 283 | + "cell_type": "markdown", |
| 284 | + "metadata": {}, |
| 285 | + "source": [ |
| 286 | + "## set_variable_types" |
| 287 | + ] |
| 288 | + }, |
| 289 | + { |
| 290 | + "cell_type": "code", |
| 291 | + "execution_count": null, |
| 292 | + "metadata": {}, |
| 293 | + "outputs": [], |
| 294 | + "source": [ |
| 295 | + "from spotPython.build.kriging import Kriging\n", |
| 296 | + "import numpy as np\n", |
| 297 | + "nat_X = np.array([[1, 2], [3, 4]])\n", |
| 298 | + "nat_y = np.array([1, 2])\n", |
| 299 | + "n=2\n", |
| 300 | + "p=2\n", |
| 301 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 302 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 303 | + "S.set_variable_types()\n", |
| 304 | + "assert S.var_type == ['num', 'num']\n", |
| 305 | + "nat_X = np.array([[1, 2, 3], [4, 5, 6]])\n", |
| 306 | + "nat_y = np.array([1, 2])\n", |
| 307 | + "n=3\n", |
| 308 | + "p=1\n", |
| 309 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 310 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 311 | + "S.set_variable_types()\n", |
| 312 | + "S.var_type\n", |
| 313 | + "assert S.var_type == ['num', 'num', 'num']" |
| 314 | + ] |
| 315 | + }, |
| 316 | + { |
| 317 | + "cell_type": "markdown", |
| 318 | + "metadata": {}, |
| 319 | + "source": [ |
| 320 | + "## set_theta_values" |
| 321 | + ] |
| 322 | + }, |
| 323 | + { |
| 324 | + "cell_type": "code", |
| 325 | + "execution_count": null, |
| 326 | + "metadata": {}, |
| 327 | + "outputs": [], |
| 328 | + "source": [ |
| 329 | + "from spotPython.build.kriging import Kriging\n", |
| 330 | + "import numpy as np\n", |
| 331 | + "from numpy import array\n", |
| 332 | + "nat_X = np.array([[1, 2], [3, 4]])\n", |
| 333 | + "nat_y = np.array([1, 2])\n", |
| 334 | + "n=2\n", |
| 335 | + "p=2\n", |
| 336 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 337 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 338 | + "S.set_variable_types()\n", |
| 339 | + "S.nat_to_cod_init()\n", |
| 340 | + "S.set_theta_values()\n", |
| 341 | + "assert S.theta.all() == array([0., 0.]).all()\n", |
| 342 | + "nat_X = np.array([[1, 2], [3, 4]])\n", |
| 343 | + "nat_y = np.array([1, 2])\n", |
| 344 | + "# n is set to 3, but the number of columns of nat_X is 2\n", |
| 345 | + "n=3\n", |
| 346 | + "p=2\n", |
| 347 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 348 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 349 | + "S.set_variable_types()\n", |
| 350 | + "S.nat_to_cod_init()\n", |
| 351 | + "snt = S.n_theta\n", |
| 352 | + "S.set_theta_values()\n", |
| 353 | + "# since snt == 3, it is not equal to S.n_theta, which is 2 because \n", |
| 354 | + "# of the correction in the set_theta_values method\n", |
| 355 | + "assert S.n_theta != snt\n" |
| 356 | + ] |
| 357 | + }, |
| 358 | + { |
| 359 | + "cell_type": "markdown", |
| 360 | + "metadata": {}, |
| 361 | + "source": [ |
| 362 | + "## initialize_matrices" |
| 363 | + ] |
| 364 | + }, |
| 365 | + { |
| 366 | + "cell_type": "code", |
| 367 | + "execution_count": 9, |
| 368 | + "metadata": {}, |
| 369 | + "outputs": [], |
| 370 | + "source": [ |
| 371 | + "from spotPython.build.kriging import Kriging\n", |
| 372 | + "import numpy as np\n", |
| 373 | + "from numpy import log, var\n", |
| 374 | + "nat_X = np.array([[1, 2], [3, 4], [5, 6]])\n", |
| 375 | + "nat_y = np.array([1, 2, 3])\n", |
| 376 | + "n=3\n", |
| 377 | + "p=1\n", |
| 378 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 379 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 380 | + "S.set_variable_types()\n", |
| 381 | + "S.nat_to_cod_init()\n", |
| 382 | + "S.set_theta_values()\n", |
| 383 | + "S.initialize_matrices()\n", |
| 384 | + "# if var(self.nat_y) is > 0, then self.pen_val = self.n * log(var(self.nat_y)) + 1e4\n", |
| 385 | + "# else self.pen_val = self.n * var(self.nat_y) + 1e4\n", |
| 386 | + "assert S.pen_val == nat_X.shape[0] * log(var(S.nat_y)) + 1e4\n", |
| 387 | + "assert S.Psi.shape == (n, n)\n", |
| 388 | + "#\n", |
| 389 | + "# use a zero variance, then the penalty should be computed without log()\n", |
| 390 | + "nat_y = np.array([1, 1, 1])\n", |
| 391 | + "n=3\n", |
| 392 | + "p=1\n", |
| 393 | + "S=Kriging(name='kriging', seed=124, n_theta=n, n_p=p, optim_p=True, noise=True)\n", |
| 394 | + "S.initialize_variables(nat_X, nat_y)\n", |
| 395 | + "S.set_variable_types()\n", |
| 396 | + "S.nat_to_cod_init()\n", |
| 397 | + "S.set_theta_values()\n", |
| 398 | + "S.initialize_matrices()\n", |
| 399 | + "# if var(self.nat_y) is > 0, then self.pen_val = self.n * log(var(self.nat_y)) + 1e4\n", |
| 400 | + "# else self.pen_val = self.n * var(self.nat_y) + 1e4\n", |
| 401 | + "assert S.pen_val == nat_X.shape[0] * (var(S.nat_y)) + 1e4\n", |
| 402 | + "assert S.Psi.shape == (n, n)\n" |
| 403 | + ] |
| 404 | + }, |
275 | 405 | { |
276 | 406 | "cell_type": "code", |
277 | 407 | "execution_count": null, |
|
0 commit comments