{"id":1323,"date":"2023-05-11T22:01:32","date_gmt":"2023-05-11T14:01:32","guid":{"rendered":"http:\/\/www.wayln.com\/?p=1323"},"modified":"2023-05-11T22:01:32","modified_gmt":"2023-05-11T14:01:32","slug":"%e8%a7%a3%e5%86%b3svd%e5%88%86%e8%a7%a3u%e5%92%8cv%e7%9a%84%e7%ac%a6%e5%8f%b7%e5%92%8cmatlab%e4%b8%8d%e5%90%8c%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=1323","title":{"rendered":"\u89e3\u51b3SVD\u5206\u89e3U\u548cV\u7684\u7b26\u53f7\u548cmatlab\u4e0d\u540c\u7684\u95ee\u9898"},"content":{"rendered":"<pre><code class=\"language-CSharp line-numbers\"> \/\/\/ &lt;summary&gt;\n        \/\/\/ Sign correction to ensure deterministic output from SVD.\n        \/\/Adjusts the columns of u and the rows of v such that the loadings in the\n       \/\/ columns in u that are largest in absolute value are always positive.\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=\"U\"&gt;&lt;\/param&gt;\n        \/\/\/ &lt;param name=\"V\"&gt;&lt;\/param&gt;\n        \/\/\/ &lt;param name=\"u_based_desion\"&gt;\u4e3b\u6210\u5206\u6570\u5927\u4e8e\u6837\u672c\u6570\u5219\u8bbe\u7f6e\u4e3afalse&lt;\/param&gt;\n        private void svd_flip(ref Matrix&lt;double&gt; U,ref Matrix&lt;double&gt; V,bool u_based_decision = true)\n        {\n            if(u_based_decision)\n            {\n                for (int j = 0; j &lt; U.ColumnCount; j++)\n                {\n                    int rowIndex = U.Column(j).AbsoluteMaximumIndex();\n                    if (U[rowIndex,j] &lt; 0)\n                    {\n                        U.SetColumn(j, U.Column(j).Multiply(-1));\n                        V.SetRow(j, V.Row(j).Multiply(-1));\n                    }\n                }\n            }\n            else\n            {\n                for (int j = 0; j &lt; V.RowCount; j++)\n                {\n                    int ColIndex = V.Row(j).AbsoluteMaximumIndex();\n                    if (V[j, ColIndex] &lt; 0)\n                    {\n                        U.SetColumn(j, U.Column(j).Multiply(-1));\n                        V.SetRow(j, V.Row(j).Multiply(-1));\n                    }\n                }\n            }\n        }\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/\/ &lt;summary&gt; \/\/\/ Sign correction to ensure deter [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,49,2],"tags":[],"class_list":["post-1323","post","type-post","status-publish","format-standard","hentry","category-c","category-49","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1323","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=1323"}],"version-history":[{"count":1,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":1324,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions\/1324"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}