matlab練習程式(LMS)

來源:互聯網
上載者:User
%LMS演算法示範(matlab)%設定參數,N為採樣個數,u為步長clear,clc;N=16;u=0.1;%設定迭代次數kk=1000;%pha為隨機雜訊的平均功率rk=randn(1,k)/2;%%常態分佈的隨機矩陣pha=mean(rk);%%求元素平均值%設定起始權值wk(1,:)=[0 0];%用LMS演算法迭代求最佳權值for i=1:k    xk(i,:)=[sin(2*pi*i/N) sin(2*pi*(i-1)/N)]+rk(i);%輸入訊號    yk(i)=xk(i,:)*wk(i,:)';%輸出訊號    dk(i)=2*cos(2*pi*i/N);%期望訊號    err(i)=dk(i)-yk(i);%誤差    wk(i+1,:)=wk(i,:)+2*u*err(i)*xk(i,:);%權值迭代end[x,y]=meshgrid([-2:0.1:8],[-10:0.1:0]);%求效能表面z=(0.5+pha)*(x.^2+y.^2)+x.*y*cos(2*pi/N)+2*y*sin(2*pi/N)+2;%求理論最佳權值x1,y1x1=2*cos(2*pi/N)*sin(2*pi/N)/((1+pha)^2-(cos(2*pi/N))^2);y1=-2*(1+2*pha)*sin(2*pi/N)/((1+pha)^2-(cos(2*pi/N))^2);%畫效能表面的等高線figure,contour(x,y,z,[0.78 1.9 6.3 13.6 23.8 37]);%%等值線圖%畫迭代時權值的變化hold on;plot(wk(:,1),wk(:,2),'r');%標註最佳權值的位置hold on;plot(x1,y1,'*');%繪製誤差與迭代次數的圖figure,plot(err);

別人的程式,效果不錯。對照原理與代碼能更好理解。

參考:

1.http://zhidao.baidu.com/question/53628331

2.http://www.cnblogs.com/LeftNotEasy/archive/2010/12/05/mathmatic_in_machine_learning_1_regression_and_gradient_descent.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.