{"id":656,"date":"2021-12-23T15:46:32","date_gmt":"2021-12-23T07:46:32","guid":{"rendered":"http:\/\/139.9.1.231\/?p=656"},"modified":"2021-12-23T15:48:31","modified_gmt":"2021-12-23T07:48:31","slug":"ica","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2021\/12\/23\/ica\/","title":{"rendered":"ICA\u72ec\u7acb\u6210\u5206\u5206\u6790"},"content":{"rendered":"\n<h3 id=\"ica\u7684\u6570\u5b66\u63a8\u5bfc\">ICA\u7684\u6570\u5b66\u63a8\u5bfc<a href=\"http:\/\/skyhigh233.com\/blog\/2017\/04\/01\/ica-math\/#ica%E7%9A%84%E6%95%B0%E5%AD%A6%E6%8E%A8%E5%AF%BC\"><\/a><\/h3>\n\n\n\n<p>ICA\u7b97\u6cd5\u7684\u601d\u8def\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u63a8\u5bfc\u8fc7\u7a0b\u6bd4\u8f83\u590d\u6742\uff0c\u672c\u6587\u53ea\u662f\u68b3\u7406\u4e86\u63a8\u7406\u8def\u7ebf\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u6709n\u4e2a\u6df7\u5408\u4fe1\u53f7\u6e90\\(X\\subset{R^{n}}\\)\u548cn\u4e2a\u72ec\u7acb\u4fe1\u53f7\\(S\\subset{R^{n}}\\)\uff0c\u4e14\u6bcf\u4e2a\u6df7\u5408\u4fe1\u53f7\u53ef\u4ee5\u7531n\u4e2a\u72ec\u7acb\u4fe1\u53f7\u7684\u7ebf\u6027\u7ec4\u5408\u4ea7\u751f\uff0c\u5373\uff1a\\(X=\\left[ \\begin{matrix} x_1&amp;\\\\ x_2&amp;\\\\ &#8230;&amp;\\\\ x_n&amp; \\end{matrix} \\right]S=\\left[ \\begin{matrix} s_1&amp;\\\\ s_2&amp;\\\\ &#8230;&amp;\\\\ s_n&amp; \\end{matrix} \\right]X=AS =&gt; S=WX,W=A^{-1}\\)<\/p>\n\n\n\n<p>\u5047\u8bbe\u6211\u4eec\u73b0\u5728\u5bf9\u4e8e\u6bcf\u4e2a\u6df7\u5408\u4fe1\u53f7\uff0c\u53ef\u4ee5\u53d6\u5f97m\u4e2a\u6837\u672c\uff0c\u5219\u6709\u5982\u4e0bn*m\u7684\u6837\u672c\u77e9\u9635\uff1a\\(D=\\left[ \\begin{matrix} d_{11}&amp;d_{12}&amp;&#8230;&amp;d_{1m}&amp;\\\\ &#8230;&amp;\\\\ d_{n1}&amp;d_{n2}&amp;&#8230;&amp;d_{nm}\\\\ \\end{matrix} \\right]\\)<\/p>\n\n\n\n<p>\u7531\u4e8eS\u4e2d\u7684n\u4e2a\u72ec\u7acb\u4fe1\u53f7\u662f\u76f8\u4e92\u72ec\u7acb\u7684\uff0c\u5219\u5b83\u4eec\u7684\u8054\u5408\u6982\u7387\u5bc6\u5ea6\u4e3a\uff1a$$p_S(s)=\\Pi_{i=1}^{n}p_{s_i}(s_i)$$<\/p>\n\n\n\n<p>\u7531\u4e8e\\(s=Wx\\)\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u5f97\u51fa\uff1a\\(p_X(x)=F^{&#8216;}_{X}(x)=|\\frac{\\partial{s}}{\\partial{x}}|*p_S(s(x))=|W|*\\Pi_{i=1}^{n}p_{s_i}(w_ix)\\)<\/p>\n\n\n\n<p>\u8003\u8651\u76ee\u524d\u6709m\u4e2a\u6837\u672c\uff0c\u5219\u53ef\u4ee5\u5f97\u5230\u6240\u6709\u6837\u672c\u7684\u4f3c\u7136\u51fd\u6570\uff1a\\(L=\\Pi_{i=1}^{m}(|W|*\\Pi_{j=1}^{n}p_{s_j}(w_{j\\cdot}d_{\\cdot{i}}))\\)<\/p>\n\n\n\n<p>\u53d6\u5bf9\u6570\u4e4b\u540e\uff0c\u5f97\u5230\uff1a\\(lnL=\\Sigma_{i=1}^{m}\\Sigma_{j=1}^{n}lnp_{s_j}(w_{j\\cdot}d_{\\cdot{i}})+mln|W|\\)<\/p>\n\n\n\n<p>\u4e4b\u540e\u53ea\u8981\u901a\u8fc7<strong>\u68af\u5ea6\u4e0b\u964d\u6cd5<\/strong>\u5bf9lnL\u6c42\u51fa\u6700\u5927\u503c\u5373\u53ef\uff0c\u5373\u6c42\u4f7f\u5f97\u8be5\u6837\u672c\u51fa\u73b0\u6982\u7387\u6700\u5927\u7684\u53c2\u6570W\u3002<br>\u6b64\u65f6\u5047\u8bbe\u6211\u4eec\u4e0a\u9762\u7684\u5404\u4e2a\u72ec\u7acb\u4fe1\u53f7\u7684<strong>\u6982\u7387\u5206\u5e03\u51fd\u6570<\/strong>\u4e3a<strong>sigmoid\u51fd\u6570<\/strong>\uff0c\u4f46\u662f\u4e0d\u786e\u5b9a\u8fd9\u91cc\u7684<strong>g\u51fd\u6570<\/strong>\u548c\u4e0b\u9762<strong>fastICA\u4e2d\u7684g\u51fd\u6570<\/strong>\u662f\u5426\u6709\u5173\u8054\uff09\uff1a\\(F_{s_i}(s_i)=\\frac{1}{1+e^{-s_i}}\\)<\/p>\n\n\n\n<p>\u6700\u7ec8\uff0c\u6211\u4eec\u6c42\u5f97\uff1a\\(\\frac{\\partial{lnL}}{\\partial{W}}=Z^TD+\\frac{m}{|W|}(W^*)^T\\)<\/p>\n\n\n\n<p>\u5176\u4e2d\uff1a$$Z=g(K)=\\left[ \\begin{matrix} g(k_{11})&amp;g(k_{12})&amp;&#8230;&amp;g(k_{1m})&amp;\\\\ &#8230;&amp;\\\\ g(k_{n1})&amp;g(k_{n2})&amp;&#8230;&amp;g(k_{nm})\\\\ \\end{matrix} \\right]g(x)=\\frac{1-e^x}{1+e^x}K=WDD=\\left[ \\begin{matrix} d_{11}&amp;d_{12}&amp;&#8230;&amp;d_{1m}&amp;\\\\ &#8230;&amp;\\\\ d_{n1}&amp;d_{n2}&amp;&#8230;&amp;d_{nm}\\\\ \\end{matrix} \\right]$$<\/p>\n\n\n\n<p>\u7531\u4e8e\u4f34\u968f\u77e9\u9635\u5177\u6709\u4ee5\u4e0b\u6027\u8d28\uff1a$$WW^*=|W|I$$<\/p>\n\n\n\n<p>\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u6c42\u51fa\uff1a\\(\\frac{\\partial{lnL}}{\\partial{W}}=Z^TD+m(W^{-1})^T\\)<\/p>\n\n\n\n<p>\u56e0\u6b64\u53ef\u4ee5\u5f97\u5230\u68af\u5ea6\u4e0b\u964d\u66f4\u65b0\u516c\u5f0f\uff1a$$W=W+\\alpha(Z^TD+m(W^{-1})^T)$$<\/p>\n\n\n\n<p>\u81f3\u6b64\uff0cICA\u7684\u57fa\u672c\u63a8\u7406\u5c31\u6b64\u7ed3\u675f\u3002\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e0bfastICA\u7684\u7b97\u6cd5\u8fc7\u7a0b\uff08\u6ca1\u6709\u6570\u5b66\u63a8\u7406\uff09\u3002<\/p>\n\n\n\n<h3 id=\"fastica\u7684\u7b97\u6cd5\u6b65\u9aa4\">fastICA\u7684\u7b97\u6cd5\u6b65\u9aa4<a href=\"http:\/\/skyhigh233.com\/blog\/2017\/04\/01\/ica-math\/#fastica%E7%9A%84%E7%AE%97%E6%B3%95%E6%AD%A5%E9%AA%A4\"><\/a><\/h3>\n\n\n\n<p>\u89c2\u6d4b\u4fe1\u53f7\u6784\u6210\u4e00\u4e2a\u6df7\u5408\u77e9\u9635\uff0c\u901a\u8fc7\u6570\u5b66\u7b97\u6cd5\u8fdb\u884c\u5bf9\u6df7\u5408\u77e9\u9635A\u7684\u9006\u8fdb\u884c\u8fd1\u4f3c\u6c42\u89e3\u5206\u4e3a\u4e09\u4e2a\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<ul><li>\u53bb\u5747\u503c\u3002\u53bb\u5747\u503c\u4e5f\u5c31\u662f\u4e2d\u5fc3\u5316\uff0c\u5b9e\u8d28\u662f\u4f7f\u4fe1\u53f7X\u5747\u503c\u662f\u96f6\u3002<\/li><li>\u767d\u5316\u3002\u767d\u5316\u5c31\u662f\u53bb\u76f8\u5173\u6027\u3002<\/li><li>\u6784\u5efa\u6b63\u4ea4\u7cfb\u7edf\u3002<\/li><\/ul>\n\n\n\n<p>\u5728\u5e38\u7528\u7684ICA\u7b97\u6cd5\u57fa\u7840\u4e0a\u5df2\u7ecf\u6709\u4e86\u4e00\u4e9b\u6539\u8fdb\uff0c\u5f62\u6210\u4e86fastICA\u7b97\u6cd5\u3002fastICA\u5b9e\u9645\u4e0a\u662f\u4e00\u79cd\u5bfb\u627e\\(w^Tz(Y=w^Tz)\\)\u7684\u975e\u9ad8\u65af\u6700\u5927\u7684\u4e0d\u52a8\u70b9\u8fed\u4ee3\u65b9\u6848\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ol><li>\u89c2\u6d4b\u6570\u636e\u7684\u4e2d\u5fc3\u5316(\u53bb\u5747\u503c)<\/li><li>\u6570\u636e\u767d\u5316(\u53bb\u76f8\u5173)\uff0c\u5f97\u5230z<\/li><li>\u9009\u62e9\u9700\u8981\u987e\u53ca\u7684\u72ec\u7acb\u6e90\u7684\u4e2a\u6570n<\/li><li>\u968f\u673a\u9009\u62e9\u521d\u59cb\u6743\u91cdW\uff08\u975e\u5947\u5f02\u77e9\u9635\uff09<\/li><li>\u9009\u62e9\u975e\u7ebf\u6027\u51fd\u6570g<\/li><li>\u8fed\u4ee3\u66f4\u65b0\uff1a<ul><li>\\(w_i \\leftarrow E\\{zg(w_i^Tz)\\}-E\\{g^{&#8216;}(w_i^Tz)\\}w\\)<\/li><li>\\(W \\leftarrow (WW^T)^{-1\/2}W\\)<\/li><\/ul><\/li><li>\u5224\u65ad\u6536\u655b\uff0c\u662f\u4e0b\u4e00\u6b65\uff0c\u5426\u5219\u8fd4\u56de\u6b65\u9aa46<\/li><li>\u8fd4\u56de\u8fd1\u4f3c\u6df7\u5408\u77e9\u9635\u7684\u9006\u77e9\u9635<\/li><\/ol>\n\n\n\n<p>\u4ee3\u7801\u5b9e\u73b0<br>\u57fa\u4e8epython2.7\uff0cmatplotlib\uff0cnumpy\u5b9e\u73b0ICA\uff0c\u4e3b\u8981\u53c2\u8003sklean\u7684FastICA\u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>import math<br>import random<br>import matplotlib.pyplot as plt<br>from numpy import *<\/p>\n\n\n\n<p>n_components = 2<\/p>\n\n\n\n<p>def f1(x, period = 4):<br>return 0.5<em>(x-math.floor(x\/period)<\/em>period)<\/p>\n\n\n\n<p>def create_data():<br>#data number<br>n = 500<br>#data time<br>T = [0.1*xi for xi in range(0, n)]<br>#source<br>S = array([[sin(xi) for xi in T], [f1(xi) for xi in T]], float32)<br>#mix matrix<br>A = array([[0.8, 0.2], [-0.3, -0.7]], float32)<br>return T, S, dot(A, S)<\/p>\n\n\n\n<p>def whiten(X):<br>#zero mean<br>X_mean = X.mean(axis=-1)<br>X -= X_mean[:, newaxis]<br>#whiten<br>A = dot(X, X.transpose())<br>D , E = linalg.eig(A)<br>D2 = linalg.inv(array([[D[0], 0.0], [0.0, D[1]]], float32))<br>D2[0,0] = sqrt(D2[0,0]); D2[1,1] = sqrt(D2[1,1])<br>V = dot(D2, E.transpose())<br>return dot(V, X), V<\/p>\n\n\n\n<p>def _logcosh(x, fun_args=None, alpha = 1):<br>gx = tanh(alpha * x, x); g_x = gx ** 2; g_x -= 1.; g_x *= -alpha<br>return gx, g_x.mean(axis=-1)<\/p>\n\n\n\n<p>def do_decorrelation(W):<br>#black magic<br>s, u = linalg.eigh(dot(W, W.T))<br>return dot(dot(u * (1. \/ sqrt(s)), u.T), W)<\/p>\n\n\n\n<p>def do_fastica(X):<br>n, m = X.shape; p = float(m); g = _logcosh<br>#black magic<br>X *= sqrt(X.shape[1])<br>#create w<br>W = ones((n,n), float32)<br>for i in range(n):<br>for j in range(i):<br>W[i,j] = random.random()<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#compute W\nmaxIter = 200\nfor ii in range(maxIter):\n    gwtx, g_wtx = g(dot(W, X))\n    W1 = do_decorrelation(dot(gwtx, X.T) \/ p - g_wtx&#91;:, newaxis] * W)\n    lim = max( abs(abs(diag(dot(W1, W.T))) - 1) )\n    W = W1\n    if lim &lt; 0.0001:\n        break\nreturn W<\/code><\/pre>\n\n\n\n<p>def show_data(T, S):<br>plt.plot(T, [S[0,i] for i in range(S.shape[1])], marker=&#8221;*&#8221;)<br>plt.plot(T, [S[1,i] for i in range(S.shape[1])], marker=&#8221;o&#8221;)<br>plt.show()<\/p>\n\n\n\n<p>def main():<br>T, S, D = create_data()<br>Dwhiten, K = whiten(D)<br>W = do_fastica(Dwhiten)<br>#Sr: reconstructed source<br>Sr = dot(dot(W, K), D)<br>show_data(T, D)<br>show_data(T, S)<br>show_data(T, Sr)<\/p>\n\n\n\n<p>if <strong>name<\/strong> == &#8220;<strong>main<\/strong>&#8220;:<br>main()<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u53c2\u8003\uff1a<\/p>\n\n\n\n<p>http:\/\/skyhigh233.com\/blog\/2017\/04\/01\/ica-math\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ICA\u7684\u6570\u5b66\u63a8\u5bfc ICA\u7b97\u6cd5\u7684\u601d\u8def\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u63a8\u5bfc\u8fc7\u7a0b\u6bd4\u8f83\u590d\u6742\uff0c\u672c\u6587\u53ea\u662f\u68b3\u7406\u4e86\u63a8\u7406\u8def\u7ebf\u3002 \u5047\u8bbe\u6211\u4eec\u6709n\u4e2a\u6df7\u5408 &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2021\/12\/23\/ica\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">ICA\u72ec\u7acb\u6210\u5206\u5206\u6790<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,12],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/656"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":12,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/656\/revisions"}],"predecessor-version":[{"id":668,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/656\/revisions\/668"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}