% Copyright 1997 by Peter C. Jones and Scott D. Tepavich. % All Rights Reserved. % % Learning mode load th250.mat % Load the simulink signals (ThD, ThOut) imax = length(t); % don't count too high in time... =) e_sq = zeros(imax,1); %initialize error to 0 W = rand(30,1)*2 - 1.0; mu = .1; KEEPGOING=1; loopcount = 0; lEpoch = length(ThD), % data points in one epoch while KEEPGOING i = rem( loopcount, imax ) + 1; loopcount = loopcount + 1; % 2 x = 0*W; % get an "input" array, initialized to 0, same size as W lW = length(W); if( i>lW ) x(1:lW) = ThOut(i:-1:i-lW+1); else x(1:i) = ThOut(i:-1:1); end if(length(x)>lW), break, end ThC = sum( x .* W ); % 3. Error = desired - actual delta = ThD(i) - ThC; e_sq(i) = delta^2; % sqared error % 4. Change weights Wnew = W + 2 * mu * delta * x; W = Wnew; % 5. plot J = fn(loop count), and compare if( rem(loopcount,lEpoch)==0 ) epoch = fix(loopcount/lEpoch); J(epoch) = sum(e_sq); % sum-squared-error if( rem(epoch,5)==0 ), figure(1), loglog(1:epoch, J(1:epoch)), end if( epoch == 10 ), pi, end if( log10(epoch) == floor(log10(epoch)) ), J(epoch), end end if( (J(epoch)<.0001) & (loopcount>imax) ), KEEPGOING=0; end end; % end "while KEEPGOING" loglog(1:epoch, J(1:epoch)) epoch