?? robot.m
字號(hào):
function robot()
% neural networks housework
%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);
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;
%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;
%address=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));
%addrs(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)];
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)];
temp2=[l(1)*cos(deta(1)*2*pi/360)+l(2)*cos((deta(1)+deta(2))*2*pi/360),l(1)*sin(deta(1)*2*pi/360)+l(2)*sin((deta(1)+deta(2))*2*pi/360)];
title('cmac robotic control');
xlabel('x');
ylabel('y');
plot([0 temp1(1)],[0 temp1(2)],'-g');
plot([temp1(1) temp2(1)],[temp1(2) temp2(2)]);
plot([temp2(1) xd(t,1)+Et(1)],[temp2(2) xd(t,2)+Et(1)],'-r');
pause2(pausetime);
end;
% if(rem(t,30)==0)
% disp(sprintf('time is:%d',t));
% Et
%end;
neterr(2*i-1)=Et(1);
neterr(2*i)=Et(2);
end;
sse=sumsqr(neterr);
sse
disp(sprintf('epcoh: %f:',p));
end;
disp('any key to continue');
pause
hold off
bar(wts,'r')
title('Network Weights');
xlabel('Weight Number');
ylabel('Weight Value');
set(gca,'xlim',[0 memsize]);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -