神经网络课程设计 神经网络用于机器手臂的控制
addrs(i)=ceil(rem(((log(address+1))*HASH),memsize)); else
-drs(i)=ceil(rem(address,c*ceil(iprange/width))); memreq = c*ceil(iprange/width);
addrs(i)=ceil(rem(address,memreq)); end;
ofs=ofs+offset; op=op+wts(addrs(i)); end;
function [wts,mod]=modcmac(wts,ip,ipdim,target,beta,iprange,c,width,memsize) addrs=zeros(c,1);
quantisation=ceil(iprange/width); offset=width/c; ofs=0; sum=0.0; for i=1:c
address=0; shift=1.0; for j=1:ipdim
address=address+ceil(ip(j)/width)*shift; shift=shift*quantisation; end;
address=address+shift*i; if memsize>0
addrs(i)=ceil(rem((log(address+1)*HASH),memsize)); else
memreq = c*ceil(iprange/width); addrs(i)=ceil(rem(address,memreq)); end;
ofs=ofs+offset;
sum=sum+wts((addrs(i))); end;
delta=beta*(target-sum)/c; for i=1:c
wts(addrs(i))=wts(addrs(i))+delta; end;
mod=sum+delta*c; 程序二
function robot()
% neural networks housework
张建文 1030319100 张卜南1030319078
神经网络课程设计 神经网络用于机器手臂的控制
%use cmac simulink 2D robotic operation
% CMAC operates as a form of lookup table. Note, however, % that it generalises, i.e. is capable of producing outputs % in response to inputs not previously experienced. %5 dim input 3 dim output help robot; clf reset; pausetime=0.1; quantisation=200; c=40;
memsize=3080; pause
z = menu('select step of studying', ... '0.00001', ... '0.1',... '0.5',...
'1.0'); if z==1
seta=0.00001; else if z==2
seta=0.1; else
if z==3
seta=0.5; else
if z==4 seta=1.0; end; end; end; end; disp('') %seta=0.1; l=[0.5 0.5 0.5]; ipdim=5;
disp(sprintf('quantisation is; %d',quantisation)); disp(sprintf('acceptive field is: %d',c)); disp(sprintf('memsize is : %d',memsize)); iprange=360; width=iprange/200;
% data initial xd=zeros(200,2);
张建文 1030319100 张卜南1030319078
神经网络课程设计 神经网络用于机器手臂的控制
disp('any key to continue');
pause
z = menu('select target function', ... 'Circle', ... 'Line'); disp('')
if z == 1 for t=1:200
xd(t,1)=0.5-0.25*cos(0.5*pi*0.02*(t-1)); xd(t,2)=0.25+0.25*sin(0.5*pi*0.02*(t-1)); end; else
for t=1:200
%xd(t,1)=0.5-0.25*cos(0.5*pi*0.02*(t-1)); %xd(t,2)=0.25+0.25*sin(0.5*pi*0.02*(t-1)); xd(t,1)=0.5-0.0025*t; xd(t,2)=0.0025*t; end; end;
k=1:200; hold off;
plot(xd(k,1),xd(k,2)); hold on;
deta=[-9.14 69.87 131.58];
x=[l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(1)*sin(deta(1)*2*pi/360)+l(2)*sin((deta(1)+deta(2))*2*pi/360)+l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360)];
jmat=[-l(1)*sin(deta(1)*2*pi/360)-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ...
-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ... -l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360); ...
l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ... l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ];
wts=zeros(memsize,3); % weight stack sse=1;
张建文 1030319100 张卜南1030319078
神经网络课程设计 神经网络用于机器手臂的控制
%sse=||Et||
addrs=zeros(c,3);
epcoh = input('enter number of training epochs '); %epcoh=4; for p=1:epcoh
disp('any key to continue'); pause k=1:200; hold off;
plot(xd(k,1),xd(k,2)); hold on; for t=1:200
delta_x=xd(t)-x;
ip=[deta 360*delta_x]+[90 90 90 0 0]; HASH=123456; offset=width/c; ofs=0;
seta_delta=[0 0 0]; for i=1:c address=0; shift=1;
for j=1:ipdim
address=address+(rem((ceil((ip(j)+ofs)/width)),quantisation))*shift; -dress=address+(ceil((ip(j)/width)))*shift; shift=shift*quantisation; end;
address=address+shift*i;
for j=1:3
addrs(i,j)=ceil(rem((log(address+1)*HASH),memsize)); -drs(i,j)=mod(address,memsize); end;
ofs=ofs+offset;
for j=1:3
seta_delta(j)=seta_delta(j)+wts(addrs(i,j),j); end; end;
deta=deta+seta_delta;
x=[l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(1)*sin(deta(1)*2*pi/360)+l(2)*sin((deta(1)+deta(2))*2*pi/360)+l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360)];
张建文 1030319100 张卜南1030319078
神经网络课程设计 神经网络用于机器手臂的控制
jmat=[-l(1)*sin(deta(1)*2*pi/360)-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ...
-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ... -l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360); ...
l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ... l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ];
Et=xd(t)-x;
seta_delta=seta_delta-0.1*(-300*Et*jmat+seta_delta); deta=deta+seta_delta;
x=[l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(1)*sin(deta(1)*2*pi/360)+l(2)*sin((deta(1)+deta(2))*2*pi/360)+l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360)];
jmat=[-l(1)*sin(deta(1)*2*pi/360)-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ...
-l(2)*sin((deta(1)+deta(2))*2*pi/360)-l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360) ... -l(3)*sin((deta(1)+deta(2)+deta(3))*2*pi/360); ...
l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ...
l(2)*cos((deta(1)+deta(2))*2*pi/360)+l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ... l(3)*cos((deta(1)+deta(2)+deta(3))*2*pi/360) ]; Et=xd(t)-x; temp=Et*jmat; for i=1:c for j=1:3
wts(addrs(i,j),j)=wts(addrs(i,j),j)+seta*temp(j); end; end;
if(rem(t,10)==0)
temp1=[l(1)*cos(deta(1)*2*pi/360),l(1)*sin(deta(1)*2*pi/360)];
张建文 1030319100 张卜南1030319078