%% elman ------- numinputs = 64; %net = newelm(repmat([0 1],numinputs,1),[70 50 2],{'tansig','tansig','tansig','satlins'}); net = newelm(repmat([0 1],numinputs,1),[70 50 3],{'tansig','tansig','tansig','satlins'}); net.trainParam.show = 1; %% build t matrix (from single desired output vector) [h w] = size(p); t = repmat(t,1,900); t = repmat({t},h,w); %% assemble input np = []; nt = []; %load ani %np = [np p]; nt = [nt t]; %load ambient %np = [np p]; nt = [nt t]; load trance np = [np p]; nt = [nt t]; load house np = [np p]; nt = [nt t]; load jungle np = [np p]; nt = [nt t]; p = []; t = []; %% mix up input [h w] = size(np); perm = randperm(w); np = np(:,perm); nt = nt(:,perm); %% train net = train(net,np,nt); % train loop (do 10 epochs on 50 input sequences at a time, since i only have 512mb ram) chunk = 40; net.trainParam.epochs = 10; s = 101; for n = 1:100 load n [h w] = size(np); if w < chunk + s s = 1; end np = np(s:s+chunk-1); nt = nt(s:s+chunk-1); s = s + chunk; net = train(net,np,nt); save nett net % net.trainParam.lr = net.trainParamlr / 1.1 end % [ ani house . . . ] plotsom(net.layers{1}.positions) %% check accuracy! (based on max of output) yes = 0; left = 0; right = 0; leftt = 0; rightt = 0; [h w] = size(np); for n = 1:w s = np{n}; sr = sim(net,s); r = mean(sr'); % only pay attention to secnd half of sequence output! [ r(1) r(2) nt{n}(1) nt{n}(2) ] % just get totals... if nt{n}(1) leftt = leftt + 1; end if nt{n}(2) rightt = rightt + 1; end % correctly classified? if and(r(1) > r(2), nt{n}(1)) yes = yes + 1; left = left + 1; end if and(r(1) < r(2), nt{n}(2)) yes = yes + 1; right = right + 1; end end [ yes w ] [ left leftt ] [ right rightt ] %% train set % for whole sequence 508 595 total 85.3% 212 298 ani 71.1 296 297 house 99.6 % second half of sequence 499 595 total 83.9 202 298 ani 67.8 297 297 house 100 %% test set % cure ans = 34 68 EDU>> [ left leftt ] ans = 10 29 EDU>> [ right rightt ] ans = 24 39 % nando 64 123 EDU>> [ left leftt ] ans = 8 60 EDU>> [ right rightt ] ans = 56 63 EDU>> brc 800 483 2000 circuit id = 10QGDB000674GTCA