Looking for TVM contributions
|
06-14-2024, 10:11 PM
Post: #43
|
|||
|
|||
RE: Looking for TVM contributions
(06-14-2024 06:40 PM)Albert Chan Wrote:(06-14-2024 03:23 PM)robve Wrote: I suspected that the slope would be close to zero for it to jump that far from the root. Right! Initial guesses matter. Can happen with any TVM calc. In the TVM code that I had before I halved I% from an initial guess I%=0.01 until |Y-W| (unscaled "slope" sort of) is larger than the I% rate itself, which prevented this effectively. But that is very ad-hoc. (06-14-2024 06:40 PM)Albert Chan Wrote:Quote:After some experimentation in C code with double precision and in SHARP BASIC, I am not sure if others noticed this as well, but I noticed that Newton suffers from instability when TVM rates converge to zero. Agree. But for Newton running on this 10 BCD machine the longer f(i)/f'(i) expression seems more likely to introduce floating point inaccuracies than the simpler Secant. Whereas the IEEE754 double precision version I have is more well behaved. It's one possible explanation. (06-14-2024 06:40 PM)Albert Chan Wrote: Both methods need accurate f(ε) calculation. The Secant slope estimation is very simple and it is not the true slope f'(ε), so surely Secant will dance around the root as well. That's what we know. I'm just seeing that it converges more nicely than Newton for small rates ε for the example cases we have and the convergence test to use is reliable too. A more expansive set of test examples could tell if this is an artifact of these examples or if this is general. Here is one example. With Newton when pushing on to get to y=0 it hovers for a moment: Code: n=480 pv=100000 pmt=-208.333 fv=0 With Secant this converges right away: Code: n=480 pv=100000 pmt=-208.333 fv=0 What I see is that convergence issues with the Newton version just happen more in 10 BCD precision when there is a loss of 4 to 5 digits. Also when to stop is tricky. Even in IEEE754 double precision, such as for these: n=40 pv=900 pmt=1000 fv=-1000 BGN n=360 pv=0 pmt=-1000 fv=1e+06 n=5 pv=-369494 pmt=17500 fv=540000 n=30 pv=-3200 pmt=-717.44 fv=60000 n=60 pv=243400 pmt=-1363.29 fv=-222976 n=6 pv=-32000 pmt=0 fv=28347 n=60 pv=8000 pmt=-150.97 fv=0 (06-14-2024 06:40 PM)Albert Chan Wrote: After I use {f(0), f'(0), f''(0)} to estimate {f(ε), f'(ε)}, this issue mostly goes away. Makes sense, but this code isn't using {f(0), f'(0), f''(0)}. Also, won't that increase the cost to execute? (06-14-2024 06:40 PM)Albert Chan Wrote: If you like to try Newton's method, use this instead (convergence test using f(i), not i) The rate gets stuck to about 1E-5 in one case and 1E-7 in another which is too far from the root at zero to be detected as a possible zero. One explanation is the use of 10 to 12 BCD (2 guard digits) with lower precision EXPM1 and LOG1P. So losing as much as 4 to 5 digits which is not great. A reliable convergence test should take this into account. (06-14-2024 06:40 PM)Albert Chan Wrote: Per function calls, Secant's method may beat Newtons. But it's almost free, right? Just iterate \( i_{\rm new} := i-(i-i_{\rm old})f/(f-f_{\rm old}) \) with one evaluation of npmt to get f(i) to update i. (06-14-2024 06:40 PM)Albert Chan Wrote: Besides getting f(i) and slope, there are bookkeeping cost too. This is true for Newton that runs fewer iterations. But this benefit diminishes rapidly with more precise initial rate guesses, especially when we only use single precision or only 10 digits then only a few iterations suffice in both cases. - Rob "I count on old friends to remain rational" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 14 Guest(s)