{"id":1215,"date":"2023-04-16T11:50:59","date_gmt":"2023-04-16T03:50:59","guid":{"rendered":"http:\/\/www.wayln.com\/?p=1215"},"modified":"2023-04-16T13:06:15","modified_gmt":"2023-04-16T05:06:15","slug":"%e8%87%aa%e5%8a%a8%e6%b1%82%e5%af%bc%e5%8e%9f%e7%90%86%e4%b8%8e%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=1215","title":{"rendered":"\u81ea\u52a8\u6c42\u5bfc\u539f\u7406\u4e0e\u5e94\u7528"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">1<\/span> \u673a\u5668\u5b66\u4e60\u4e2d\u7684\u6c42\u5bfc<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">2<\/span> \u7b80\u5355\u51fd\u6570\u6c42\u5bfc<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u590d\u6742\u51fd\u6570\u6c42\u504f\u5bfc<\/a><\/li><\/ul><\/div>\n\n<h1><span id=\"i\">\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u6c42\u5bfc<\/span><\/h1>\n<p>\u968f\u673a\u68af\u5ea6\u4e0b\u964d\u6cd5\uff08SGD\uff09\u662f\u8bad\u7ec3\u6df1\u5ea6\u5b66\u4e60\u6a21\u578b\u5e38\u7528\u7684\u4f18\u5316\u65b9\u6cd5\uff0c\u901a\u8fc7\u68af\u5ea6\u7684\u5b9a\u4e49\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0c\u68af\u5ea6\u7684\u6c42\u89e3\u5176\u5b9e\u5c31\u662f\u6c42\u51fd\u6570\u504f\u5bfc\u7684\u95ee\u9898\uff0c\u5bfc\u6570\u5728\u4e25\u683c\u610f\u4e49\u4e0a\u8bf4\u662f\u4e00\u5143\u7684\u504f\u5bfc<br \/>\nTensorFolow\u7684\u81ea\u52a8\u6c42\u5bfc\u5c31\u662f\u57fa\u4e8e\u8fd4\u4e61\u6a21\u5f0f\u6570\u503c\u5fae\u5206\u7684\uff0c\u5c31\u662f\u6211\u4eec\u8bf4\u7684BP\u7b97\u6cd5\uff0c\u5176\u539f\u7406\u5c31\u662f\u94fe\u5f0f\u6cd5\u5219\u3002\u5b9e\u73b0\u7684\u65b9\u5f0f\u662f\u5229\u6c38\u53cd\u5411\u4f20\u64ad\u4e0e\u94fe\u5f0f\u6cd5\u5219\u5efa\u7acb\u4e00\u5f20\u5bf9\u5e94\u539f\u8ba1\u7b97\u56fe\u7684\u68af\u5ea6\u56fe\uff0c\u5bfc\u6570\u53ea\u662f\u53e6\u5916\u4e00\u5f20\u8ba1\u7b97\u56fe\uff0c\u53ef\u4ee5\u518d\u6b21\u8fdb\u884c\u53cd\u5411\u4f20\u9012\uff0c\u5bf9\u5bfc\u6570\u8fdb\u884c\u518d\u6c42\u5bfc\u4ee5\u5f97\u5230\u66f4\u9ad8\u9636\u7684\u5bfc\u6570\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u4ec5\u9700\u8981\u4e00\u4e2a\u94b1\u7bb1\u8fc7\u7a0b\u548c\u6cd5\u76f8\u8ba1\u7b97\u5c31\u53ef\u4ee5\u8ba1\u7b97\u6240\u6709\u53c2\u6570\u7684\u5bfc\u6570\u6216\u68af\u5ea6\u3002<br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2023\/04\/wp_editor_md_9a84fbbc5c768d5c258885fe50754fb8.jpg\"><img decoding=\"async\" src=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2023\/04\/wp_editor_md_9a84fbbc5c768d5c258885fe50754fb8.jpg\" alt=\"\" \/><\/a><br \/>\n<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2023\/04\/wp_editor_md_960da49d509257fefbe89359d608c6cf.jpg\"><img decoding=\"async\" src=\"http:\/\/www.wayln.com\/wp-content\/uploads\/2023\/04\/wp_editor_md_960da49d509257fefbe89359d608c6cf.jpg\" alt=\"\" \/><\/a><\/p>\n<h1><span id=\"i-2\">\u7b80\u5355\u51fd\u6570\u6c42\u5bfc<\/span><\/h1>\n<p>\u5728\u5373\u65f6\u6267\u884c\u6a21\u5f0f\u4e0b\uff0cTensorFlow\u5f15\u5165\u4e86tf.GradientTape()\u8fd9\u4e2a\u201c\u6c42\u5bfc\u8bb0\u5f55\u5668\u201d\u6765\u5b9e\u73b0\u81ea\u52a8\u6c42\u5bfc\u3002<\/p>\n<pre><code class=\"language-Charp line-numbers\">var x = tf.Variable(5.0, dtype: TF_DataType.TF_FLOAT);\n            using var tape = tf.GradientTape();\/\/\u5728\u8be5\u8bed\u53e5\u540e\u9762\u533a\u57df\u7684\u6240\u6709\u8ba1\u7b97\u6b65\u9aa4\u90fd\u4f1a\u88ab\u8bb0\u5f55\u4ee5\u7528\u4e8e\u6c42\u5bfc\n            var y = tf.square(x) + tf.multiply(x, 6.0f); \/\/y=x*x+6*x\n            var y_grad = tape.gradient(y, x);\/\/\u8ba1\u7b97\u5173\u4e8eX\u7684\u5bfc\u6570y'=2*x+6\n<\/code><\/pre>\n<h1><span id=\"i-3\">\u590d\u6742\u51fd\u6570\u6c42\u504f\u5bfc<\/span><\/h1>\n<p>\u591a\u5143\u51fd\u6570\u7684\u504f\u5bfc\u6570\u4ee5\u53ca\u5bf9\u5411\u91cf\u6216\u77e9\u9635\u8fdb\u884c\u6c42\u5bfc\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c55\u793a\u5982\u4f55\u4f7f\u7528tf.GradientTape()\u8ba1\u7b97\u51fd\u6570<\/p>\n<div class=\"katex math multi-line no-emojify\">L(w,b)=\\begin{Vmatrix}Xw+b-y\\end{Vmatrix}^2<\/p>\n<\/div>\n<p><span class=\"katex math inline\">X=\\left[\\begin{array}{rr}0.5&amp;-0.6&#92;\\0.75&amp;1.1\\end{array}\\right] ,Y=\\left[\\begin{array}<br \/>\n{rr}1&#92;\\2 \\end{array}\\right]<\/span><\/p>\n<p>\u5728 <span class=\"katex math inline\">w=(1,2)^T,b=1<\/span> \u65f6\u5206\u522b\u5bf9w\u3001b\u7684\u504f\u5bfc\u6570<\/p>\n<pre><code class=\"language-CSharp line-numbers\"> var x = tf.constant(new[,] { { 1.0f, 2.0f }, { 3.0f, 4.0f } });\n            var y = tf.constant(new[,] { { 1 }, { 2 } });\n            var w = tf.Variable(new[,] { { 1.0f }, { 2.0f } });\n            var b = tf.Variable(1.0f);\n            using var tape = tf.GradientTape();\n            var L = tf.reduce_sum(tf.square(tf.matmul(x, w) + b - y));\n            var (w_grad, b_grad) = tape.gradient(L, (w, b));\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u673a\u5668\u5b66\u4e60\u4e2d\u7684\u6c42\u5bfc2 \u7b80\u5355\u51fd\u6570\u6c42\u5bfc3 \u590d\u6742\u51fd\u6570\u6c42\u504f\u5bfc \u673a\u5668\u5b66\u4e60\u4e2d\u7684\u6c42\u5bfc \u968f\u673a\u68af\u5ea6\u4e0b\u964d\u6cd5\uff08SG [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50,49,2],"tags":[],"class_list":["post-1215","post","type-post","status-publish","format-standard","hentry","category-tensorflow","category-49","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1215"}],"version-history":[{"count":16,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1215\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1215\/revisions\/1231"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}