home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / RLaB 1.18c / examples / nn-test.r < prev    next >
Encoding:
Text File  |  1994-09-20  |  4.6 KB  |  67 lines  |  [TEXT/ttxt]

  1.  + abs(s1)); // simple
  2.     s2 = weight2 * hidden + theta2;
  3.     output = s2 ./ (1 + abs(s2)); // simple
  4.     
  5.     // error vectors
  6.     e2 = (mu * (1 ./ ((1 + abs(s2)) .* (1 + abs(s2))) + 0.05)) ...
  7.           .* (desired - output); // simple
  8.     e1 = (1 ./ ((1 + abs(s1)) .* (1 + abs(s1))) + 0.05) ...
  9.           .* (weight2' * e2); // simple
  10.  
  11.     // weight update
  12.     weight1 = weight1 + e1 * input';
  13.     weight2 = weight2 + e2 * hidden';
  14.     
  15.     // threshold update
  16.     theta1 = theta1 + e1;
  17.     theta2 = theta2 + e2;
  18.     
  19.     err = desired - output;
  20.     esquare = 0.995 * esquare + 0.005 * (err' * err);
  21.     if (iter > skiplimit) 
  22.     {
  23.       wsave[(iter - skiplimit);] = [desired, firout, output, err, esquare];
  24.     }
  25.     
  26.   }
  27.   
  28. }
  29.  
  30. bp2 = function () 
  31. {
  32.   global(niter, fircoeff, nfir, nsaved, sigsave, firout, ...
  33.          desired, iter, ninput, input, weight1, theta1, ...
  34.          weight2, theta2, ndf, nhidden, mu, esquare, output, ...
  35.          nwsave, wsave, skiplimit)
  36.  
  37.   iter = 1;
  38.   toiter = 0;
  39.   while (iter < niter) 
  40.   {
  41.     fromiter = toiter + 1;
  42.     toiter = fromiter + 999;
  43.     if (toiter > niter) 
  44.     {
  45.       toiter = niter;
  46.     }
  47.     
  48.     bp2steps(fromiter, toiter, skiplimit);
  49.     
  50.     printf("Iteration %d: esquare = %g,\n", iter, esquare);
  51.     printf("   weight1^2 = %g, theta1^2 = %g,\n", ...
  52.                trace(weight1 * weight1'), theta1' * theta1);
  53.     printf("   weight2^2 = %g, theta2^2 = %g\n", ...
  54.                weight2 * weight2', theta2' * theta2);
  55.   }
  56.   
  57.   plotdata = [((skiplimit + 1):niter)', wsave];
  58.   
  59.   plgrid();
  60.   ptitle ( "RLaB Neural Net Example (contributed)" );
  61.   xlabel ( "" );
  62.   ylabel ( "" );
  63.   plot(plotdata[nwsave-100:nwsave;]);
  64.   
  65. }
  66.  
  67.