首页 模拟退火算法实验

模拟退火算法实验

举报
开通vip

模拟退火算法实验模拟退火算法的Matlab实现 模拟退火算法的Matlab实现 一、主程序 clc; clear all; close all; X=[0 0;0 1;1 0;1 1]; %input Y=[0;1;1;0]; %output h=4; %hide_layer codes [x_row,x_col]=size(X); [y_row,y_col]=size(Y); W=(rand(x_col,h)-0.5)*2; V=(rand(h,y_col)-0.5)*2; test(h)=0; T=10; namita=0.9...

模拟退火算法实验
模拟退火算法的Matlab实现 模拟退火算法的Matlab实现 一、主程序 clc; clear all; close all; X=[0 0;0 1;1 0;1 1]; %input Y=[0;1;1;0]; %output h=4; %hide_layer codes [x_row,x_col]=size(X); [y_row,y_col]=size(Y); W=(rand(x_col,h)-0.5)*2; V=(rand(h,y_col)-0.5)*2; test(h)=0; T=10; namita=0.9; alpha=0.7; %initial while T>1 for i=1:x_row E=0; o1=F(X(x_row,:)*W); o2=F(o1*V); for j=1:y_col E=E+((o2(j)-Y(i,j))^2); end E1=E; %pre_E flag=1; while(flag) %loop until flag is true flag=0; n=round((x_col*h+h*y_col-1)*rand())+1; %choose one w p_delta_w=rand(); delta_w=alpha*T*p_delta_w; %change of w if n>x_col*h V(n-x_col*h)=V(n-x_col*h)+delta_w; %选中V else W(n)=W(n)+delta_w; %选中W end E2=0; o1=F(X(x_row,:)*W); o2=F(o1*V); for j=1:y_col E2=E2+((o2(j)-Y(i,j))^2); %change_E end r=rand(); p=T/(T^2+E^2); if (E2-E1)>0 if px_col*h V(n-x_col*h)=V(n-x_col*h)-delta_w; else W(n)=W(n)-delta_w; end flag=1; else end else end end end T=namita*T; %decent_T end 二、调用的F函数 function out=F(a) %F函数 [x,y]=size(a); for i=1:x for j=1:y out(i,j)=1/(1+exp(-a(i,j)));%S型函数 end end
本文档为【模拟退火算法实验】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_592359
暂无简介~
格式:doc
大小:25KB
软件:Word
页数:2
分类:
上传时间:2011-05-20
浏览量:28