{"id":2099,"date":"2023-04-01T22:14:02","date_gmt":"2023-04-01T14:14:02","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2099"},"modified":"2023-04-06T13:56:45","modified_gmt":"2023-04-06T05:56:45","slug":"fundamentals-of-deep-learning-linear-algebra-feature-decomposition-and-implementation-of-numpy-and-scipy","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/fundamentals-of-deep-learning-linear-algebra-feature-decomposition-and-implementation-of-numpy-and-scipy\/","title":{"rendered":"\u6df1\u5ea6\u5b66\u4e60\u57fa\u7840\uff1a\u7ebf\u6027\u4ee3\u6570(1)_\u7279\u5f81\u5206\u89e3\u53canumpy\u3001scipy\u5b9e\u73b0"},"content":{"rendered":"<h2>\u7279\u5f81\u5206\u89e3\u7684\u610f\u4e49<\/h2>\n<p>\u6709\u65f6\uff0c\u6211\u4eec\u4f1a\u5c06\u73b0\u5b9e\u4e2d\u7684\u67d0\u4e9b\u4e8b\u7269\u62bd\u8c61\u6210\u77e9\u9635\u7684\u5f62\u5f0f\uff0c\u4f8b\u5982\u53ef\u4ee5\u5c06\u4e00\u5f20\u56fe\u7247\u62bd\u8c61\u6210\u4e00\u4e2a\u50cf\u7d20\u503c\u7ec4\u6210\u7684\u77e9\u9635\u3002\u6b64\u65f6\uff0c\u6211\u4eec\u4e5f\u8bb8\u5e0c\u671b\u4e2d\u5c06\u77e9\u9635\u5206\u89e3\u6210\u591a\u4e2a\u7ec4\u6210\u90e8\u5206\uff0c\u8fd9\u4e9b\u7ec4\u6210\u90e8\u5206\u4ee3\u8868\u4e86\u8fd9\u4e2a\u77e9\u9635\u7684\u7279\u5f81\uff0c\u8fd9\u5c31\u662f\u7279\u5f81\u5206\u89e3\u7684\u610f\u4e49\u3002<\/p>\n<p><!-- more --><\/p>\n<h2>\u7279\u5f81\u503c\u4e0e\u7279\u5f81\u5411\u91cf<\/h2>\n<p>\u7ed9\u5b9a\u65b9\u9635$A$\uff0c\u5982\u679c\u5b58\u5728\u5411\u91cf$v$\u548c\u6807\u91cf$\\lambda$\uff0c\u4f7f\u5f97<\/p>\n<p>$$Av=\u03bbv$$<\/p>\n<p>\u90a3\u4e48$v$\u79f0\u4e3a\u77e9\u9635A\u7684<strong>\u7279\u5f81\u5411\u91cf<\/strong>\uff0c$\\lambda$\u79f0\u4e3a\u7279\u5f81\u5411\u91cf$v$\u5bf9\u5e94\u7684<strong>\u7279\u5f81\u503c<\/strong>\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u5982\u679c$v$\u662f\u77e9\u9635$A$\u7684\u7279\u5f81\u5411\u91cf\uff0c\u90a3\u4e48\u5bf9v\u7f29\u653e\u4efb\u610f\u500d\uff0c\u5373$sv(S \\in {\\Bbb {R}}, S \\neq 0)$\u5747\u662f\u77e9\u9635$A$\u7684\u7279\u5f81\u5411\u91cf\uff0c\u56e0\u6b64\u901a\u5e38\u53ea\u8003\u8651<strong>\u5355\u4f4d\u7279\u5f81\u5411\u91cf<\/strong>\u3002<\/p>\n<h2>\u7279\u5f81\u5206\u89e3<\/h2>\n<p>\u5047\u8bbe\u77e9\u9635$A$\u6709n\u4e2a\u7279\u5f81\u65e0\u5173\u7684\u7279\u5f81\u5411\u91cf${v_1, v_2, &#8230;, v_n}$\uff0c\u5bf9\u5e94\u7684\u7279\u5f81\u503c\u4e3a${\\lambda_1, \\lambda_2, &#8230;, \\lambda_n}$\u3002<\/p>\n<p>\u6211\u4eec\u5c06\u7279\u5f81\u5411\u91cf\u8fde\u63a5\u6210\u4e00\u4e2a\u77e9\u9635\uff0c\u4f7f\u5f97\u6bcf\u4e00\u5217\u662f\u4e00\u4e2a\u7279\u5f81\u5411\u91cf\uff1a$V = [v_1, v_2, &#8230;, v_n]$\u3002\u540c\u6837\u7684\uff0c\u6211\u4eec\u5c06\u7279\u5f81\u503c\u8fde\u63a5\u6210\u4e00\u4e2a\u5411\u91cf$\\lambda = [\\lambda_1, \\lambda_2, &#8230;, \\lambda_n]$\u3002\u53ef\u4ee5\u5f97\u5230\u4e0b\u5f0f\uff1a<\/p>\n<p>$$AV = Vdiag(\\lambda)$$<\/p>\n<p>\u5176\u4e2d$diag(\\lambda)$\u662f\u5411\u91cf$\\lambda$\u5bf9\u5e94\u7684\u5bf9\u89d2\u77e9\u9635\u3002\u4ee4<\/p>\n<p>$$AVV^{-1} = Vdiag(\\lambda)V^{-1}$$<\/p>\n<p>\u5373<\/p>\n<p>$$A = Vdiag(\\lambda)V^{-1}$$<\/p>\n<p>\u6b64\u65f6\uff0c\u77e9\u9635$A$\u4fbf\u53ef\u4ee5\u5206\u89e3\u4e3a\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u7684\u4e58\u79ef\uff0c\u79f0\u4e3a<strong>\u7279\u5f81\u5206\u89e3<\/strong>\u3002<\/p>\n<h2>\u6b63\u4ea4\u77e9\u9635<\/h2>\n<p>\u5982\u679c$AA^T = E$\uff08$E$\u4e3a\u5355\u4f4d\u77e9\u9635\uff0c$A^T$\u8868\u793a\u77e9\u9635$A$\u7684\u8f6c\u7f6e\u77e9\u9635\uff09\u6216$A^TA=E$\uff0c\u5219$n$\u9636\u5b9e\u77e9\u9635$A$\u79f0\u4e3a\u6b63\u4ea4\u77e9\u9635\u3002<\/p>\n<h2>\u5b9e\u5bf9\u79f0\u77e9\u9635\u7684\u7279\u5f81\u5206\u89e3<\/h2>\n<p>\u4e0d\u662f\u6bcf\u4e2a\u77e9\u9635\u90fd\u53ef\u4ee5\u5206\u89e3\u6210\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\u3002\u5373\u4f7f\u7279\u5f81\u5206\u89e3\u5b58\u5728\uff0c\u4e5f\u6709\u53ef\u80fd\u6d89\u53ca\u5230\u590d\u6570\u3002\u4f46\u5bf9\u4e8e<em>\u5b9e\u5bf9\u79f0\u77e9\u9635<\/em>\u6765\u8bf4\uff0c\u5176\u5fc5\u53ef\u4ee5\u5206\u89e3\u6210<strong>\u5b9e\u7279\u5f81\u503c<\/strong>\u548c<strong>\u5b9e\u7279\u5f81\u5411\u91cf<\/strong>\u3002<\/p>\n<p>\u4ee4<\/p>\n<p>$$A = Q \\Lambda Q^T$$<\/p>\n<p>\u5176\u4e2d$Q$\u662f\u77e9\u9635$A$\u7684\u7279\u5f81\u5411\u91cf\u7ec4\u6210\u7684\u6b63\u4ea4\u77e9\u9635\uff0c$\\Lambda$\u662f\u5bf9\u89d2\u77e9\u9635\u3002\u7279\u5f81\u503c$\\Lambda<em>{i,i}$\u5bf9\u5e94\u7684\u7279\u5f81\u5411\u91cf\u662f\u77e9\u9635$Q$\u7684\u7b2c$i$\u5217\uff0c\u8bb0\u4f5c$Q<\/em>{:,i}$\u3002\u56e0\u4e3a$Q$\u662f\u6b63\u4ea4\u77e9\u9635\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06$A$\u770b\u4f5c\u662f\u6cbf\u65b9\u5411$v_i$\u5ef6\u4f38$\\lambda_i$\u500d\u7684\u7a7a\u95f4\u3002<\/p>\n<h2>\u5b9e\u5bf9\u79f0\u77e9\u9635\u5728\u4e8c\u6b21\u65b9\u7a0b\u4e2d\u7684\u5e94\u7528<\/h2>\n<p>\u5bf9\u4e8e\u4e8c\u6b21\u65b9\u7a0b<\/p>\n<p>$$ f(x) = x^TAx, ||x||_2 = 1$$<\/p>\n<p>\u5f53$x$\u662f\u7279\u5f81\u5411\u91cf\u65f6\uff0c$f(x)$\u5c31\u662f$x$\u5bf9\u5e94\u7684\u7279\u5f81\u503c\u3002\u56e0\u6b64\u5728$x$\u662f\u5355\u4f4d\u5411\u91cf\u7684\u9650\u5236\u4e0b\uff0c\u51fd\u6570$f(x)$\u7684\u6700\u5927\u503c\u5c31\u662f\u6700\u5927\u7279\u5f81\u503c\uff0c\u6700\u5c0f\u503c\u5c31\u662f\u6700\u5c0f\u7279\u5f81\u503c\u3002<\/p>\n<h2>\u6b63\u5b9a\u3001\u534a\u6b63\u5b9a\u3001\u8d1f\u5b9a\u3001\u534a\u8d1f\u5b9a<\/h2>\n<ul>\n<li>\u6b63\u5b9a\uff1a\u6240\u6709\u7279\u5f81\u503c\u90fd\u662f\u6b63\u6570\uff0c\u5373$x^TAx &gt; 0$\u3002<\/li>\n<li>\u534a\u6b63\u5b9a\uff1a\u6240\u6709\u7279\u5f81\u503c\u90fd\u662f\u975e\u8d1f\u6570\uff0c\u5373$x^TAx \\geq 0$\u3002<\/li>\n<li>\u8d1f\u5b9a\uff1a\u6240\u6709\u7279\u5f81\u503c\u90fd\u662f\u8d1f\u6570\uff0c\u5373$x^TAx &lt; 0$\u3002<\/li>\n<li>\u534a\u8d1f\u5b9a\uff1a\u6240\u6709\u7279\u5f81\u503c\u90fd\u662f\u975e\u8d1f\u6570\uff0c\u5373$x^TAx \\leq 0$\u3002<\/li>\n<\/ul>\n<h2>Python\u5b9e\u73b0<\/h2>\n<h3>Numpy<\/h3>\n<pre><code class=\"language-python\">import numpy as np\n\nA = np.array([[1,2,3],\n             [4,5,6],\n             [7,8,9]])\n# \u8ba1\u7b97\u7279\u5f81\u503c\nprint(np.linalg.eigvals(A))\n# \u540c\u65f6\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\neigvals, eigvectors = np.linalg.eig(A)\nprint(eigvals)\nprint(eigvectors)<\/code><\/pre>\n<h3>Scipy<\/h3>\n<pre><code class=\"language-python\">import numpy as np\nimport scipy as sp\nfrom scipy import linalg\n\nA = np.array([[1,2,3],\n             [4,5,6],\n             [7,8,9]])\n# \u8ba1\u7b97\u7279\u5f81\u503c\nprint(sp.linalg.eigvals(A))\n# \u540c\u65f6\u8ba1\u7b97\u7279\u5f81\u503c\u548c\u7279\u5f81\u5411\u91cf\neigvals, eigvectors = sp.linalg.eig(A)\nprint(eigvals)\nprint(eigvectors)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7279\u5f81\u5206\u89e3\u7684\u610f\u4e49 \u6709\u65f6\uff0c\u6211\u4eec\u4f1a\u5c06\u73b0\u5b9e\u4e2d\u7684\u67d0\u4e9b\u4e8b\u7269\u62bd\u8c61\u6210\u77e9\u9635\u7684\u5f62\u5f0f\uff0c\u4f8b\u5982\u53ef\u4ee5\u5c06\u4e00\u5f20\u56fe\u7247\u62bd\u8c61\u6210\u4e00\u4e2a\u50cf\u7d20\u503c\u7ec4\u6210\u7684\u77e9\u9635\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[527],"tags":[531],"class_list":["post-2099","post","type-post","status-publish","format-standard","hentry","category-ai","tag-531"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2099"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2099\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}