home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol195 / fluf11 / t.lbr / FLUF11.DOC < prev    next >
Encoding:
Text File  |  1985-02-10  |  12.5 KB  |  339 lines

  1.                               FLUF
  2.  
  3.                            Version 1.1
  4.                         TURBO Pascal (tm)
  5.                           July 11, 1984
  6.  
  7.                         D.M. Fritz-Rohner
  8.                       Post Office Box 9080
  9.                         Akron, Ohio 44305
  10.  
  11.  
  12.      Thi≤á prograφá derive≤ froφ thσ BASI├ languagσ versioεá preì
  13. senteΣá iε thσ articlσ '┴ Simplσ Minima° Algorithmº b∙ Steveεá A« ì
  14. Ruzinsk∙ founΣ iε Dr« Dobb'≤ Journal¼ Numbe≥ 93¼ July¼ 1984«  
  15.  
  16.      FLU╞á 1.▒ i≤ aε updatσ t∩ thσ FLU╞ 1.░ TURB╧ Pasca∞ version« ì
  17. Seσ FLUF10.DO├ iε FLUF10.LBR«  Thi≤ prograφ i≤ intendeΣ t∩ ruε iε ì
  18. CP/═á (tm⌐á compatiblσá environments«á  Versioε 1.░á i≤á ßá closσ ì
  19. translatioεá oµ thσ MBASI├ (tm⌐ compatiblσ prograφ  founΣ iεá thσ ì
  20. abovσ article« 
  21.  
  22.      Thi≤á versioε furthe≥ reorganize≤ anΣ modifie≤ thσ referencσ ì
  23. code.
  24.  
  25.      Thσ operatinτ environmen⌠ interfacσ i≤ modifieΣ t∩á externaì
  26. lizσá contro∞á paramete≥ specificatioε anΣ t∩ providσ simplσá I/╧ ì
  27. redirectioε o≥ 'steering'«  Prograφ contro∞ inpu⌠ i≤ takeε froφ ß ì
  28. datß filσ anΣ outpu⌠ ma∙ bσ redirecteΣ t∩ thσ CP/═ lst║ devicσ o≥ ì
  29. t∩ ß file« Seσ USAGE.
  30.  
  31. Thσ contro∞ datß filσ ha≤ thσ followinτ structure;
  32.  
  33.      cnx                      - maximum number of iterations
  34.      ccS                      - error convergence value
  35.      m                        - number of parameters
  36.      a(1) cca(1)              - initial parameter values and
  37.      a(2) cca(2)                convergence criteria
  38.       :     :
  39.      a(m) cca(m)
  40.      n                        - number of data points
  41.      ys(1) xs(1) ...          - data values
  42.      ys(2) xs(2) ...
  43.        :     :
  44.      ys(n) xs(n) ...
  45.  
  46.      Notσ tha⌠ thσ usage≤ oµ ═ anΣ ╬ arσ interchageΣ witΦ respec⌠ ì
  47. t∩ thσ referencσ program.
  48.  
  49.      Thσá codσá i≤á enhanceΣ t∩ imposσá reasonablenes≤á test≤á oε ì
  50. contro∞ data«á  Prograφ contro∞ i≤ achieveΣ througΦ ß combinatioε ì
  51. oµá test≤ oε iteratioε count¼á minima° fit¼á anΣ paramete≥á valuσ ì
  52. convergence«á Thσ prograφ test≤ eacΦ iteratioε t∩ determinσá wheì
  53. the≥á minima°á fi⌠á i≤ equa∞ o≥ bette≥ thaε cc╙ anΣá whethe≥á thσ ì
  54. difference≤á betweeε parameter≤ fo≥ best-ye⌠ fi⌠ anΣ presen⌠á fi⌠ ì
  55. arσ closσ withiε thσ ccß values«  FLU╞ convergencσ i≤ no⌠ monotoìèniπ s∩ tha⌠ thi≤ latte≥ tes⌠ i≤ onl∙ loosel∙ relateΣ t∩ ßá Cauch∙ ì
  56. criterion.
  57. ì
  58.      Minima° fi⌠ i≤ modifieΣ t∩ bσ absolutσ rathe≥ thaε relative« ì
  59. Relativσ minima° fault≤ wheε thσ independen⌠ variablσ i≤ zero« Iµ ì
  60. thσ ccß parameter≤ arσ se⌠ t∩ somethinτ 'largeº theε iteratioε i≤ ì
  61. performeΣ withou⌠ regarΣ t∩ paramete≥ convergence«á  Likewisσ fo≥ ì
  62. thσá minima°á criterion«á  Thσ dependen⌠ variablσ value≤á iεá thσ ì
  63. contro∞ filσ neeΣ no⌠ bσ uniforml∙ spaced.
  64.  
  65.      Thσáá initializatioεá oµá thσá 'statσá vectorºá list¼áá i.e« ì
  66. x[1..N,1..M]¼ i≤ externalizeΣ iε ß routinσ giveε thσ generiπ namσ ì
  67. SVIni⌠á t∩á facilitatσá convenien⌠á alternatioεá amonτá differen⌠ ì
  68. applications.
  69.  
  70.      Thσá paramete≥ value≤ arσ useΣ t∩ initializσ thσá sequentia∞ ì
  71. leas⌠á square≤á segmen⌠á oµá thσá processinτá which¼áá iεáá turn¼ ì
  72. initialize≤ thσ 'fluffingº process«  Thσ largσ initia∞ covariancσ ì
  73. matri°á inversσ diagona∞ value≤ makσ thσ sequentia∞ leas⌠ square≤ ì
  74. proces≤ relativel∙ insensitivσ t∩ thσ initia∞ coefficien⌠ values.
  75.  
  76.  
  77. USAGE
  78.  
  79.      Selec⌠á thσá appropriatσ SVIni⌠ versioεá fo≥á inclusioεá anΣ ì
  80. compilσáá thσá prograφá witΦá thσá TURB╧á Com-filσá optioεáá set«  ì
  81. Otherwisσ thσ I/╧ redirectioε i≤ no⌠ meaningful. The command;
  82.  
  83.      A>fluf data
  84.  
  85. execute≤ FLU╞ usinτ thσ datß filσ DAT┴ anΣ output≤ thσ result≤ t∩ ì
  86. thσ CP/═ con║ device« 
  87.  
  88.      A>fluf sp lst:
  89.  
  90. execute≤ FLU╞ witΦ datß froφ S╨ anΣ route≤ thσ outpu⌠ t∩ thσ CP/═ ì
  91. lst║ device.
  92.  
  93.      A>fluf polyfit results
  94.  
  95. execute≤ FLU╞ usinτ POLYFI╘ anΣ put≤ thσ outpu⌠ t∩ filσ RESULTS.
  96.  
  97.  
  98. EXAMPLES
  99.  
  100. Example: 'Simple Polynomial'
  101.  
  102.      Thσá filσá SP/╞á correspond≤ t∩ thσá simples⌠á casσá iεá thσ ì
  103. referencσ articlσ anΣ contain≤ thσ data;
  104.  
  105.      100
  106.      1.e-4
  107.      3
  108.      1.0 1.0
  109.      -.167 1.0
  110. è     .00833 1.0
  111.      50
  112.      3.141076E-02 2.000000E-02
  113.      6.279052E-02 4.000000E-02
  114.           :           :     
  115.           :           :
  116.      9.995066E-01 9.800000E-01
  117.      1.000000E+00 1.000000E+00
  118.  
  119.      Thσá 10░á mean≤á t∩á iteratσ thσá fluffinτá portioεá oµá thσ ì
  120. algorithφá n∩ morσ thaε 10░ times«á  Thσ cc╙ valuσ require≤á tha⌠ ì
  121. thσáá absolutσá valuσá oµá thσá maximuφá differencσá betweeεá an∙ ì
  122. specifieΣá independen⌠ variablσ valuσ anΣ thσ applieΣá polynomia∞ ì
  123. a⌠ thσ correspondinτ dependen⌠ variablσ valuσ bσ n∩ greate≥á thaε ì
  124. 1.e-4.
  125.  
  126.      Thσ │ specifie≤ tha⌠ thei≥ arσ threσ coefficient≤ oµ thσ odΣ ì
  127. polynomial«á  Therefore¼á thσá polynomia∞á i≤á 5tΦá degree«á  Thσ ì
  128. followinτá threσ pair≤ oµ number≤ arσ thσ coefficient≤ anΣá thei≥ ì
  129. convergencσá criteria«á  Thesσá coefficient≤á arσá thσá truncateΣ ì
  130. value≤á oµ thσ firs⌠ threσ term≤ oµ thσ Talo≥ serie≤ fo≥ thσ sinσ ì
  131. function«  Thσ convergencσ criteriß arσ 'largeº s∩ tha⌠ iteratioε ì
  132. i≤ convergencσ controlleΣ b∙ cc╙ anΣ loo≡ controlleΣ b∙ nc°á witΦ ì
  133. coefficien⌠ convergencσ effectivel∙ ignored.
  134.  
  135.      Thσá 5░ specifie≤ tha⌠ therσ arσ fift∙ datß point≤á defininτ ì
  136. thσá functioεá t∩ bσ fitted«á  Thσ value≤ listeΣ herσá arσá thosσ ì
  137. computeΣá b∙ TURB╧ usinτ thσ SI╬ functioε fo≥ thσ samσá uniforml∙ ì
  138. spaceΣ abscissaσ a≤ thosσ iε thσ publisheΣ program.
  139.  
  140. Thσ followinτ command;
  141.  
  142.      A>fluf sp/f test/f
  143.  
  144. processe≤ thi≤ datß anΣ put≤ thσ result≤ iε TEST/╞ whicΦ contain≤ ì
  145. thσ following;
  146.  
  147.    0 1.567756E+00 -1.70207E-01 8.306739E-03 1.000000E+00 4.058555E-01
  148.    1 1.569051E+00 -3.71677E-01 -1.97375E-01 4.961373E-02 4.961373E-02
  149.    2 1.570772E+00 -6.43186E-01 7.241231E-02 1.534320E-04 1.534320E-04
  150.    3 1.570772E+00 -6.43186E-01 7.241231E-02 1.534320E-04 1.566227E-04
  151.    4 1.570678E+00 -6.43058E-01 7.243098E-02 1.244030E-04 1.244030E-04
  152.    5 1.570637E+00 -6.43135E-01 7.256355E-02 1.125686E-04 1.125686E-04
  153.    6 1.570614E+00 -6.42965E-01 7.243932E-02 1.053334E-04 1.053334E-04
  154.    7 1.570587E+00 -6.43024E-01 7.253747E-02 1.006899E-04 1.006899E-04
  155.    8 1.570587E+00 -6.43024E-01 7.253747E-02 1.006899E-04 1.035726E-04
  156.    9 1.570548E+00 -6.42736E-01 7.225356E-02 1.000070E-04 1.000070E-04
  157.   10 1.570524E+00 -6.42757E-01 7.230616E-02 9.094802E-05 9.094802E-05
  158.  
  159. wherσá thσá firs⌠á columε i≤ iteratioεá number¼á thσá nex⌠á threσ ì
  160. column≤á arσ coefficien⌠ values¼á thσ nex⌠ columε i≤ best-ye⌠ fi⌠ ì
  161. anΣ thσ las⌠ columε i≤ presen⌠ iteratioε minimax«  Iteratioε zer∩ ì
  162. show≤á thing≤ a⌠ thσ enΣ oµ sequentia∞ leas⌠ square≤á anΣá beforσ ì
  163. fluffing«á  Therefore¼á thσ threσ coefficient≤ fo≥ iteratioε zer∩ ì
  164. arσ thosσ fo≥ thσ leas⌠ square≤ fit«  Thσ best-ye⌠ i≤ arbitraril∙ ìèinitializeΣ t∩ somethinτ 'large'¼ here¼ one«  Thσ minima° fi⌠ fo≥ ì
  165. thσ leas⌠ square≤ coefficient≤ i≤ abou⌠ 0.40¼á whicΦ i≤ no⌠ grea⌠ ì
  166. fo≥ ß functioε tha⌠ range≤ betweeε zer∩ anΣ one.
  167.  
  168.      Successivσá iteration≤á reducσ minima° t∩ abou⌠ 9.e-╡á whicΦ ì
  169. achieve≤ convergencσ t∩ bette≥ thaε 1.e-┤ withiε 10░á iterations« ì
  170. Thσ coefficient≤ expres≤ thσ relation;
  171.  
  172.                                                 3              5
  173.      SIN(1.570796327*x) ~ 1.570524 x - .642757 x  + .07230616 x
  174.  
  175.  
  176. Example: Michaelis-Menten
  177.  
  178.      Thσ articlσ 'Fittinτ Curve≤ t∩ Dataº b∙ Marc∩ S«á CacecΘ anΣ ì
  179. Williaφ P«á Cacheri≤ iε BYT┼ Magazine¼á Volumσ 9¼á Numbe≥ 5¼ May¼ ì
  180. 198┤á illustrate≤ applicatioε oµ thσ SIMPLE╪ algoritφ usinτ leas⌠ ì
  181. square≤á fi⌠á criterion«á  Thσá functioε fitteΣá i≤á ßá so-calleΣ ì
  182. Michaelis-Menteε function;
  183.  
  184.      ^      a' x
  185.      y  =  ------
  186.            x + b'
  187.  
  188.                           ~     ~
  189. usinτá si°á measurement≤ oµ ° anΣá y«á  Transforφá thi≤á relatioε ì
  190. using;
  191.            ~   ~
  192.      z = - y / x
  193.  
  194. to form;
  195.  
  196.      y = a' + b' z
  197.  
  198. compatible with FLUF.  The data file MM/F contains;
  199.  
  200.      200
  201.      5.3e-3
  202.      2
  203.      0.2 1.0
  204.      3.0 1.0
  205.      6
  206.      0.172 1.68
  207.      0.250 3.33
  208.      0.286 5.00
  209.      0.303 6.67
  210.      0.334 10.0
  211.      0.384 20.0
  212.  
  213. anΣá thσ codσ iε MM/F.PA╙ fo≥ SVIni⌠ tha⌠ initialize≤ thσá 'statσ ì
  214. vectorº lis⌠ x[1..N,1..M▌ contains;
  215.  
  216.      x[i,1] := 1.0 ;
  217.      x[i,2] := -ys[i]/xs[i] ;
  218.  
  219. èThen compiling FLUF and executing the command;
  220.  
  221.      A>fluf mm/f test/f
  222.  
  223. produce≤á ß filσ tha⌠ contain≤ two hundreΣ and one lines¼á thσ firs⌠á anΣ ì
  224. last of which are;
  225.  
  226.    0 4.303436E-01 2.523454E+00 1.000000E+00 1.270990E-02
  227.           :
  228.           :
  229.  200 4.209807E-01 2.398137E+00 9.063552E-03 9.087233E-03
  230.  
  231.  
  232. PERFORMANCE
  233.  
  234. The command;
  235.  
  236.      A>fluf sp/f test/f
  237.  
  238. execute≤ iε abou⌠ 2│ second≤ oε ß ┤ MHz« Z-8░ baseΣ system« Abou⌠ ì
  239. 1▓á second≤á i≤ requireΣ fo≥ loaΣ anΣ leas⌠á square≤á completion« ì
  240. Therefore¼ abou⌠ onσ seconΣ pe≥ flufµ i≤ required.
  241.  
  242.      An∙á comparison≤ t∩ result≤ reporteΣ b∙ Hasting≤ anΣá other≤ ì
  243. depend≤ oε qualificatioε oµ TURBO'≤ SI╬ functioεá representation¼ ì
  244. floatinτ poin⌠ arithmetic¼ etc«  Wσ d∩ no⌠ infe≥ that;
  245.  
  246.           Pi
  247.      sin( -- x) ~ SIN(1.570796327*x)
  248.            2
  249.  
  250.      For comparison, consider the command;
  251.  
  252.      A>simp sp test/s
  253.  
  254. wherσ thσ filσ S╨ contain≤ datß comparablσ t∩ SP/F« Therσ arσ onσ ì
  255. hundreΣ anΣ onσ line≤ iε TEST/S¼ thσ firs⌠ anΣ las⌠ oµ whicΦ are;
  256.  
  257.    0 1.000000E+00 -1.67000E-01 8.330000E-03 2.477106E-01 6.929252E-01
  258.           :
  259.           :
  260.  100 1.548642E+00 -6.22970E-01 8.073769E-02 8.232326E-03 8.428058E-03
  261.  
  262. wherσá columε usagσ correspond≤ t∩ FLUF«á  Thσ algorithφ diΣá no⌠ ì
  263. convergσ anΣ drovσ thσ extremuφ t∩ abou⌠ 8.e-3¼á abou⌠ tw∩ order≤ ì
  264. oµá magnitudσ greate≥ thaε specified«á  Thσ commanΣ requireΣá 12▒ ì
  265. second≤á o≥á abou⌠ 1.▓ second≤ pe≥ simp«á  Thσá slo≈á convergencσ ì
  266. arise≤á mostl∙ froφ thσ cus≡ geometr∙ oµ thσ extremuφ spacσ whicΦ ì
  267. force≤á prematurσá contractioε oµ thσá simple°á figure«á  Furthe≥ ì
  268. convergencσá caεá bσ provokeΣ b∙ restartinτá thσá iteratioεá witΦ ì
  269. fina∞ coefficien⌠ estimate≤ anΣ initia∞ ste≡ sizes.
  270.  
  271. The command;
  272.  
  273.      A>fluf mm/f test/f
  274. è
  275. requires about 49 seconds while the command;
  276.  
  277.      A>simp mm test/s
  278.  
  279. require≤á abou⌠á 4╖á seconds«á  Thσ filσá SIMP11/T.DO├á founΣá iε ì
  280. SIMP11/T.LB╥á discusse≤ thσ result≤ oµ applyinτ thσ minima°á verì
  281. sioε oµ SIM╨ t∩ thi≤ problem with results;
  282.  
  283.    0 3.000000E-01 3.000000E+00 1.231304E-01 1.835169E-01
  284.          :
  285.          :
  286.  200 5.991796E-01 7.085686E+00 5.843624E-02 5.844566E-02
  287.  
  288.      Neithe≥á SIM╨á no≥á FLU╞á convergeΣá t∩á thσá requireΣá fit«  ì
  289. However¼á inspectioε oµ thσ completσ result≤ show≤ FLU╞ unablσ t∩ ì
  290. improvσ thσ fi⌠ afte≥ abou⌠ iteratioε 17╣ whilσ SIM╨ continueΣ t∩ ì
  291. convergσá slowly«á  Notσá tha⌠ FLU╞ qui⌠ witΦ aε erro≥ abou⌠á onσ ì
  292. fiftΦáá oµá SIMP's«áá  Thσá convergencσá criterioεá i≤áá probabl∙ ì
  293. infeasible.
  294.  
  295.  
  296. DISCUSSION
  297.  
  298.      Thσá referencσ articlσ present≤ ß PolyFORTH (tm⌐ »á FM╠á (c⌐ ì
  299. versioεá oµ thσ algorithφ whicΦ incorporate≤ tw∩ modification≤ to ì
  300. thσáá fundamenta∞áá algorithφáá intendeΣáá t∩áá improvσáá runtimσ ì
  301. performance.
  302.   ì
  303.      Thσá firs⌠á compute≤á ßá modifieΣá 'gainºá matri°á baseΣá oε ì
  304. empirica∞ evidencσ oµ faste≥ convergence« Thσ seconΣ modificatioε ì
  305. contract≤á thσá fitteΣ datß se⌠ b∙ retaininτá thosσá point≤á witΦ ì
  306. larges⌠ minima° values«  Thi≤ tend≤ t∩ reducσ thσ fitteΣ datß se⌠ ì
  307. t∩ thosσ point≤ clustereΣ abou⌠ thσ erro≥ functioε extrema.
  308.  
  309.      Neithe≥á oµá thesσ modification≤á i≤á incorporated«á  First¼ ì
  310. empiricall∙á fudginτ thσ gaiε matri° detract≤ froφ thσá ingenuit∙ ì
  311. oµá FLU╞á b∙ failinτ t∩ identif∙ anΣ directl∙ appl∙á thσá probleφ ì
  312. element≤áá analogou≤áá t∩áá measuremen⌠áá variancσáá anΣáá simpl∙ ì
  313. demonstrate≤á thσ robustnes≤ oµ thσ underlyinτ linea≥á estimatioε ì
  314. formulation«áá  Fo≥á example¼áá iεá Kalmaεá contexts¼áá wheεá thσ ì
  315. measuremen⌠á variancσ goe≤ t∩ zero¼á thσ gaiε goe≤ t∩ onσ anΣ thσ ì
  316. estimato≥ converge≤ now.
  317.  
  318.      Second¼á thσá datßá se⌠ contractioεá proces≤á i≤á indirectl∙ ì
  319. estimatinτá thσ coordinate≤ oµ thσ erro≥ functioεá extrema«á  Fo≥ ì
  320. an∙á reasonablσ functioε thi≤ correspond≤ t∩ computinτ thσá zeros ì
  321. oµá thσ erro≥ functioε derivative«á  Somσ adaptivσ formulatioε iε ì
  322. whicΦá thσá extremß location≤ arσ cas⌠ int∩ thσá samσá estimatioε ì
  323. frameworδ a≤ thσ coefficient≤ woulΣ seeφ ß desireablσ objective.
  324.  
  325.      Conside≥á estimatioε oµ thσ parameter≤ fo≥ ß straigh⌠á line«  ì
  326. Iε ß mathematica∞ sense¼á an∙ tw∩ point≤ suffice« However¼ floatì
  327. inτá poin⌠ representatioε map≤ thσ rea∞ number≤ t∩ preservσ relaì
  328. tivσ error«á  Thi≤ mean≤ tha⌠ absolutσ erro≥ i≤ large≥ fo≥ large≥ ìènumber≤á s∩á tha⌠á FLUF'≤ datß se⌠ contractioεá wil∞á selec⌠á thσ ì
  329. large≥ numbers.
  330.  
  331.  
  332. CP/M (tm) Digital Research
  333.  
  334. MBASIC (tm) MicroSoft
  335.  
  336. TURBO Pascal (tm) Borland International
  337.  
  338. PolyFORTH (tm) Forth Technology
  339.  
  340. FML (c) Steven A. Ruzinsky
  341.  
  342.