% % ocrtrain.m % % train a 2 level feedforward net to recognize the % members of the DNA alphabet. The letters are bit patterns % associated with a 5x5 LED array. % % usage [V,W] = dnaocr(V0,W0,maxiter,rate) % % where V0 is the 25x25 matrix of weights from input to hidden % W0 is the 2x25 matrix of weights from hidden to output % maxiter is the number of training iterations % rate is the learning rate % % e.g., V0 = randn(25); W0 = randn(2,25); % [V,W] = dnaocr(V0,W0,5000,0.1) % function [V,W] = ocrtrain(V0,W0,maxiter,rate) V = V0; % initialize V, W = W0; % initialize W, state = zeros(4,25); state(1,[1:5 6 13 18 23]) = 1; % T state(2,[1:5 6 10 11:15 16 20 21 25]) = 1; % A state(3,[1:5 6 11 16 21:25]) = 1; % C state(4,[1:5 6 11 14 15 16 20:25]) = 1; % G target = [0 0; % T (state T should produce this output) 0 1; % A 1 0; % C 1 1]; % G for iter=1:maxiter, j = ceil(rand*4); % index of input i = ceil(rand*2); % index of output p = state(j,:)'; % 25-by-1 h = s(V*p); % 25-by-1 o = s(W(i,:)*h); % 1-by-1 tmp = (o-target(j,i))*o*(1-o); % the common part of the update W(i,:) = W(i,:) - rate*tmp*h'; % update row i of W V = V - rate*tmp*(W(i,:)'.*h.*(1-h))*p'; % update V end % the soft theshold function val = s(x) val = 1./(1+exp(-x+.5));