%%% C:/work/PLPaper2/simul/NoBiasControl.txt

****************************************************************************
******
******  11 July 2005 -- Can PLM_Hebb2 even get off the ground if the
******                  criterion control mechanism is turned off?
******                  Can it survive the context switches?
******
***************************************************************************


>> clear all; cd(fullfile(work_pathstr,'PLPaper2','simul'));
>> global PLM_CACHE;load(fullfile(PLM_pathstr,'PLM_CACHE.mat'));clear Idef;

>> Mpar_nf=PLM_params;Mpar_nf.fdbk_fract=0;Mpar_nf.fdbk_mode=0;Mpar_nf.out_noise=.156;Mpar_nf.criterion=0
Mpar_nf = 
      rep_size: [7 5 1]
       max_act: 0.5000
      rep_gain: 0.8000
      out_gain: 5
     rep_noise: 0.1000
     out_noise: 0.1560
      W_minmax: [-1 1]
        W_init: 0.1700
       W0_seed: [35x1 double]
    learn_rate: 0.0016
    runav_rate: 0.0200
     criterion: 0           % <-- Criterion control turned off!!
      fdbk_wgt: 1.8000
    fdbk_fract: 0
     fdbk_mode: 0
      blk_size: 300


%%%%  Try a stationary environment first.
%
% 10800 trials in context R.
» C=2;N=10800;spec=expand_block_spec([0 0 C N]);stim=block_from_cache(spec,PLM_CACHE,1);         % [Nx5]
» [o,Wh]=PLM_Hebb2(stim,Mpar_nf);t=[1:30:N];for k=1:5 subplot(2,3,k);plot(t,Wh([1:7]+7*k-7,t)','b');axis([0 N -.5 +.5]);set(gca,'ytick',[-.5:.1:+.5]);grid on;end
» subplot(2,3,6);plot(t,Wh(36,t));axis([0 N 0 1]);set(gca,'ytick',[0:.125:1]);grid on;title('Response running average');

% Run to a steady state: 48000 trials
» C=2;N=48000;spec=expand_block_spec([0 0 C N]);stim=block_from_cache(spec,PLM_CACHE,1);         % [Nx5]
» [o,Wh]=PLM_Hebb2(stim,Mpar_nf);t=[1:60:N];
» figure(1);for k=1:5 subplot(2,3,k);plot(t,Wh([1:7]+7*k-7,t)','b');axis([0 N -.6 +.6]);set(gca,'ytick',[-.6:.1:+.6]);grid on;end
» figure(1);subplot(2,3,6);plot(t,Wh(36,t),'.');axis([0 N -1 1]);set(gca,'ytick',[-1:.25:1]);grid on;title('Response running average');xlabel('48,000 trials total');
% Saved as PLPaper2/simul/PureHebb_ContextR.pdf

» figure(2);subplot(2,2,1);plot(t,o(t,2),'.');axis([0 N -.55 .55]);grid on;title('Postsynaptic activation (actE=actL)');
» figure(2);subplot(2,2,2);plot(t,o(t,3),'.');axis([0 N -1 1]);grid on;title('Bottom-up evidence');
» figure(2);subplot(2,2,3);plot(t,Wh(37,t),'.');axis([0 N -.3 .3]);set(gca,'ytick',[-.3:.1:.3]);grid on;title('Running average of the postsynaptic activation');
» figure(2);subplot(2,2,4);plot(t,Wh(36,t),'.');axis([0 N -1 1]);set(gca,'ytick',[-1:.25:1]);grid on;title('Response running average');

%%%  The model can lean the sationary environment without feedback and without criterion control!!



%%%% Non-stationary 36-block protocol. 20 runs under Schedule 2 = R-8L-8R-...
%
» load(fullfile(work_pathstr,'PLExp2','modelfits','sched36.mat'));
» N_trials=10800; N_runs=20;for k=1:N_runs d=block_from_cache(sched36_2,PLM_CACHE);Mdata36(k).stim=cat(1,d{:});Mdata36(k).chev=make_chev(N_trials);end;d=cat(3,Mdata36(:).stim);d=squeeze(d(:,3,:));imagesc(d);clear d  % sanity check
» o=zeros(10800,6,N_runs);for k=1:N_runs md=Mdata36(k);md.params=Mpar_nf;[o(:,:,k),Wh]=PLM_Hebb2(md);end
» st=PLM_stats2(cat(3,Mdata36(:).stim),o(:,1,:))
st =   group: [20x1 double]
    zP_congr: [36x3x20 double]
    zP_incon: [36x3x20 double]
      dprime: [36x3x20 double]
       accZP: [20x6 double]

» sst=PLM_summary(st)
sst = 
      N_runs: 20
    zP_congr: [36x3 double]
    zP_incon: [36x3 double]
      dprime: [36x3 double]
       accZP: [2.3088 2.3096 2.3184 -0.9524 -1.8656 -2.2182]

» global HUMAN_ZCONGR;load(fullfile(work_pathstr,'PLExp2','modelfits','HUMAN_ZCONGR.mat'));
» plot_PLM_fit2a({sst.zP_congr',sst.zP_incon'},[]);    % quick-and-dirty hack in PLPaper2/simul/plot_PLM_fit2a.m
% Figure saved as PLPaper2/simul/NoBiasControl.pdf

% Plot a sample weight history
» [o,Wh]=PLM_Hebb2(stim,Mpar_nf);t=[1:30:N_trials];
» for k=1:5 subplot(2,3,k);plot(t,Wh([1:7]+7*k-7,t)','b');axis([0 N_trials -.5 +.5]);set(gca,'xtick',[300:2400:N_trials],'xticklabel',[],'ytick',[-.5:.1:+.5]);grid on;end
» subplot(2,3,6);plot(t,Wh(36,t),'.');axis([0 N_trials -1 1]);set(gca,'xtick',[300:2400:N_trials],'xticklabel',[],'ytick',[-1:.25:1]);grid on;title('Response running average');



*************************************************************************

Date: Mon, 11 Jul 2005 21:19:40 -0700
To: Barbara Dosher <bdosher@uci.edu>
From: Alexander Petrov <apetrov@uci.edu>
Subject: Simulation results

Dear Barbara,

I ran the model with the bias feedback parameter set to zero. 
The results are quite remarkable and can be summarized as follows.

If the environment is stationary, the model can learn, slowly.  
There is strong bias for the congruent response at first, but gradually 
it goes away and the model achieves nearly balanced response frequencies 
around trial number 20,000.  The weights of the target-sensitive channels 
grow, and so d' should increase. (I haven't calculated explicit d's for 
the stationary condition, only looked at weight histories and response 
runninng averages -- see PureHebb_ContextR.pdf).  This Hebbian algorithm 
is quite powerful indeed!   It can learn without feedback or bias control 
and still converges to the right solution, PROVIDED THE ENVMT IS STATIONARY!!

The model doesn't work so well in non-stationary environments, however.  
The z-transformed probability correct for congruent stimuli was at 
ceiling throughout each of the 20 runs that I simulated. 
(See the top panel in attached Figure NoBiasControl.pdf.)  
The z-transformed Pcorrect for the incongruent stimuli was deeply 
negative (i.e. below chance) throughout, although not all the way 
to the bottom and with separation between the three contrast levels.  
The overall d' zig-zags up and down, unable to make consistent progress.  
The weights remain more or less stable. There is even a tendency to 
increase the weights of the relevant channels. 
(See p. 2 in NoBiasControl.pdf).

Conclusions:
  1. Non-stationary environments are inherently more difficult than stationary ones.
  2. A purely Hebbian model, without any bias control, can converge to a nice, 
     balanced solution in a stationary environment.  Slowly but surely.
  3. In non-stationary envmt, however, the external switches occur much 
     more often than the pure Hebbian component with its slow learning 
     rate can cope with. This results in marked ceiling effects in the 
     response frequencies, especially for the congruent stimuli.

All this is anticipated in the manuscript, but now we can be sure it's true.
Regards,
  -- Alex

[PLPaper2/simul/PureHebb_ContextR.pdf]
[PLPaper2/simul/NoBiasControl.pdf]
