//Scilab version of hebb learning rule (cf. ZELL, 1994, S.103)
//Author: Gerd Doeben-Henisch
//Version 13.Jan.2009
//Dependent from: anns-vecmtx.sci (vector and matrix functions)
//Dependent from: neuron1.sce, nnbin1.sce
//
//
//
//***************************************************
//Increment weights
//
// in := input to network as vector
// W := Matrix with weights
// out := output from network as vector
// tr := Vector with training values (length(t) = length(o)
function[W]=hebb1(in, out,tr,W)
for j=1:length(out),
if out(j) == tr(j) then,
elseif out(j) == 0 then W=vecAddMi(W,j,in),//Increment W
elseif out(j) == 1 then W=vecSubMi(W,j,in), //Decrement W
end
end
endfunction
//***************************************************
//network with w-dynamic
//
// IN := input to network as matrix
// W := Matrix with weights
// th := thresholds for N as vector
// N := Matrix of hiffen neurons as list of neuron functions
// TR := training values as matrix
// s := number of steps
// m := mode either 0 := no learning or 1 := learning
function[W,o]=wdynbin(IN,W,th,N,TR,s, m)
if m <> 1 then printf("NO LEARNING"),
for i=1:s,o=nnbin(IN(i,:),W,th); printf("i=%d\n",i),
end
else printf("LEARNING"),
for i=1:s,o=nnbin(IN(i,:),W,th); printf("i=%d\n",i),
W=hebb1(IN(i,:), o,TR(i,:),W),
end
end
endfunction
//***********************************************************************
// Special version with test output
// works only with length of output vector = 2
function[W,o]=wdynbinP(IN,W,th,N,TR,s, m)
if m <> 1 then printf("NO LEARNING"),
for i=1:s,o=nnbin(IN(i,:),W,th); printf("i=%d\n",i),write(%io(2),o,'('' | '',2(f10.3,'' | ''))');
end
else printf("LEARNING"),
for i=1:s,o=nnbin(IN(i,:),W,th); printf("i=%d\n",i),
W=hebb1(IN(i,:), o,TR(i,:),W),
end
end
endfunction
//********************************************************
// Test of a learning scenario
//
// (1) Set W to zero
// (2) Outer Loop with training items from IN
// (3) Inner Loop with test of learning effect with items from TST
//
function[i,W,o]=testrun(IN,TST, W,th,N,TR,s)
[r,c]=size(W),
if size(W) <> size(TST) then error('INP AND TST DO NOT MATCH');
else
W=zeros(r,c),
printf("TEST BEFORE LEARNING\n");
//Here usage of the special wdynbinP() function with limited output
[W,o]=wdynbinP(TST,W,th,N,TR,s, 0);
printf("SWITCHING PARTIAL LEARNING AND TESTING\n");
for i=1:s, printf("%2d = LEARN------------------------\n",i);
[W,o]=wdynbin(IN,W,th,N,TR,i, 1),
printf("TST FOR %2d ------------------------\n",i);
[W,o]=wdynbinP(TST,W,th,N,TR,s, 0)
end
end
endfunction