function digfig( arg, arg2) % digfig: dig figures global ns na rew1 rew2 global R V Q nt averew entval gamman global state action reward value delta vals tmax global fm ff switch( arg) case 'init' ss = get(0,'ScreenSize'); fm = [ 10, 20, 42, 3]; % figure margins if nargin < 2 fx = min( ss(3)-4, 1024)/2 - (fm(1)+fm(2)); fy = (ss(4)-24)/2 - (fm(3)+fm(4)); else fx = arg2(1); fy = arg2(2); end ff = 1; % figure to be focused: 4 for digi figure(1); set(1,'Position',[fm(1),ss(4)-fm(3)-fy,fx,fy],'Name','Value'); clf; % figure(2); % set(2,'Position',[fm(1),ss(4)-fm(3)*2-fm(4)-fy*2,fx,fy],'Name','Value'); clf; figure(2); set(2,'Position',[fm(1)*2+fm(2)+fx,ss(4)-fm(3)-fy,fx,fy],'Name','Waves'); clf; case 'value' figure(1); clf; subplot(3,1,1); bar( V); ylabel( 'V'); set( gca, 'YLim',[-rew2,rew2], 'Ygrid','on'); subplot(3,1,2); bar( Q); ylabel( 'Q'); set( gca, 'YLim',[-rew2,rew2], 'Ygrid','on'); subplot(3,1,3); bar( R); ylabel( 'R'); set( gca, 'YLim',[-rew2,rew2], 'Ygrid','on'); case 'wave' figure(2); clf; if nargin<2, arg2=length(action); end tt = 1:arg2; rows = 4; % state, action, value/reward, delta lw = 2; % line width % state subplot( rows, 1, 1); plot( tt, state(tt), 'b', 'LineWidth', lw); set( gca, 'YLim',[1,ns], 'Ygrid','on'); ylabel( 'State'); % action subplot( rows, 1, 2); plot( tt, action(tt), 'c', 'LineWidth', lw); set( gca, 'YLim',[0.5,na+0.5], 'Ygrid','on'); ylabel( 'Action'); % reward subplot( rows, 1, 3); plot( tt, value(tt), 'g', tt, reward(tt), 'r', 'LineWidth', lw); set( gca, 'YLim',[-rew2,rew2], 'Ygrid','on'); ylabel( 'R & V'); % value/TD subplot( rows, 1, 4); plot( tt, delta(tt), 'm', 'LineWidth', lw); maxd = max(abs(delta(tt))); set( gca, 'YLim',[-maxd,maxd], 'Ygrid','on'); ylabel( 'TD'); case 'evol' figure(1); clf; tt = 1:nt; lw = 2; subplot(3,1,1); plot( 1:nt, averew(1:nt), 'r', 'LineWidth', lw); ylabel( 'E[r]'); subplot(3,1,2); plot(tt, entval(1:nt), 'g', 'LineWidth', lw); ylabel( 'H[V]'); subplot(3,1,3); plot( tt, gamman(1:nt), 'b', 'LineWidth', lw); ylabel( 'Gamma'); case 'reval' figure(2); tt = 1:tmax; rows = 4; % state, action, value/reward, delta lw = 1; % line width % reward subplot( rows, 1, 3); hold( 'on'); plot( tt, vals(tt,:), 'LineWidth', lw); end drawnow; %%%%