home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume22 / back-prop / part01 / README
Text File  |  1991-08-28  |  43KB  |  1,119 lines

  1. .ce
  2. Fast Back-Propagation
  3. .ce
  4. Copyright (c) 1991 by Donald R. Tveter
  5.  
  6.  
  7. .ce
  8. 1. Introduction
  9.  
  10.    The programs described below were produced for my own use in studying
  11. back-propagation and for doing some examples that are found in my
  12. introduction to Artificial Intelligence textbook, \fIThe Basis of
  13. Artificial Intelligence\fR, to be published by Computer Science Press.
  14. (One would hope some time before the sun burns out or before the Cubs
  15. win the World Series or before Congress balances the budget or ... .)
  16. I have copyrighted these files but I hereby give permission to
  17. anyone to use them for experimentation, educational purposes or to
  18. redistribute them on a not for profit basis.  All others that want to
  19. use these programs for business or commercial purposes, I will charge
  20. you a small fee.  You should contact me by mail at:
  21.  
  22. .na
  23. .nf
  24. Dr. Donald R. Tveter
  25. 5228 N. Nashville Ave.
  26. Chicago, Illinois   60656
  27. USENET:  drt@chinet.chi.il.us
  28. .ad
  29. .fi
  30.  
  31. Also, I would be interested in hearing from anyone with suggestions,
  32. bug reports and major successes or failures.
  33.  
  34.    Note:  this is use at your own risk software:  there is no guarantee
  35. that it is bug-free.  Use of this software constitutes acceptance for
  36. use in an as is condition.  There are no warranties with regard to this
  37. software. In no event shall the author be liable for any damages
  38. whatsoever arising out of or in connection with the use or performance
  39. of this software.
  40.  
  41.    There is also a good chance that I will soon produce and sell DOS and
  42. extended DOS binary versions with more capabilities than there are in
  43. this UNIX (tm of AT&T Bell Labs) source code version.  They will
  44. probably include Quickprop, SuperSAB and Cascade Correlation at the very
  45. least and perhaps also DSM, LVQ1 and counter-propagation as well.
  46.  
  47.    There are four simulators that can be constructed from the included
  48. files.  The program, rbp, does back-propagation using real weights and
  49. arithmetic.  The program, bp, does back-propagation using 16-bit integer
  50. weights, 16 and 32-bit integer arithmetic and some floating point
  51. arithmetic.  The program, sbp, uses 16-bit integer symmetric weights but
  52. only allows two-layer networks.  The program srbp does the same using
  53. real weights.  The purpose of sbp and srbp is to produce networks that
  54. can be used with the Boltzman machine relaxation algorithm (not
  55. included).
  56.  
  57.    In most cases, the 16-bit integer programs are the most useful,
  58. because they are the fastest.  Unfortunately, sometimes 16-bit
  59. integer weights don't have enough range or precision and then using the
  60. floating point versions may be necessary.  Many other speed-up
  61. techniques are included in these programs.
  62.  
  63. .ce
  64. Updated Version
  65.  
  66.    This version contains a number of improvements and changes to command
  67. names vs. the September 1990 version.  For a summary of changes and
  68. additions see the file changes.
  69.  
  70. .ce
  71. 2. Making the Simulators
  72.  
  73.    This code has been written to use either 32-bit floating point
  74. (float) or 64-bit floating point (double) arithmetic.  On System V
  75. machines the standard seems to be that all floating point arithmetic is
  76. done with double precision arithmetic so double arithmetic is faster
  77. than float so this is the default.  Other versions of C (e.g. ANSI C)
  78. will do single precision real arithmetic.  To get 32-bit floating point
  79. set the compiler flag FLOAT in the makefile.  The function, exp, defined
  80. in real.c is double since System V specifies it as double.  If your C
  81. uses float, change this definition as well.
  82.  
  83.    One option exists for bp and sbp.  If your compiler isn't smart
  84. enough to divide by 1024 by shifting, remove the SMART flag in the
  85. makefile.
  86.  
  87.    To make a particular executable file, use the makefile given
  88. with the data files and make any or all of them like so:
  89.  
  90. .ce
  91. make bp
  92. .ce
  93.  make sbp
  94. .ce
  95.  make rbp
  96. .ce
  97.   make srbp
  98.  
  99.    To make a record of all the input and output from the programs,
  100. the following small UNIX command file I call "record" can be used:
  101.  
  102. .na
  103. .nf
  104. trap "" 2
  105. outfile="${1}.record"
  106. if test -f $outfile 
  107.    then
  108.       rm $outfile
  109.    fi
  110. echo $outfile
  111. (tee -a $outfile | $*) | tee -a $outfile
  112. process=`ps | grep tee | cut -c1-6`
  113. kill $process
  114. .ad
  115. .fi
  116.  
  117. For example to make a record of all the input and output from the
  118. program bp using data file, xor, use:
  119.  
  120. .ce
  121. record bp xor
  122.  
  123. .ce
  124. 3. A Simple Example
  125.  
  126.   Each version would normally be called with the name of a file to read
  127. commands from, as in:
  128.  
  129. .ce
  130. bp xor
  131.  
  132. When no file name is specified, bp will take commands from the keyboard
  133. (UNIX stdin file).  After the data file is read commands are then taken
  134. from the keyboard.
  135.  
  136.    The commands are one letter commands and most of them have optional
  137. parameters.  The `A', `B', `d' and `f' commands allow a number of
  138. sub-commands on a line.  The maximum length of any line is 256
  139. characters.  An `*' is a comment and it can be used to make the
  140. remainder of the line a comment.  Here is an example of a data file to
  141. do the xor problem:
  142.            
  143. .na
  144. .nf
  145. * input file for the xor problem
  146.            
  147. m 2 1 1           * make a 2-1-1 network
  148. c 1 1 3 1         * add this extra connection
  149. c 1 2 3 1         * add this extra connection
  150. s 7               * seed the random number function
  151. k 0 1             * give the network random weights
  152.  
  153. n 4               * read four new patterns into memory
  154. 1 0 1
  155. 0 0 0
  156. 0 1 1
  157. 1 1 0
  158.  
  159. e 0.5             * set eta to 0.5 (and eta2 to 0.5)
  160. a 0.9             * set alpha to 0.9
  161. .ad
  162. .fi
  163.  
  164. First, in this example, the m command will make a network with 2 units
  165. in the input layer, 1 unit in the second layer and 1 unit in the third
  166. layer.  The following c commands create extra connections from layer 1
  167. unit 1 to layer 3 unit 1 and from layer 1 unit 2 to layer 3 unit 1.
  168. The `s' command sets the seed for the random number function.  The `k'
  169. command then gives the network random weights.  The `k' command has
  170. another use as well.  It can be used to try to kick a network out of a
  171. local minimum.  Here, the meaning of "k 0 1" is to examine all the
  172. weights in the network and for every weight equal to 0 (and they all
  173. start out at 0), add in a random number between -1 and +1.  The `n'
  174. command specifies four new patterns to be read into memory.  With
  175. the `n' command, any old patterns that may have been present are
  176. removed.  There is also an `x' command that behaves like the `n'
  177. command, except the `x' commands \fIadds\fR the extra patterns to the
  178. current training set.  The input pattern comes first, followed by the
  179. output pattern.  The statement, e 0.5, sets eta, the learning rate for
  180. the upper layer to 0.5 and eta2 for the lower layers to 0.5 as well.
  181. The last line sets alpha, the momentum parameter, to 0.9.
  182.  
  183.    After these commands are executed, the following messages and prompt
  184. appears:
  185.  
  186. .na
  187. .nf
  188. .ne3
  189. Fast Back-Propagation Copyright (c) 1991 by Donald R. Tveter
  190. taking commands from stdin now
  191. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]?
  192. .ad
  193. .fi
  194.  
  195. The characters within the square brackets are a list of the possible
  196. commands.  To run 100 iterations of back-propagation and print out the
  197. status of the learning every 20 iterations type "r 100 20" at the
  198. prompt:
  199.  
  200. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? r 100 20
  201.  
  202. This gives:
  203.  
  204. .na
  205. .nf
  206. running . . .
  207.    20 iterations    0.00% right (0 right   4 wrong)   0.49927 error/unit
  208.    40 iterations    0.00% right (0 right   4 wrong)   0.43188 error/unit
  209.    60 iterations   75.00% right (3 right   1 wrong)   0.09033 error/unit
  210.    62 iterations  100.00% right (4 right   0 wrong)   0.07129 error/unit
  211. patterns learned to within 0.10 at iteration^G 62
  212. .ad
  213. .fi
  214.  
  215. The program immediately prints out the "running . . ." message.  After
  216. each 20 iterations, a summary of the learning process is printed, giving
  217. the percentage of patterns that are right, the number right and wrong
  218. and the average value of the absolute values of the errors of the output
  219. units.  The program stops when the each output for each pattern has been
  220. learned to within the required tolerance, in this case the default value
  221. of 0.1.  A ctrl-G is normally printed out as well to sound the bell.  If
  222. the second number defining how often to print out a summary is omitted,
  223. the summaries will not be printed.  Sometimes the integer versions will
  224. do a few extra iterations before declaring the problem done because of
  225. truncation errors in the arithmetic done to check for convergence.  The
  226. status figures for iteration i are computed when making the forward pass
  227. of the iteration and before the weights are updated so these values are
  228. one iteration out of date.  This saves on CPU time, however, if you
  229. really need up-do-date statistics use the u+ option described in the
  230. format specifications.
  231.  
  232. .ce
  233. Listing Patterns
  234.  
  235.    To get a listing of the status of each pattern, use the `P' command
  236. to give:
  237.  
  238. .na
  239. .nf
  240. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? P
  241.   1  0.90  (0.098) ok
  242.   2  0.05  (0.052) ok
  243.   3  0.94  (0.062) ok
  244.   4  0.07  (0.074) ok
  245.    62 iterations  100.00% right (4 right   0 wrong)   0.07129 error/unit
  246. .ad
  247. .fi
  248.  
  249. The numbers in parentheses give the sum of the absolute values of the
  250. output errors for each pattern.  An `ok' is given to every pattern that
  251. has been learned to within the required tolerance.  To get the status of
  252. one pattern, say, the fourth pattern, type "P 4" to give:
  253.  
  254.  0.07  (0.074) ok
  255.  
  256. To get a summary without the complete listing, use "P 0".  To get the
  257. output targets for a given pattern, say pattern 3, use "O 3".
  258.  
  259.    A particular test pattern can be input to the network with the `p'
  260. command, as in:
  261.  
  262. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? p 1 0
  263.  0.90 
  264.  
  265. .ce
  266. Examining Weights
  267.  
  268.    It is often interesting to see the values of some particular weights
  269. in the network.  To see a listing of all the weights in a network, use
  270. the save weights command described below and then cat the file weights,
  271. however, to see the weights leading into a particular node, say
  272. the node in row 2, node 1 use the w command as in:
  273.  
  274. .na
  275. .nf
  276. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? w 2 1
  277. layer unit  unit value     weight         input from unit
  278.   1      1    1.00000     9.53516             9.53516
  279.   1      2    0.00000    -8.40332             0.00000
  280.   2      t    1.00000     4.13086             4.13086
  281.                                       sum =  13.66602
  282. .ad
  283. .fi
  284.  
  285. This listing also gives data on how the current activation value of
  286. the node is computed using the weights and the activations values of
  287. the nodes feeding into unit 1 of layer 2.  The `t' unit is the
  288. threshold unit.
  289.  
  290. .ce
  291. The Help Command
  292.  
  293.    To get a short description of any command, type `h' followed by
  294. the letter of the command.  Here, we type h h for help with help:
  295.  
  296. .na
  297. .nf
  298. .ne3
  299. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? h h
  300.  
  301. h <letter> gives help for command <letter>.
  302. .ad
  303. .fi
  304.  
  305. To list the status of all the parameters in the program, use `?'.
  306.  
  307. .ce
  308. To Quit the Program
  309.  
  310.    Finally, to end the program, the `q' (for quit) command is entered:
  311.  
  312. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? q
  313.  
  314. .ce
  315. 4. The Format Command
  316.  
  317.    There are several ways to input and output patterns, numbers and
  318. other values and there is one format command, `f', that is used to set
  319. these options.  In the format command, a number of options can be
  320. specified on a single line, as for example in:
  321.  
  322. .ce
  323. f b+ ir oc s- wB
  324.  
  325. .ce
  326. Input Patterns
  327.  
  328.    The programs are able to read pattern values in two different
  329. formats.  The default input format is the compressed format.  In it,
  330. each value is one character and it is not necessary to have blanks
  331. between the characters.  For example, in compressed format, the patterns
  332. for xor could be written out in either of the following ways:
  333.  
  334. .ce
  335. 101               10 1
  336. .ce
  337. 000               00 0
  338. .ce
  339. 011               01 1
  340. .ce
  341. 110               11 0
  342.  
  343. The second example is preferable because it makes it easier to see the
  344. input and the output patterns.  Compressed format can also be used to
  345. input patterns with the `p' command.  In addition to using 1 and 0 as
  346. input, the character, `?' can be used.  This character is initially
  347. defined to be 0.5, but it can be redefined using the Q command like so:
  348.  
  349. .ce
  350. Q -1
  351.  
  352. This sets the value of ? to -1.  Other valid input characters are the
  353. letters, `h', `i', `j' and `k'.  The `h' stands for `hidden'.  Its
  354. meaning in an input string is that the value at this point in the string
  355. should be taken from the next unit in the second layer of the network.
  356. This notation is useful for specifying simple recurrent
  357. networks.  Naturally, `i', `j' and `k' stand for taking input
  358. values from the third, fourth and fifth layers (if they exist).  A
  359. simple example of a recurrent network is given later.
  360.  
  361.    The other input format for numbers is real.  The number portion must
  362. start with a digit (.35 is not allowed, but 0.35 is).  Exponential
  363. notation is not allowed.  Real numbers have to be separated by a space.
  364. The `h', `i', `j', `k' and `?' characters are also allowed with real
  365. input patterns.  To take input in the real format, it is necessary
  366. to set the input format to be real using the `f' (format) command as in:
  367.  
  368. .ce
  369. f ir
  370.  
  371. To change back to the compressed format, use:
  372.  
  373. .ce
  374. f ic
  375.  
  376. .ce
  377. Output of Patterns
  378.  
  379.    Output format is controlled with the `f' command as in:
  380.  
  381. .ce
  382. f or
  383. .ce
  384. f oc
  385. .ce
  386. f oa
  387.  
  388. The first sets the output to real numbers.  The second sets the
  389. output to be compressed mode where the value printed will be a `1' when
  390. the unit value is greater than 1.0 - tolerance, a `^' when the value
  391. is above 0.5 but less than 1.0 - tolerance, a `v' when the value is
  392. less than 0.5 but greater than the tolerance.  Below the tolerance
  393. value, a `0' is printed.  The tolerance can be changed using the `t'
  394. command (not a part of the format command).  For example, to make all
  395. values greater than 0.8 print as `1' and all values less than 0.2 print
  396. as `0', use:
  397.  
  398. .ce
  399. t 0.2
  400.  
  401. Of course, this same tolerance value is also used to check to see if all
  402. the patterns have converged.  The third output format is meant to
  403. give "analog compressed" output.  In this format, a `c' is printed when
  404. a value is close enough to its target value.  Otherwise, if the answer
  405. is close to 1, a `1' is printed, if the answer is close to 0, a `0' is
  406. printed, if the answer is above the target but not close to 1, a `^' is
  407. printed and if the answer is below the target but not close to 0, a `v'
  408. is printed.  This output format is designed for problems where the
  409. output is a real number, as for instance, when the problem is to make a
  410. network learn sin(x).
  411.  
  412.    For the sake of convenience, the output format (and only the
  413. output format) can be set without using the `f', so that:
  414.  
  415. .ce
  416. or
  417.  
  418. will also make the output format real.
  419.  
  420. .ce
  421. Breaking up the Output Values
  422.  
  423.    In the compressed formats, the default is to print a blank after
  424. every 10 values.  This can be altered using the `b' (for inserting
  425. breaks) command.  The use for this command is to separate output values
  426. into logical groups to make the output more readable.  For instance, you
  427. may have 24 output units where it makes sense to insert blanks after the
  428. 4th, 7th and 19th positions.  To do this, specify:
  429.  
  430. .ce
  431. b 4 7 19
  432.  
  433. Then for example, the output will look like:
  434.  
  435. .na
  436. .nf
  437.   1 10^0 10^ ^000v00000v0 01000 (0.17577)
  438.   2 1010 01v 0^0000v00000 ^1000 (0.16341)
  439.   3 0101 10^ 00^00v00000v 00001 (0.16887)
  440.   4 0100 0^0 000^00000v00 00^00 (0.19880)
  441. .ad
  442. .fi
  443.  
  444. The `b' command allows up to 20 break positions to be specified.  The
  445. default output format is the real format with 10 numbers per line.  For
  446. the output of real values, the `b' command specifies when to print a
  447. carriage return rather than when to print a blank.  (Note:  the `b'
  448. command is not part of the `f' command.)
  449.  
  450. .ce
  451. Pattern Formats
  452.  
  453.    There are two different types of problems that back-propagation can
  454. handle, the general type of problem where every output unit can take on
  455. an arbitrary value and the classification type of problem where the goal
  456. is to turn on output unit i and turn off all the other output units when
  457. the pattern is of class i.  The xor problem is an example of the general
  458. type of problem.  For an example of a classification problem, suppose
  459. you have a number of data points scattered about through two-dimensional
  460. space and you have to classify the points as either class 1, class 2 or
  461. class 3.  For a pattern of class 1 you can always set up the
  462. output: "1 0 0", for class 2: "0 1 0" and for class 3: "0 0 1",
  463. however doing the translation to bit patterns can be annoying, so
  464. another notation can be used.  Instead of specifying the bit patterns
  465. you can set the pattern format option to classification (as opposed to
  466. the default value of general) like so:
  467.  
  468. .ce
  469. f pc
  470.  
  471. and then the program will read data in the form:
  472.  
  473.    1.33   3.61   1   *  shorthand for 1 0 0
  474.    0.42  -2.30   2   *  shorthand for 0 1 0
  475.   -0.31   4.30   3   *  shorthand for 0 0 1
  476.  
  477. and translate it to the bit string form when the pattern is loaded
  478. onto the output units.  To switch to the general form, use "f pg".
  479.  
  480.    In addition to controlling the input of data, the p command within
  481. the format command is used to control the output of patterns from a set
  482. of test patterns kept on a file.  If the format is either c or g then
  483. when the test set is run thru the network you will only get a summary
  484. of how many patterns are correct.  If the format is either C or G you
  485. will get a listing of the output values for each pattern as well as
  486. the summary.  When reading patterns, C works the same as c and G works
  487. the same as g.
  488.  
  489. .ce
  490. Controlling Summaries
  491.  
  492.    When the program is learning patterns you can have it print out
  493. the status of the learning process at regular intervals.  The default
  494. is to print out only a summary of how learning is going, however you
  495. can also print out the status of every pattern at regular intervals.
  496. To get the whole set of patterns, use "f s-" to turn off the summary
  497. format and "f s+" to go back to summarizing.
  498.  
  499. .ce
  500. Ringing the Bell
  501.  
  502.    To ring the bell when the learning has been completed use "f b+"
  503. and to turn off the bell, use "f b-".
  504.  
  505. .ce
  506. Echoing Input
  507.  
  508.    When you are reading commands from a file, it is often worthwhile
  509. to see those commands echoed on the screen.  To do this, use "f e+"
  510. and to turn off the echoing, use "f e-".
  511.  
  512. .ce
  513. Up-To-Date Statistics
  514.  
  515.    During the ith pass thru the network the program will collect
  516. statistics on how many patterns are correct and how much error there
  517. is overall.  These numbers are gathered before the weights are updated
  518. and so the results listed for iteration i really show the situation
  519. after the weight update for iteration i-1.  To complicate matters more
  520. the weight updates can be done continuously instead of after all the
  521. patterns have been presented so the statistics you get here are skewed
  522. even more.  If you want to have up-to-date statistics with either
  523. method, use "f u+" and to go back to statistics that are out of date,
  524. use "f u-".  The penalty with "f u+" is that the program needs to do
  525. another forward pass.  When using the continuous update method it is
  526. highly advisable to use "f u+", at least when you get close to
  527. complete convergence because the default method of checking may claim
  528. the learning is finished when it isn't or it may continue training
  529. after the tolerances have been met.
  530.  
  531. .ce
  532.  5. Taking Training and Testing Patterns from Files
  533.  
  534.    In the xor example given above the four patterns were part of the
  535. data file and to read them in the following lines were used:
  536.  
  537. .na
  538. .nf
  539. n 4
  540. 1 0 1
  541. 0 0 0
  542. 0 1 1
  543. 1 1 0
  544. .ad
  545. .fi
  546.  
  547. However, it is also convenient to take patterns from a file that
  548. contains nothing but a list of patterns (and possibly comments).
  549. To read a new set of patterns from some file, patterns, use:
  550.  
  551. .ce
  552. n f patterns
  553.  
  554. To add an extra bunch of patterns to the current set you can use:
  555.  
  556. .ce
  557. x f patterns
  558.  
  559.    In addition to keeping a set of training patterns you can take
  560. testing patterns from a file as well.  To specify the file you can
  561. invoke the program with a second file name, as in:
  562.  
  563. .ce
  564. bp xor xtest
  565.  
  566. In addition, if you do the following:
  567.  
  568. .ce
  569. t f xtest
  570.  
  571. the program will set xtest as the test file and immediately do the
  572. testing.  Once the file has been defined you can test the patterns
  573. on the test file by "t f" or just "t".  (This leaves the t command
  574. doing double duty since "t <real>" will set the tolerance to <real>.)
  575. Also in addition, the test file can be set without being tested by using
  576.  
  577. .ce
  578. B t f xtest
  579.  
  580. as explained in the benchmarking section.
  581.  
  582.  
  583. .ce
  584. 6. Saving and Restoring Weights and Related Values
  585.  
  586.    Sometimes the amount of time and effort needed to produce a set of
  587. weights to solve a problem is so great that it is more convenient to
  588. save the weights rather than constantly recalculate them.  Weights can
  589. be saved as real values in an ASCII format (the default) or as binary,
  590. to save space.  To save the weights enter the command, `S'.  The weights
  591. are written on a file called "weights".  The following file comes from
  592. the xor problem:
  593.  
  594. .na
  595. .nf
  596. 62r   file = ../xor3
  597.     9.5351562500
  598.    -8.4033203125
  599.     4.1308593750
  600.     5.5800781250
  601.    -4.9755859375
  602.   -11.3095703125
  603.     8.0527343750
  604. .ad
  605. .fi
  606.  
  607. To write the weights, the program starts with the second layer, writes
  608. out the weights leading into these units in order with the threshold
  609. weight last.  Then it moves on to the third layer, and so on.  To
  610. restore these weights, type an `R' for restore.  At this time, the
  611. program reads the header line and sets the total number of iterations
  612. the program has gone through to be the first number it finds on the
  613. header line.  It then reads the character immediately after the number.
  614. The `r' indicates that the weights will be real numbers represented as
  615. character strings.  If the weights were binary, the character would be
  616. a `b' rather than an `r'.  Also, if the character is `b', the next
  617. character is read.  This next character indicates how many bytes are
  618. used per value.  The integer versions, bp and sbp write files with 2
  619. bytes per weight, while the real versions, rbp and srbp write files with
  620. 8 bytes per weight for double precision reals and 4 bytes per weight
  621. for single precision reals.  With this notation, weight files written by
  622. one program can be read by the other.  A binary weight format is
  623. specified within the `f' command by using "f wb".  A real format is
  624. specified by using "f wr".  If your program specifies that weights
  625. should be written in one format, but the weight file you read from is
  626. different, a notice will be given.  There is no check made to
  627. see if the number of weights on the file equals the number of weights in
  628. the network.
  629.  
  630.    The above formats specify that only weights are written out and this
  631. is all you need once the patterns have converged.  However, if you're
  632. still training the network and want to break off training and pick up
  633. the training from exactly the same point later on, you need to save
  634. the old weight changes when using momentum, and the parameters for the
  635. delta-bar-delta method if you are using this technique.  To save these
  636. extra parameters on the weights file, use "f wR" to write the extra
  637. values as real and "f wB" to write the extra values as binary.
  638.  
  639.    In the above example, the command S, was used to save the weights
  640. immediately.  Another alternative is to save weights at regular
  641. intervals.  The command, S 100, will automatically save weights every
  642. 100 iterations the program does.  The default rate at which to save
  643. weights is set at 100,000, which generally means that no weights will
  644. ever be saved.
  645.  
  646. .ce
  647. 7. Initializing Weights and Giving the Network a `Kick'
  648.  
  649.    All the weights in the network initially start out at 0.  In
  650. symmetric networks then, no learning may result because error signals
  651. cancel themselves out.  Even in non-symmetric networks, the training
  652. process will usually converge faster if the weights start out at small
  653. random values.  To do this, the `k' command will take the network and
  654. alter the weights in the following ways.  Suppose the command given is:
  655.  
  656. .ce
  657. k 0 0.5
  658.  
  659. Now, if a weight is exactly 0, then the weight will be changed to a
  660. random value between +0.5 and -0.5.  The above command can therefore be
  661. used to initialize the weights in the network.  A more complex use of
  662. the `k' command is to decrease the magnitude of large weights in the
  663. network by a certain random amount.  For instance, in the following
  664. command:
  665.  
  666. .ce
  667. k 2 8
  668.  
  669. all the weights in the network that are greater than or equal to 2, will
  670. be decreased by a random number between 0 and 8.  Weights less than or
  671. equal to -2 will be increased by a random number between 0 and 8.  The
  672. seed to the random number generator can be changed using the `s' command
  673. as in "s 7".  The integer parameter in the `s' command is of type,
  674. unsigned.
  675.  
  676.    Another method of giving a network a kick is to add hidden layer
  677. units.  The command:
  678.  
  679. .ce
  680. H 2 0.5
  681.  
  682. adds one unit to layer 2 of the network and all the weights that are
  683. created are initialized to between - 0.5 and + 0.5.
  684.  
  685.    The subject of kicking a back-propagation network out of local minima
  686. has barely been studied and there is no guarantee that the above methods
  687. are very useful in general.
  688.  
  689. .ce
  690. 8. Setting the Algorithm to Use
  691.  
  692.    A number of different variations on the original back-propagation
  693. algorithm have been proposed in order to speed up convergence and some
  694. of these have been built into these simulators.  These options are set
  695. using the `A' command and a number of options can go on the one line.
  696.  
  697. .ce
  698. Activation Functions
  699.  
  700.    To set the activation function, use:
  701.  
  702.  A al * the linear activation function
  703.  A ap * the piece-wise activation function
  704.  A as * the smooth activation function
  705.  A at * the piecewise near-tanh function that runs from -1 to +1
  706.  A aT * the continuous near-tanh function that runs from -1 to +1
  707.  
  708. When using the linear activation function, it is only appropriate to
  709. use the differential step-size derivative and a two-layer network.
  710. The smooth activation function is:
  711.  
  712. .ce
  713. f = 1.0 / (1.0 + exp(-x))
  714.  
  715. where x is the input to a unit.  The piece-wise function is an
  716. approximation to the function, f and it will normally save some CPU
  717. time even though it may increase the number of iterations you need to
  718. solve the problem.  The continuous near-tanh function is 2f - 1 and the
  719. piece-wise version approximates this function with a series of straight
  720. lines.
  721.  
  722. .ce
  723. Sharpness (or Gain)
  724.  
  725.    The sharpness (or gain) is the parameter, D, in the function:
  726.  
  727. .ce
  728. 1.0 / (1.0 + exp(-D*x)).
  729.  
  730. A sharper sigmoid shaped activation function (larger D) will produce
  731. faster convergence (see "Speeding Up Back Propagation" by Yoshio Izui
  732. and Alex Pentland in the Proceedings of \fIIJCNN-90-WASH-DC\fR, Lawrence
  733. Erlbaum Associates, 1990).  To set this parameter, to say, 8,
  734. use "A D 8".  The default value is 1.  Unfortunately, too large a value
  735. for D will hurt convergence so this is not a perfect solution to
  736. speeding up learning.  Sometimes the best value for D may be less than
  737. 1.0.  A larger D is also useful in the integer version of
  738. back-propagation where the weights are limited to between -32 and
  739. +31.999.  A larger D value in effect magnifies the weights and makes it
  740. possible for the weights to stay smaller.  Values of D less than one may
  741. be useful in extracting a network from a local minima (see "Handwritten
  742. Numeral Recognition by Multi-layered Neural Network with Improved
  743. Learning Algorithm" by Yamada, Kami, Temma and Tsukumo in Proceedings of
  744. the 1989 IJCNN, IEEE Press).  A smaller value of D will also force the
  745. weights and the weight changes to be larger and this may be of value
  746. when the weight changes become less than the weight resolution of 0.001
  747. in the integer version.
  748.  
  749. .ce
  750. The Derivatives
  751.  
  752.    The correct derivative for the standard activation function is s(1-s)
  753. where s is the activation value of a unit, however when s is near 0 or 1
  754. this term will give only very small weight changes during the learning
  755. process.  To counter this problem, Fahlman proposed the following one
  756. for the output layer:
  757.  
  758. .ce
  759. 0.1 + s(1-s)
  760.  
  761. (For the original description of this method, see "Faster Learning
  762. Variations of Back-Propagation:  An Empirical Study", by Scott E.
  763. Fahlman, in \fIProceedings of the 1988 Connectionist Models Summer
  764. School\fR, Morgan Kaufmann, 1989.)  Besides Fahlman's derivative and the
  765. original one, the differential step size method (see "Stepsize Variation
  766. Methods for Accelerating the Back-Propagation Algorithm", by Chen and
  767. Mars, in \fIIJCNN-90-WASH-DC\fR, Lawrence Erlbaum, 1990) takes the
  768. derivative to be 1 in the layer going into the output units and uses the
  769. correct derivative for all other layers.  The learning rate for the
  770. inner layers is normally set to some smaller value.  To set a value for
  771. eta2, give two values in the `e' command as in:
  772.  
  773. .ce
  774. e 0.1 0.01
  775.  
  776. To set the derivative, use the `A' command as in:
  777.  
  778. .ne4
  779.   A dd   * use the differential step size derivative (default)
  780.   A dF   * use Fahlman's derivative in only the output layer
  781.   A df   * use Fahlman's derivative in all layers
  782.   A do   * use the original, correct derivative
  783.  
  784. .ce
  785. Update Methods
  786.  
  787.    The choices are the periodic (batch) method, the continuous (online)
  788. method and Jacob's delta-bar-delta method.  The following commands
  789. set the update methods:
  790.  
  791.   A uc   * for the continuous update method
  792.   A ud   * for the delta-bar-delta method
  793.   A up   * for the original periodic update method (default)
  794.  
  795. The delta-bar-delta method uses a number of special parameters and these
  796. are set using the `d' command.  Delta-bar-delta can be used with any of
  797. the derivatives and the algorithm will find its own value of eta for
  798. each weight.
  799.  
  800. .ce
  801. Other Algorithm Options
  802.  
  803.    The `b' command controls whether or not to backpropagate error for
  804. units that have learned their response to within a given tolerance.  The
  805. default is to always backpropagate error.  The advantage to not
  806. backpropagating error is that this can save computer time.  This
  807. parameter can be set like so:
  808.  
  809.    A b+   * always backpropagate error
  810.    A b-   * don't backpropagate error when close
  811.  
  812.    The `s' sub-command will set the number of times to skip a pattern
  813. when the pattern has been learned to within the desired tolerance.  To
  814. skip 3 iterations, use "A s 3", to reset to not skip any patterns
  815. use "A s 0".
  816.  
  817.    The `t' sub-command will take the given pattern (only one at a
  818. time) out of the training set so that you can then train the other
  819. patterns and test the network's response to this one pattern that was
  820. removed.  To test pattern 3, use "A t 3" and to reset to use all the
  821. patterns use "A t 0".
  822.  
  823. .ce
  824. 9. The Delta-Bar-Delta Method
  825.  
  826.    The delta-bar-delta method attempts to find a learning rate
  827. eta, for each individual weight.  The parameters are the initial
  828. value for the etas, the amount by which to increase an eta that seems
  829. to be too small, the rate at which to decrease an eta that is
  830. too large, a maximum value for each eta and a parameter used in keeping
  831. a running average of the slopes.  Here are examples of setting these
  832. parameters:
  833.  
  834. .na
  835. .nf
  836. d d 0.5    * sets the decay rate to 0.5
  837. d e 0.1    * sets the initial etas to 0.1
  838. d k 0.25   * sets the amount to increase etas by (kappa) to 0.25
  839. d m 10     * sets the maximum eta to 10
  840. d n 0.005  * an experimental noise parameter
  841. d t 0.7    * sets the history parameter, theta, to 0.7
  842. .ad
  843. .fi
  844.  
  845. These settings can all be placed on one line:
  846.  
  847. .ce
  848. d d 0.5  e 0.1  k 0.25  m 10  t 0.7
  849.  
  850. The version implemented here does not use momentum.  The symmetric
  851. versions, sbp and srbp do not implement delta-bar-delta.
  852.  
  853.    The idea behind the delta-bar-delta method is to let the program find
  854. its own learning rate for each weight.  The `e' sub-command sets the
  855. initial value for each of these learning rates.  When the program sees
  856. that the slope of the error surface averages out to be in the same
  857. direction for several iterations for a particular weight, the program
  858. increases the eta value by an amount, kappa, given by the `k' parameter.
  859. The network will then move down this slope faster.  When the program
  860. finds the slope changes signs, the assumption is that the program has
  861. stepped over to the other side of the minimum and so it cuts down the
  862. learning rate, by the decay factor, given by the `d' parameter.  For
  863. instance, a d value of 0.5 cuts the learning rate for the weight in
  864. half.  The `m' parameter specifies the maximum allowable value for an
  865. eta.  The `t' parameter (theta) is used to compute a running average of
  866. the slope of the weight and must be in the range 0 <= t < 1.  The
  867. running average at iteration i, a\di\u, is defined as:
  868.  
  869. .ce
  870. a\di\u = (1 - t) slope\di\u + ta\di-1\u,
  871.  
  872. so small values for t make the most recent slope more important than
  873. the previous average of the slope.  Determining the learning rate for
  874. back-propagation automatically is, of course, very desirable and this
  875. method often speeds up convergence by quite a lot.  Unfortunately, bad
  876. choices for the delta-bar-delta parameters give bad results and a lot of
  877. experimentation may be necessary.  If you have n patterns in the
  878. training set try starting e and k around 1/n.  The n parameter is an
  879. experimental noise term that is only used in the integer version.  It
  880. changes a weight in the wrong direction by the amount indicated when the
  881. previous weight change was 0 and the new weight change would be 0 and
  882. the slope is non-zero.  (I found this to be effective in an integer
  883. version of quickprop so I tossed it into delta-bar-delta as well.  If
  884. you find this helps, please let me know.)  For more on
  885. delta-bar-delta see "Increased Rates of Convergence" by Robert A.
  886. Jacobs, in \fINeural Networks\fR, Volume 1, Number 4, 1988.
  887.  
  888. .ce
  889. 10. Recurrent Networks
  890.  
  891.    Recurrent back-propagation networks take values from higher level
  892. units and use them as activation values for lower level units.  This
  893. gives a network a simple kind of short-term memory, possibly a little
  894. like human short-term memory.  For instance, suppose you want a network
  895. to memorize the two short sequences, "acb" and "bcd".  In the middle of
  896. both of these sequences is the letter, "c".  In the first case you
  897. want a network to take in "a" and output "c", then take in "c" and
  898. output "b".  In the second case you want a network to take in "b" and
  899. output "c", then take in "c" and output "d".  To do this, a network
  900. needs a simple memory of what came before the "c".
  901.  
  902.    Let the network be an 7-3-4 network where input units 1-4 and output
  903. units 1-4 stand for the letters a-d.  Furthermore, let there be 3 hidden
  904. layer units.  The hidden units will feed their values back down to the
  905. input units 5-7, where they become input for the next step.  To see why
  906. this works, suppose the patterns have been learned by the network.
  907. Inputing the "a" from the first string produces some random pattern of
  908. activation, p1, on the hidden layer units and "c" on the output units.
  909. The pattern p1 is copied down to units 5-7 of the input layer.  Second,
  910. the letter, "c" is presented to the network together with p1 now on
  911. units 5-7.  This will give "b" on the output units.  However, if the "b"
  912. from the second string is presented first, there will be a different
  913. random pattern, p2, on the hidden layer units.  These values are copied
  914. down to input units 5-7.  These values combine with the "c" to produce
  915. the output, "d".
  916.  
  917.    The training patterns for the network can be:
  918.  
  919.      1000 000   0010  * "a" prompts the output, "c"
  920.      0010 hhh   0100  * inputing "c" should produce "b"
  921.  
  922.      0100 000   0010  * "b" prompts the output, "c"
  923.      0010 hhh   0001  * inputing "c" should produce "d"
  924.  
  925. where the first four values on each line are the normal input, the
  926. middle three either start out all zeros or take their values from the
  927. previous values of the hidden units.  The code for taking these values
  928. from the hidden layer units is "h".  The last set of values represents
  929. the output that should be produced.  To take values from the third layer
  930. of a network, the code is "i".  For the fourth and fifth layers (if they
  931. exist) the codes are "j" and "k".  Training recurrent networks can take
  932. much longer than training standard networks and the average error can
  933. jump up and down quite a lot.
  934.  
  935. .ce
  936. 11. The Benchmarking Command
  937.  
  938.    The main purpose of the benchmarking command is to make it possible
  939. to run a number of tests of a problem with different initial weights and
  940. average the number of iterations and CPU time for networks that
  941. converged.  A second purpose is to run a training set thru the network a
  942. number of times, and for each try, a test pattern or a test set can be
  943. checked at regular intervals.
  944.  
  945.    A typical command to simply test the current parameters on a number
  946. of networks is:
  947.  
  948. .ce
  949. B g 5 m 15 k 1 r 1000 200
  950.  
  951. The "g 5" specifies that you'd like to set the goal of getting 5
  952. networks to converge but the "m 15" sets a maximum of 15 tries to
  953. reach this goal.  The k specifies that each initial network will get
  954. a kick by setting each weight to a random number between -1 and 1.
  955. The "r 1000 200" portion specifies that you should run up to 1000
  956. iterations on a network and print the status of learning every 200
  957. iterations.  This follows the normal run command and the second
  958. parameter defining how often to print the statistics can be omitted.
  959. For example, here is some output from benchmarking with the xor
  960. problem:
  961.  
  962. .na
  963. .nf
  964. [?!*AaBbCcdefHhiklmnOoPpQqRrSstWwx]? B g 5 m 5 k 1 r 200
  965.  seed =      7; running . . .
  966. patterns learned to within 0.10 at iteration 62
  967.  seed =      7; running . . .
  968.  seed =      7; running . . .
  969. patterns learned to within 0.10 at iteration 54
  970.  seed =      7; running . . .
  971. patterns learned to within 0.10 at iteration 39
  972.  seed =      7; running . . .
  973. patterns learned to within 0.10 at iteration 44
  974. 1 failures; 4 successes; average = 49.750000     0.333320 sec/network
  975. .ad
  976. .fi
  977.  
  978. The time/network includes however much time is used to print messages
  979. so to time the process effectively, all printing should be minimized.
  980. The timing is done using the UNIX clock(3C) function and on a UNIX PC
  981. at least, the time returned by clock will overflow after 2147 seconds, or
  982. about 36 minutes.  If you system has the same limitation, take care that
  983. ALL of the benchmarking you do in a single call of the program adds up
  984. to less than 36 minutes.
  985.  
  986.    In the above example, the seed that was used to set the random values
  987. for the weights was set to 7 (outside the benchmarking command), however
  988. if you set a number of seeds, as in:
  989.  
  990. .ce
  991. s 3 5 7 18484 99
  992.  
  993. the seeds will be taken in order for each network.  When there are more
  994. networks to try than there are seeds, the random values keep coming from
  995. the last seed value, so actually you can get by using a single seed.
  996. The idea behind allowing multiple seeds is so that if one network does
  997. something interesting you can use that seed to run a network with the
  998. same initial weights outside of the benchmarking command.
  999.  
  1000.    Once the benchmarking parameters have been set, it is only necessary
  1001. to include the run portion in order to start the benchmarking process
  1002. again, thus, "B r 200" will run benchmarking again using the current set
  1003. of parameters.  Also, the parameters can be set without starting the
  1004. benchmarking process by just not including the `r' parameters in the B
  1005. command as in:
  1006.  
  1007. .ce
  1008. B g 5 m 5 k 1
  1009.  
  1010.    In addition to getting data on convergence, you can have the program
  1011. run test patterns thru the network at the print statistics rate given
  1012. in the `r' sub-command.  To specify the test file, test100, use:
  1013.  
  1014. .ce
  1015. B t f test100
  1016.  
  1017. To run the training data thru for up to 1000 iterations and test every
  1018. 200 iterations use:
  1019.  
  1020. .ce
  1021. B r 1000 200
  1022.  
  1023. If the pattern format specification p is set to either c or g you will
  1024. get a summary of the patterns on the test file.  If p is either C or G
  1025. you will get the results for each pattern listed as well as the summary.
  1026. To stop testing the data on the data file, use "B t 0".
  1027.  
  1028.    Sometimes you may have so little data available that it is difficult
  1029. to separate the patterns into a training set and a test set.  One
  1030. solution is to remove each pattern from the training set, train the
  1031. network on the remaining patterns and then test the network on the
  1032. pattern that was removed.  To remove a pattern, say pattern 1 from the
  1033. training set use:
  1034.  
  1035. .ce
  1036. B t 1
  1037.  
  1038. To systematically remove each pattern from the training set, use a
  1039. data file with the following commands:
  1040.  
  1041. .na
  1042. .nf
  1043. B t 1 r 200 50
  1044. B t 2 r 200 50
  1045. B t 3 r 200 50
  1046.  ... etc.
  1047. .ad
  1048. .fi
  1049.  
  1050. and the pattern will be tested every 50 iterations.  If, in the course
  1051. of training the network, all the patterns converge, the program will
  1052. print out a line starting with a capital S followed by a test of the
  1053. test pattern.  If the programs hits the point where statistics on the
  1054. learning process have to be printed and the network has not converged,
  1055. then a capital F will print out followed by a test of the test pattern.
  1056. To stop this testing, use "B t 0".
  1057.  
  1058.    It would be nice to have the program average up and tabulate all the
  1059. data that comes out of the benchmarking command, but I thought I'd leave
  1060. that to users for now.  You can use the record command to save the
  1061. output from the entire session and then run it thru some other program,
  1062. such as an awk program in order to sort everything out.
  1063.  
  1064. .ce
  1065. 12. Miscellaneous Commands
  1066.  
  1067.    Below is a list of some miscellaneous commands, a short example of
  1068. each and a short description of the command.
  1069.  
  1070. .IP "   !   !cmd    " 15
  1071. Anything after `!' will be passed on to UNIX as a command to execute.
  1072.  
  1073. .IP "   C   C       " 15
  1074. The C command will clear the network of values, reset the number of
  1075. iterations to 0 and reset other values so that another run can be made.
  1076. The seed value is reset so you can run the same network over with the
  1077. same initial weights but with different learning parameters.  Even
  1078. though the seed is reset, the weights are not initialized, so you
  1079. must do this step after clearing the network.
  1080.  
  1081. .IP "   i   i f     " 15
  1082. Entering "i f" will read commands from the file, f.  When there are
  1083. no more commands on the file, the program resumes reading from the
  1084. previous file being used.  You can also have an `i' command within the
  1085. file f, however the depth to which you can nest the number of active
  1086. files is 4 and stdin itself counts as the first one.  Once an input
  1087. file has been specified, you can simply type "i" to read from the file
  1088. again.
  1089.  
  1090. .IP "   l   l 2     " 15
  1091. Entering "l 2" will print the values of the units on layer 2,
  1092. or whatever layer is specified.
  1093.  
  1094. .IP "   T   T -3    " 15
  1095. In sbp and srbp only, "T -3" sets all the threshold weights
  1096. to -3 or whatever value is specified and freezes them at this value.
  1097.  
  1098. .IP "   W   W 0.9   " 15
  1099. Entering "W 0.9" will remove (whittle away) all the weights with
  1100. absolute values less than 0.9.
  1101. .in-15
  1102.  
  1103. In addition, when a user generated interrupt occurs (by typing DEL)
  1104. the program will drop its current task and take the next command from
  1105. the keyboard.
  1106.  
  1107. .ce
  1108. 13. Limitations
  1109.  
  1110.    Weights in the bp and sbp programs are 16-bit integer weights, where
  1111. the real value of the weight has been multiplied by 1024.  The integer
  1112. versions cannot handle weights less than -32 or greater than 31.999.
  1113. The weight changes are all checked for overflow but there are other
  1114. places in these programs where calculations can possibly overflow as
  1115. well and none of these places are checked.  Input values for the integer
  1116. versions can run from -31.994 to 31.999.  Due to the method used to
  1117. implement recurrent connections, input values in the real version are
  1118. limited to -31994.0 and above.
  1119.