|
325 | 325 | "\n" |
326 | 326 | ] |
327 | 327 | }, |
| 328 | + { |
| 329 | + "cell_type": "markdown", |
| 330 | + "metadata": {}, |
| 331 | + "source": [ |
| 332 | + "Cost function over parameter space ($w_1 \\times w_2$ plane)<br>\n", |
| 333 | + "매개변수공간 ($w_1 \\times w_2$ 평면) 상의 비용함수\n", |
| 334 | + "\n" |
| 335 | + ] |
| 336 | + }, |
| 337 | + { |
| 338 | + "cell_type": "code", |
| 339 | + "execution_count": null, |
| 340 | + "metadata": {}, |
| 341 | + "outputs": [], |
| 342 | + "source": [ |
| 343 | + "def plot_cost_surf(cost_function):\n", |
| 344 | + "\n", |
| 345 | + " w1 = np.linspace(-10.0, 10.0, 20*20+1)\n", |
| 346 | + " w2 = np.linspace(-10.0, 10.0, 20*20+1)\n", |
| 347 | + "\n", |
| 348 | + " W1, W2 = np.meshgrid(w1, w2)\n", |
| 349 | + " C = np.zeros_like(W1)\n", |
| 350 | + "\n", |
| 351 | + " for i_row in range(W1.shape[0]):\n", |
| 352 | + " for j_col in range(W1.shape[1]):\n", |
| 353 | + " w = np.array([W1[i_row, j_col], W2[i_row, j_col]])\n", |
| 354 | + " C[i_row, j_col] = cost_function(w, data)\n", |
| 355 | + "\n", |
| 356 | + " fig = plt.figure(figsize=(10, 5))\n", |
| 357 | + "\n", |
| 358 | + " ax0 = fig.add_subplot(1, 2, 1)\n", |
| 359 | + " ax0.contour(W1, W2, C, cmap='viridis')\n", |
| 360 | + " ax0.set_xlabel('$w_1$')\n", |
| 361 | + " ax0.set_ylabel('$w_2$')\n", |
| 362 | + " ax0.axis('equal')\n", |
| 363 | + " ax0.grid(True)\n", |
| 364 | + "\n", |
| 365 | + " ax1 = fig.add_subplot(1, 2, 2, projection='3d')\n", |
| 366 | + " ax1.plot_surface(W1, W2, C, cmap='viridis')\n", |
| 367 | + " ax1.set_xlabel('$w_1$')\n", |
| 368 | + " ax1.set_ylabel('$w_2$')\n", |
| 369 | + "\n", |
| 370 | + " return ax0, ax1\n", |
| 371 | + "\n" |
| 372 | + ] |
| 373 | + }, |
| 374 | + { |
| 375 | + "cell_type": "code", |
| 376 | + "execution_count": null, |
| 377 | + "metadata": {}, |
| 378 | + "outputs": [], |
| 379 | + "source": [ |
| 380 | + "axs = plot_cost_surf(cost_function_first_attempt)\n", |
| 381 | + "\n" |
| 382 | + ] |
| 383 | + }, |
328 | 384 | { |
329 | 385 | "cell_type": "markdown", |
330 | 386 | "metadata": {}, |
|
496 | 552 | "\n" |
497 | 553 | ] |
498 | 554 | }, |
| 555 | + { |
| 556 | + "cell_type": "markdown", |
| 557 | + "metadata": {}, |
| 558 | + "source": [ |
| 559 | + "Cost function over parameter space ($w_1 \\times w_2$ plane)<br>\n", |
| 560 | + "매개변수공간 ($w_1 \\times w_2$ 평면) 상의 비용함수\n", |
| 561 | + "\n" |
| 562 | + ] |
| 563 | + }, |
| 564 | + { |
| 565 | + "cell_type": "code", |
| 566 | + "execution_count": null, |
| 567 | + "metadata": {}, |
| 568 | + "outputs": [], |
| 569 | + "source": [ |
| 570 | + "axs = plot_cost_surf(cost_function_step)\n", |
| 571 | + "\n" |
| 572 | + ] |
| 573 | + }, |
499 | 574 | { |
500 | 575 | "cell_type": "markdown", |
501 | 576 | "metadata": {}, |
|
638 | 713 | "\n" |
639 | 714 | ] |
640 | 715 | }, |
| 716 | + { |
| 717 | + "cell_type": "markdown", |
| 718 | + "metadata": {}, |
| 719 | + "source": [ |
| 720 | + "Cost function over parameter space ($w_1 \\times w_2$ plane)<br>\n", |
| 721 | + "매개변수공간 ($w_1 \\times w_2$ 평면) 상의 비용함수\n", |
| 722 | + "\n" |
| 723 | + ] |
| 724 | + }, |
| 725 | + { |
| 726 | + "cell_type": "code", |
| 727 | + "execution_count": null, |
| 728 | + "metadata": {}, |
| 729 | + "outputs": [], |
| 730 | + "source": [ |
| 731 | + "axs = plot_cost_surf(cost_function_sigmoid)\n", |
| 732 | + "\n" |
| 733 | + ] |
| 734 | + }, |
641 | 735 | { |
642 | 736 | "cell_type": "markdown", |
643 | 737 | "metadata": {}, |
|
729 | 823 | "\n" |
730 | 824 | ] |
731 | 825 | }, |
| 826 | + { |
| 827 | + "cell_type": "markdown", |
| 828 | + "metadata": {}, |
| 829 | + "source": [ |
| 830 | + "Cost function over parameter space ($w_1 \\times w_2$ plane)<br>\n", |
| 831 | + "매개변수공간 ($w_1 \\times w_2$ 평면) 상의 비용함수\n", |
| 832 | + "\n" |
| 833 | + ] |
| 834 | + }, |
| 835 | + { |
| 836 | + "cell_type": "code", |
| 837 | + "execution_count": null, |
| 838 | + "metadata": {}, |
| 839 | + "outputs": [], |
| 840 | + "source": [ |
| 841 | + "axs = plot_cost_surf(cost_function_cross_entropy)\n", |
| 842 | + "\n" |
| 843 | + ] |
| 844 | + }, |
732 | 845 | { |
733 | 846 | "cell_type": "markdown", |
734 | 847 | "metadata": {}, |
|
0 commit comments