Post Reply 
Looking for TVM contributions
06-20-2024, 04:03 AM
Post: #73
RE: Looking for TVM contributions
(06-19-2024 09:06 PM)Albert Chan Wrote:  
(06-19-2024 03:47 PM)robve Wrote:  n=480 pv=100000 pmt=-208.333333333333343 fv=0
evals=4, i%=-1.39404957469160446e-17%, FVerror=5.4e+05

(-pmt) > (pv/n), by a smudge. I would expect positive rate (0 is good too)
Still, -1.4e-17% is not too bad (using fma, true rate = +1.89e-17%)

i ≈ 1/p - p/n² = (n²-p²)/(p*n²) = (n+p)*(n-p) / (p*n²)      -- where p=-pv/pmt

lua> fma(n,pmt,-pv) * fma(n,pmt,pv) / (-pv*pmt*n*n)      -- scale by pmt²/pmt²
1.8947806286936e-19

More concerning is huge FVerror, perhaps bug in FV code?

No. The error is in the i% result. As a consequence the TVM model's parameter space suffers large errors.

With previous i% after overshooting the TVM model parameter space isn't badly affected
./tvm 480 '?' 100000 -208.333333333333343 0
1/1 i%= 1e-05 y= 0.00501045666647
2/1 i%= 7.98321085531e-11 y= 3.999917908e-08
3/1 i%= 1.03199085624e-16 y= 2.84217094304e-14
4/1 i%= 6.09287401526e-17 y= 2.84217094304e-14
4, i%=6.0928740152605195e-17%
FVerror=1.5e-11
PVerr=1.5e-11
PMTerr=2.8e-14

With last i% after overshooting the TVM model parameters space error is bad:
./tvm 480 '?' 100000 -208.333333333333343 0
1/1 i%= 1e-05 y= 0.00501045666647
2/1 i%= 7.98321085531e-11 y= 3.999917908e-08
3/1 i%= 1.03199085624e-16 y= 2.84217094304e-14
4/1 i%= 6.09287401526e-17 y= 2.84217094304e-14
4, i%=-1.39404957469160446e-17%
FVerr=5.4e+05
PVerr=5.4e+05
PMTerr=2.6e+02

Which result should we trust? I am inclined to accept the former over the latter.

(06-19-2024 09:06 PM)Albert Chan Wrote:  
robve Wrote:I'm not completely happy about the iguess() (it's your guess_i() code by the way), which works fine in END mode, but is not as good in BEGIN mode. It also can return an overflow >100% causing NaN.

guess_i() is retired from use. Edge rate is now preferred.

Anyway, BEGIN mode {n,pv,pmt,fv} == END mode {n,pv+pmt,pmt,fv-pmt}

Yes, but for iguess() adjusted for pmt this produces bad initial i% guess for some of the more extreme cases and that worries me. I don't understand why and how an adjustment can be safely made. But I digress since guess_i() is retired (it's quite good actually, except for BEGIN mode and a few other cases). For example, I noticed that adjusting pmt for BGN mode in this case n=40 pv=900 pmt=-400 fv=-1000 gives i%=371.725. Now, this is a hard example so it's not unexpected but still.

(06-19-2024 09:06 PM)Albert Chan Wrote:  
test sample #1 Wrote:./tvm 40 ? 900 -40 -1000 1

lua> n,pv,pmt,fv = 40,900,-40,-1000 -- BEGIN mode
lua> pv,fv = pv+pmt, fv-pmt -- END mode
lua> n,pv,pmt,fv
40      860      -40      -960
lua> pmt/fv, pmt/-pv
0.041666666666666664      0.046511627906976744

1 sign changes --> 1 solution, either edge is good.

With BEGIN mode and the Newton solver:
1/1 i%= 4.55232470519 y= -1.77265084526
2/1 i%= 4.75326326796 y=-0.000915829625612
3/1 i%= 4.75336718854 y=-2.40206077251e-10
4/1 i%= 4.75336718857 y= -7.1054273576e-15
i%=4.75336718857102181%
FVerr=1.1e-13
PVerr=0
PMTerr=7.1e-15

After adjusting PV and FV for BEGIN mode there is a sign change because we start at "the wrong side" of the curve but that's no problem:
1/1 i%= 4.75977785174 y= 0.0564948432948
2/1 i%= 4.75336708491 y=-9.13549698112e-07
3/1 i%= 4.75336718857 y= 7.1054273576e-15
4/1 i%= 4.75336718857 y= -7.1054273576e-15
i%=4.75336718857102092%
FVerr=2.3e-13
PVerr=0
PMTerr=7.1e-15

Both are equally good.

When we have to do one more iteration to get on the right side of the curve, then that isn't a big deal.

About the npmt curvature: adjusting npmt for positive f'' is just a sign change of npmt. But root finders don't need to care as we know, because they flip to the other side of the curve anyway (as shown above). Theoretically then they never need to flip back again unless f'' changes sign. For TVM f'' won't change sign I believe, but numerically there is a nonzero possibility that the sign of npmt may flip close to root due to inaccuracies, especially with lower precision solvers. That worries me.

- Rob

"I count on old friends to remain rational"
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Looking for TVM contributions - dm319 - 05-12-2024, 06:58 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:48 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:49 PM
RE: Looking for TVM contributions - dm319 - 05-12-2024, 08:00 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 11:04 AM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:58 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 05:59 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:34 PM
RE: Looking for TVM contributions - dm319 - 05-14-2024, 08:31 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 01:00 PM
RE: Looking for TVM contributions - dm319 - 05-15-2024, 12:57 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 10:05 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 01:43 PM
RE: Looking for TVM contributions - dm319 - 05-25-2024, 08:40 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 11:22 AM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 02:58 PM
RE: Looking for TVM contributions - dm319 - 05-24-2024, 09:22 PM
RE: Looking for TVM contributions - dm319 - 06-02-2024, 02:46 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 02:04 AM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 12:15 PM
RE: Looking for TVM contributions - robve - 06-09-2024, 03:29 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 06:05 PM
RE: Looking for TVM contributions - dm319 - 06-09-2024, 10:00 PM
RE: Looking for TVM contributions - robve - 06-12-2024, 08:48 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 03:23 PM
RE: Looking for TVM contributions - robve - 06-14-2024, 10:11 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:54 AM
RE: Looking for TVM contributions - dm319 - 06-12-2024, 11:56 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 03:05 AM
RE: Looking for TVM contributions - robve - 06-15-2024, 05:48 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 09:52 PM
RE: Looking for TVM contributions - robve - 06-15-2024, 01:38 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 05:18 PM
RE: Looking for TVM contributions - Werner - 06-17-2024, 05:11 PM
RE: Looking for TVM contributions - robve - 06-16-2024, 08:26 PM
RE: Looking for TVM contributions - dm319 - 06-16-2024, 11:55 PM
RE: Looking for TVM contributions - robve - 06-17-2024, 09:03 PM
RE: Looking for TVM contributions - robve - 06-18-2024, 03:27 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 12:57 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 02:01 AM
RE: Looking for TVM contributions - robve - 06-19-2024, 03:47 PM
RE: Looking for TVM contributions - robve - 06-20-2024 04:03 AM
RE: Looking for TVM contributions - robve - 06-20-2024, 05:07 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 04:30 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 06:27 PM
RE: Looking for TVM contributions - robve - 06-20-2024, 02:33 AM
RE: Looking for TVM contributions - robve - 06-21-2024, 09:04 PM
RE: Looking for TVM contributions - robve - 06-22-2024, 08:00 PM
RE: Looking for TVM contributions - robve - 06-23-2024, 06:03 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:39 PM
RE: Looking for TVM contributions - dm319 - 07-05-2024, 09:44 PM



User(s) browsing this thread: 25 Guest(s)