{"id":8378,"date":"2020-06-14T09:33:00","date_gmt":"2020-06-14T00:33:00","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=8378"},"modified":"2020-06-14T10:46:24","modified_gmt":"2020-06-14T01:46:24","slug":"%ec%9e%85%eb%a0%a5-1%ea%b0%9c%ec%99%80-%ec%b6%9c%eb%a0%a5-2%ea%b0%9c%ec%97%90-%eb%8c%80%ed%95%9c-%ec%84%a0%ed%98%95%ed%9a%8c%ea%b7%80-%ec%8b%a0%ea%b2%bd%eb%a7%9d-%ea%b5%ac%ec%84%b1","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=8378","title":{"rendered":"\uc785\ub825 1\uac1c\uc640 \ucd9c\ub825 2\uac1c\uc5d0 \ub300\ud55c \uc120\ud615\ud68c\uadc0 \uc2e0\uacbd\ub9dd \uad6c\uc131 (\ubcf5\ud569 \ucd9c\ub825 \/ \ub2e4\uc911 \ucd9c\ub825 \uc2e0\uacbd\ub9dd \ubaa8\ub378)"},"content":{"rendered":"<p>\ub2e4\uc74c\uacfc \uac19\uc740 \uad6c\uc870\uc758 \uc2e0\uacbd\ub9dd\uc744 \uad6c\ud604\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc774\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/Linear_1_2.png\" alt=\"\" width=\"800\" class=\"aligncenter size-full wp-image-8379\" \/><\/p>\n<p>\uc704\uc758 \uc2e0\uacbd\ub9dd\uc744 \ud1b5\ud574 \ud310\ub2e8\ud560 \uc218 \uc788\ub294 \uac83\uc740 \uc785\ub825\uac12\uc740 1\uac1c\uc774\uace0 \ucd9c\ub825\uac12\uc774 2\uac1c\uc774\ubbc0\ub85c \uac01\uac01\uc758 \ud150\uc11c\uad6c\uc870\ub294 [x], [y1, y2]\ub77c\ub294 \uac83\uc774\ub2e4. \uc2e0\uacbd\ub9dd\uc758 \ub9c8\uc9c0\ub9c9 \uc740\ub2c9\uce35\uc758 \ub274\ub7f0\uac1c\uc218\ub294 \ucd9c\ub825 \uac1c\uc218\uc640 \ub3d9\uc77c\ud558\ubbc0\ub85c 2\uac1c\uc774\ub2e4.<\/p>\n<p>\ucf54\ub4dc\ub97c \ubcf4\uc790. \uba3c\uc800 \ud544\uc694\ud55c \ud328\ud0a4\uc9c0\uc758 \uc784\ud3ec\ud2b8\uc774\ub2e4. \ud30c\uc774\ud1a0\uce58\ub97c \uc0ac\uc6a9\ud55c \uc608\uc774\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport torch\r\nimport torch.nn as nn\r\nimport torch.optim as optim\r\nimport torch.nn.init as init\r\n<\/pre>\n<p>\ub370\uc774\ud130\ub97c \uc900\ube44\ud55c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nnum_data = 4000\r\n\r\nx = torch.Tensor(num_data,1)\r\ninit.uniform_(x,-10,10)\r\n\r\nnoise = torch.FloatTensor(num_data,2)\r\ninit.normal_(noise, std=1)\r\n\r\ndef func1(x): return 4*x+5 \r\ndef func2(x): return 7*x+3 \r\n\r\ny1 = func1(x)\r\ny2 = func2(x)\r\n\r\ny_noise = torch.Tensor(num_data,2)\r\ny_noise[:,0] = y1[:,0] + noise[:,0]\r\ny_noise[:,1] = y2[:,0] + noise[:,1]\r\n<\/pre>\n<p>\ub370\uc774\ud130\uc14b\uc758 \uad6c\uc131 \uac1c\uc218\ub294 4000\uac1c\ub85c \ud588\ub2e4. \uc785\ub825\uac12(x)\uc5d0 \ub300\ud574 2\uac1c\uc758 \ucd9c\ub825\uac12\uc744 \uc704\ud55c \uc120\ud615\uacf5\uc2dd\uc774 9\uc640 10 \ub77c\uc778\uc5d0 \ubcf4\uc778\ub2e4. 12-17\ub77c\uc778\uc740 \ub370\uc774\ud130\uc5d0 \uc7a1\uc74c\uc744 \ucd94\uac00\ud55c \uac83\uc774\ub2e4. \uc7a1\uc74c\uc774 \ucd94\uac00\ub41c \ub370\uc774\ud130\ub97c \ud1b5\ud574 \uac00\uc911\uce58(\uae30\uc6b8\uae30)\uc778 4, 7\uacfc \ud3b8\ud5a5(y\uc808\ud3b8)\uc778 5, 3\uc744 \uacb0\uacfc\ub97c \uc5bb\uc5b4\ub0b4\uba74 \ub41c\ub2e4. \uc544\ub798\ub294 \uc774\ub97c \uc704\ud55c \ud559\uc2b5 \ucf54\ub4dc\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nmodel = nn.Linear(1,2)\r\nloss_func = nn.L1Loss()\r\noptimizer = optim.SGD(model.parameters(), lr=0.01)\r\nlabel = y_noise\r\nnum_epoch = 2000\r\n\r\nfor i in range(num_epoch):\r\n    optimizer.zero_grad()\r\n    output = model(x)\r\n    loss = loss_func(output, label)\r\n    loss.backward()\r\n    optimizer.step()\r\n\r\n    if i%10 == 0:\r\n        print(loss.data)\r\n\r\nparam_list = list(model.parameters())\r\nprint(param_list[0], param_list[1])\r\n<\/pre>\n<p>\uacb0\uacfc\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\r\ntensor(28.9745)\r\ntensor(27.7681)\r\ntensor(26.5639)\r\ntensor(25.3614)\r\ntensor(24.1623)\r\ntensor(22.9677)\r\ntensor(21.7777)\r\n.\r\n.\r\n.\r\ntensor(0.7945)\r\ntensor(0.7945)\r\ntensor(0.7945)\r\nParameter containing:\r\ntensor([[3.9986],\r\n        [7.0006]], requires_grad=True) Parameter containing:\r\ntensor([4.9845, 3.0214], requires_grad=True)\r\n<\/pre>\n<p>\ucd1d 2000\ubc88 \ud559\uc2b5 \uc2dc\ucf30\uace0, \uadf8 \uacb0\uacfc\ub85c \uc190\uc2e4\uac12\uc774 \uc57d 27\ub85c \uc2dc\uc791\ud574\uc11c \uc57d 0.79 \uc904\uc5c8\ub2e4. \uadf8\ub9ac\uace0 \uacb0\uacfc\ub294 4, 7 \uadf8\ub9ac\uace0 5, 3\uc5d0 \uadfc\uc0ac\ud55c \uac12\uc774 \ub098\uc628\uac83\uc744 \uc54c \uc218 \uc788\ub2e4.<\/p>\n<p>\uc774 \ucf54\ub4dc\ub97c \ud1b5\ud574 \uc54c\uc544\ub0b8 \uac83\uc740 1\uac1c\uc758 \ud2b9\uc131\uc744 \ud1b5\ud574 \uadf8\ubcf4\ub2e4 \ub354 \ub9ce\uc740 2\uac1c\uc758 \ud2b9\uc131\uc744 \uc5bb\uc5b4\ub0b4\uc57c \ud558\ub294 \uc774 \uacbd\uc6b0\uc5d0\ub294 \uc785\ub825 \ub370\uc774\ud130\uac00 \uc0c1\ub300\uc801\uc73c\ub85c \ub9ce\uc544\uc57c \ud55c\ub2e4\ub294 \uac83\uc774\ub2e4. \uc774 \uacbd\uc6b0\ub294 4000\uac1c\uc774\ub2e4. \uc544\uc6b8\ub7ec \uc801\ub2f9\ud55c \uc190\uc2e4\ud568\uc218\ub97c \uc0ac\uc6a9\ud574\uc57c \ud55c\ub2e4. \uc704\uc758 \uc608\uc81c\ub294 L1 \uc190\uc2e4\ud568\uc218\ub97c \uc0ac\uc6a9\ud588\uc9c0\ub9cc \ud3c9\uade0\uc81c\uacf1\uc624\ucc28 \uc190\uc2e4\ud568\uc218\ub97c \uc0ac\uc6a9\ud558\uba74 \ub354 \uc801\uc740 \ub370\uc774\ud130(\uc774 \ubd80\ubd84\uc740 \ud655\uc778\uc774 \ud544\uc694\ud568)\uc640 \ubc18\ubcf5\ud559\uc2b5\uc774 \uac00\ub2a5\ud558\ub2e4.<\/p>\n<p>\uc5ec\uae30\uc11c \uc785\ub825 \ub370\uc774\ud130\uc640 \ubd84\uc11d \uacb0\uacfc\ub97c \uadf8\ub798\ud504\ub85c \uc2dc\uac01\ud654 \ud574\ubcf4\uc790. \ud574\ub2f9 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\ub2e4. \uc9c0\uae08\uae4c\uc9c0\uc758 \ucf54\ub4dc\uc5d0\uc11c \ub9c8\uc9c0\ub9c9\uc5d0 \ubd99\uc774\uba74 \ub41c\ub2e4.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nplt.figure(figsize=(15,15))\r\nplt.scatter(x.numpy(),y_noise[:,0].numpy(),s=3,c=\"gray\")\r\nplt.scatter(x.numpy(),y_noise[:,1].numpy(),s=3,c=\"black\")\r\n\r\nx = np.arange(-10, 10, 0.01)\r\nplt.plot(x, func1(x), linestyle='-', label=\"func1\", c='red')\r\nplt.plot(x, func2(x), linestyle='-', label=\"func2\", c='blue')\r\n\r\nplt.axis([-10, 10, -30, 30])\r\nplt.show()\r\n<\/pre>\n<p>\uadf8\ub798\ud504\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/2019\/10\/Linear_1_2_graph.png\" alt=\"\" width=\"950\" class=\"aligncenter size-full wp-image-8386\" \/><\/p>\n<p>\ud68c\uc0c9\uc810\uacfc \uac80\uc815\uc0c9\uc810\uc740 \uc785\ub825 \ub370\uc774\ud130\uc774\uace0, \ube68\uac04\uc0c9\uc120\uacfc \ud30c\ub780\uc0c9\uc120\uc740 \uc120\ud615\ud68c\uadc0 \uacb0\uacfc\ub97c \ud45c\uc2dc\ud55c \uac83\uc774\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ub2e4\uc74c\uacfc \uac19\uc740 \uad6c\uc870\uc758 \uc2e0\uacbd\ub9dd\uc744 \uad6c\ud604\uc5d0 \ub300\ud55c \ub0b4\uc6a9\uc774\ub2e4. \uc704\uc758 \uc2e0\uacbd\ub9dd\uc744 \ud1b5\ud574 \ud310\ub2e8\ud560 \uc218 \uc788\ub294 \uac83\uc740 \uc785\ub825\uac12\uc740 1\uac1c\uc774\uace0 \ucd9c\ub825\uac12\uc774 2\uac1c\uc774\ubbc0\ub85c \uac01\uac01\uc758 \ud150\uc11c\uad6c\uc870\ub294 [x], [y1, y2]\ub77c\ub294 \uac83\uc774\ub2e4. \uc2e0\uacbd\ub9dd\uc758 \ub9c8\uc9c0\ub9c9 \uc740\ub2c9\uce35\uc758 \ub274\ub7f0\uac1c\uc218\ub294 \ucd9c\ub825 \uac1c\uc218\uc640 \ub3d9\uc77c\ud558\ubbc0\ub85c 2\uac1c\uc774\ub2e4. \ucf54\ub4dc\ub97c \ubcf4\uc790. \uba3c\uc800 \ud544\uc694\ud55c \ud328\ud0a4\uc9c0\uc758 \uc784\ud3ec\ud2b8\uc774\ub2e4. \ud30c\uc774\ud1a0\uce58\ub97c \uc0ac\uc6a9\ud55c \uc608\uc774\ub2e4. import torch import torch.nn as nn import torch.optim as optim import torch.nn.init as init &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=8378\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;\uc785\ub825 1\uac1c\uc640 \ucd9c\ub825 2\uac1c\uc5d0 \ub300\ud55c \uc120\ud615\ud68c\uadc0 \uc2e0\uacbd\ub9dd \uad6c\uc131 (\ubcf5\ud569 \ucd9c\ub825 \/ \ub2e4\uc911 \ucd9c\ub825 \uc2e0\uacbd\ub9dd \ubaa8\ub378)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[131,132,1],"tags":[],"class_list":["post-8378","post","type-post","status-publish","format-standard","hentry","category-python","category-deep-machine-learning","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8378"}],"version-history":[{"count":16,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8378\/revisions"}],"predecessor-version":[{"id":9787,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/8378\/revisions\/9787"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8378"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}