home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / educaton / polysim.arc / POLYSIM.DOC < prev    next >
Text File  |  1989-05-22  |  10KB  |  190 lines

  1. POLYSIM - Fits experimental data to a large polynomial equation using
  2.           a modified simplex approach.
  3.  
  4. Version 1.1
  5.  
  6. D.J.Murphy 1989
  7.  
  8.  
  9. Usage: polysim [min_index max_index] inputfile outputfile
  10.  
  11. Description: POLYSIM is designed to be run either on a PC in a "fire & forget"
  12.              manner, or on a Unix (or other) host capable of supporting
  13.              background processes. This is because optimization can be a time
  14.              consuming business, and so once invoked no other input is required
  15.              providing the data has been entered into the input file correctly.
  16.              It fits data to the equation:
  17.  
  18.              y = ax^5 + bx^4 + cx^3 + dx^2 + ex + f + g/x + h/(x^2)
  19.  
  20.              using a modified simplex method (see below) to optimize the
  21.              coefficients a through h such that the mean deviation of Y(input)
  22.              from Y(calculated) is minimized.
  23.              Alternatively, any part of this equation can be fitted by entering
  24.              minimum and maximum values for the X-index on the command line.
  25.              Restrictions here are that the indices must either both be entered
  26.              or not at all (not one alone), and must be entered minimum then
  27.              maximum. The indices, I, must be integers and 5 >= I >= -2.
  28.              Using this option it is possible to use an educated guess at the
  29.              general form of the function your data should fit to restrict the
  30.              amount of work POLYSIM has to do, and thus reduce the time it will
  31.              take to run.
  32.              Output is via a text file, and includes number of iterations used,
  33.              values of all the coefficients, mean deviation and a list of
  34.              input data, Y(calculated) and the differences.
  35.  
  36. Index Range: If you do not include this, the default range of X^5 to X^(-2)
  37.              will be used. If you want to restrict this, enter the minimum
  38.              index value you want, then the maximum, as integers.
  39.  
  40. Input file:  The input file must contain the input data as delimited
  41.              X Y pairs, preferably one pair per line:
  42.              eg.  1 1
  43.                   2 4
  44.                   3 9
  45.                   4 16
  46.                   |  |
  47.  
  48.              Do not include anything else in this dataset. Try to avoid
  49.              including x=0 values, as data pairs with x = 0 are ignored on
  50.              reading the file (this to avoid divide-by-zero errors when
  51.              evaluating Y(calculated)). Any valid filename is accepted.
  52.  
  53.  
  54. Output file: Any valid filename is accepted. Any existing file of that name
  55.              will be overwritten, unless it is write-protected in which case
  56.              POLYSIM will fail AFTER running the optimization.
  57.  
  58. Example:     C:\polysim 0 2 expt1.dat expt1.res
  59.  
  60.              Run POLYSIM on the data in C:\EXPT1.DAT, optimizing to the
  61.              function y = ax^2 + bx + c, and write the results to the
  62.              file C:\EXPT1.RES which can be listed to the screen, printer
  63.              or included in other programs.
  64.  
  65. Cautions:    This is an optimization program - it is wise to plot the data
  66.              visually before using it, as the fit POLYSIM reports may be better
  67.              for some parts of the dataset than others. It is unwise to
  68.              extrapolate too much beyond the range of the given data set.
  69.              POLYSIM also takes a while to run - you are advised to try using
  70.              a log(X) - log(Y) least squares method first to try and get a
  71.              straight line, unless you either know that this won't give you
  72.              a straight line or you are desperate for a curve.
  73.              Also, not all data sets will give reasonable curves - again, try
  74.              plotting first to see if this is likely to be so - if not the
  75.              answer (if you get one) is likely to be meaningless.
  76.  
  77. Portability: POLYSIM is written in C, and was developed on a PC using
  78.              Borland's Turbo C v1.5, and compiled using floating point
  79.              emulation so it will use an 80x87 math coprocessor if one is
  80.              present but it does not require it (use of such is highly
  81.              recommended, though - POLYSIM makes extensive use of
  82.              double precision real numbers and as such will be very slow
  83.              without a floating point processor).
  84.              No odd facilities are used in the source code, so it should
  85.              be portable onto a Unix system, or to any ANSI C compiler -
  86.              it _should_ be - I'm making no promises.
  87.  
  88. What is "modified simplex" optimization?
  89.  
  90. Simplex is a formal procedure for optimizing a set of parameters in a case
  91. where you can measure responses for different combinations of parameter values
  92. but have no knowledge of the "response surface" which gives rise to the
  93. observed pattern - i.e. it is not possible to use calculus to find a maximum
  94. or minimum. A simplex is a geometrical figure which has one more vertex than
  95. the number of dimensions it occupies - a 2 dimensional simplex is a triangle,
  96. for example. POLYSIM uses up to an 8 dimensional simplex, one for each
  97. coefficient, so needs up to 9 equations. Consider the 2d one for illustration.
  98.  
  99. We have some response, z, such that z = f(x,y), but we don't know what. In the
  100. basic simplex method, we test 3 points, B, N and W, and get the Best, Next best
  101. and Worst responses respectively. We then take a line between B and N and find
  102. the centre of it, C - then reflect W through that centre point to get a new
  103. point, A :
  104.                          The figure BNW is the old simplex, and BNA is the
  105.                          new one. If we now test the response at A, and compare
  106.            B             it with those at B and N, we can repeat the process.
  107.                          Doing this often enough will home the simplex in on
  108.                          the optimum response (think about it).
  109.    W       C       A
  110.  
  111.  
  112.            N
  113.  
  114. However, the problem with this is 3 fold. Firstly, the simplex stays the same
  115. size, so there is a limit to how accurately we can home in on the optimum. Also
  116. because of this, large "distances" on the x,y surface are covered fairly slowly
  117. if we make the figure small enough to get a reasonable resolution.
  118. The third problem is that, other than looking for repetition of the position
  119. of the simplex, there is little opportunity for detecting when the optimum has
  120. been reached and thus when to stop the process.
  121.  
  122. The answer to these problems comes with "modified" or "accelerated" simplex,
  123. which is as above with additions:
  124.  
  125.               B                      Now we reflect to find A, as before, but
  126.                                      this time we check the response at A first
  127.                                      and modify the simplex:
  128.   W     F     C     G     A      H   If response at A is BETTER than B, we're
  129.                                      obviously going in the right general
  130.                                      direction, so double the W translation and
  131.               N                      make the new simplex BNH instead.
  132. If response at A is between B and N, stay at A, but if it is between W and N,
  133. we must be careful not to overshoot, so the new simplex is BNG. If response at
  134. A is worse than W, the new simplex is BNF.
  135. In practice, this means that the simplex gets bigger to cover large "distances"
  136. toward the optimum, then shrinks itself around it to home in with a higher
  137. resolution. This gives a method of stopping the process as we can elect to
  138. terminate the simplex loop when it has got below a certain size (for example,
  139. 0.1% of the total Y-range - the sort of thing POLYSIM does).
  140. POLYSIM uses this this method, but with up to 8 dimensions, to optimize the
  141. combination of coefficients such that |(y(calculated) - y(given))| is minimized.
  142. The point at which it stops, and hence the resolution, is set within the
  143. program, but can be changed with recompilation.
  144.  
  145. Acknowledgements:
  146.  
  147. What I know about simplex optimization comes from writing a teaching program
  148. in 1988 for the University of Edinburgh Chemistry Department. POLYSIM is an
  149. application based upon experience gained in that project, which was carried
  150. out for Drs. Kenneth Lawley and Ian Gosney.
  151. The paper I was referred to was:
  152. S.N. Deming & S.L. Morgan,  Analytical Chemistry vol.45, 278A (1973),
  153. and further references can be found at the end of this, though I have not
  154. looked at them.
  155.  
  156.  
  157. Disclaimer and such like:
  158.  
  159. This was written by me for me. I'm not going to accept any hassle over it
  160. since I have not ripped anyone off and am distributing it because it has
  161. come to my attention that some people might find it useful.
  162. I've included source code as well as IBM PC executable in the archive
  163. supplied, for those who want to play with it (and make improvements which
  164. are possible but which escape me at present) or port it to other machines.
  165. I really don't care if anyone changes anything, but unless you're going to
  166. improve it there is not much point. If you do improve it, could you please
  167. mail them to me at one of the addresses below with a description of the
  168. modification. Anything implemented will be forwarded with acknowledgements.
  169. The same goes for constructive criticism. Flame will go to /dev/null.
  170.  
  171. Contact:
  172. Anyone wishing to contact me about this program can do so at the following
  173. addresses:
  174.  
  175. SnailMail: D.J. Murphy
  176.            Room 213
  177.            Chemistry Department
  178.            Edinburgh University
  179.            King's Buildings
  180.            West Mains Road
  181.            Edinburgh
  182.            Scotland
  183.            EH9 3JJ
  184.  
  185. Email:
  186.           JANET                                     ARPA
  187.   djm@uk.ac.edinburgh.etive           djm%ed.etive@nsfnet-relay.ac.uk
  188.             or                                       or
  189.   Murff@uk.ac.edinburgh               Murff%ed.emas-a@nsfnet-relay.ac.uk
  190.