日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

sklearn.decomposition.FastICA实现FastICA算法

發(fā)布時(shí)間:2024/7/23 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sklearn.decomposition.FastICA实现FastICA算法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

關(guān)于sklearn.decomposition.FastICA的介紹http://lijiancheng0614.github.io/scikit-learn/modules/generated/sklearn.decomposition.FastICA.html

import numpy as np import matplotlib.pyplot as plt from sklearn.decomposition import FastICAC = 200 # 樣本數(shù) x = np.arange(C) s1 = 2 * np.sin(0.02 * np.pi * x) # 正弦信號(hào)a = np.linspace(-2, 2, 25) s2 = np.array([a, a, a, a, a, a, a, a]).reshape(200, ) # 鋸齒信號(hào) s3 = np.array(20 * (5 * [2] + 5 * [-2])) # 方波信號(hào) s4 = 4 * (np.random.random([1, C]) - 0.5).reshape(200, ) #隨機(jī)信號(hào) """畫出4種信號(hào)""" ax1 = plt.subplot(411) ax2 = plt.subplot(412) ax3 = plt.subplot(413) ax4 = plt.subplot(414) ax1.plot(x,s1) ax2.plot(x,s2) ax3.plot(x,s3) ax4.plot(x,s4) plt.show() """將4種信號(hào)混合 其中mix矩陣是混合后的信號(hào)矩陣,shape=[4,200]""" s=np.array([s1,s2,s3,s4]) ran=2*np.random.random([4,4]) mix=ran.dot(s) ax1 = plt.subplot(411) ax2 = plt.subplot(412) ax3 = plt.subplot(413) ax4 = plt.subplot(414) ax1.plot(x,mix[0,:]) ax2.plot(x,mix[1,:]) ax3.plot(x,mix[2,:]) ax4.plot(x,mix[3,:]) plt.show()ica = FastICA(n_components=4) #獨(dú)立成分為4個(gè) mix = mix.T #將信號(hào)矩陣轉(zhuǎn)為[n_samples,n_features],即[200,4] u = ica.fit_transform(mix) # u為解混后的4個(gè)獨(dú)立成分,shape=[200,4] u = u.T # shape=[4,200] print(ica.n_iter_) # 算法迭代次數(shù) """畫出解混后的4種獨(dú)立成分""" ax1 = plt.subplot(411) ax2 = plt.subplot(412) ax3 = plt.subplot(413) ax4 = plt.subplot(414) ax1.plot(x,u[0,:]) ax2.plot(x,u[1,:]) ax3.plot(x,u[2,:]) ax4.plot(x,u[3,:]) plt.show()

還有另外一種得到獨(dú)立成分的寫法,思路是將求得的解混矩陣和混合信號(hào)矩陣相乘得到獨(dú)立成分,代碼如下:

"""前面一樣""" ica = FastICA(n_components=4) mix = mix.T ica.fit(mix) w = ica.components_ #解混矩陣,shape=[n_components, n_features],即[4,4] u = np.dot(w,mix.T) #解混矩陣和混合信號(hào)相乘得到獨(dú)立成分 print(ica.n_iter_) ax1 = plt.subplot(411) ax2 = plt.subplot(412) ax3 = plt.subplot(413) ax4 = plt.subplot(414) ax1.plot(x,u[0,:]) ax2.plot(x,u[1,:]) ax3.plot(x,u[2,:]) ax4.plot(x,u[3,:]) plt.show()

?

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的sklearn.decomposition.FastICA实现FastICA算法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。