Looking for TVM contributions
|
06-15-2024, 01:38 PM
(This post was last modified: 06-16-2024 12:56 PM by robve.)
Post: #47
|
|||
|
|||
RE: Looking for TVM contributions
I already had considered Newton termination tests and tried them before I posted. I don't post about considerations that don't work or work as well.
Disclaimer: it's experimental, so things can and probably will change when better alternative implementations or combinations emerge. fabs(y) >= 1E-11 1E-12 does not terminate, but 1E-11 is too permissive with larger rate errors and does not offer termination guarantee i + h*h > i this tests i% (scaled 100x), but still permits rate errors (h squared is too optimistic as a practical Newton convergence expectation) results in the PDF j + h*h/10000 > j Albert's version with fractional rate (h is scaled 100x), but this is even worse than the results in the PDF, because of quicker quadratic downscaling of h The three I'm more comfortable with are (edited to add context and the ones I've posted before): } while (y != 0.0 && y != w && g-- > 0); } while (fsign(y) == fsign(w) && fabs(y) < fabs(w)); } while (y != 0.0 && y != w && g-- > 0); } while (y != 0.0 && fabs(y) < fabs(w)); } while (y != 0.0 && y != w && g-- > 0); where w is the previous y=npmt(). The second above repeats until sign change or step increases rather than decreases, then retries again a maximum of g times. The third is similar, but does stop when the sign changes, which I slightly prefer. We pick g >= 3 to be competitive to Secant (for Secant g does not matter too much, g=2 works just fine as in the code shown in previous posts and used in this comparison). Pick g too large and some test cases run too long without improving the rate with Newton. With g=2, 3, 4 and 8 the Newton versus Secant results are: tvmperfcomp-g2348.pdf (Size: 145.98 KB / Downloads: 1) Perhaps a better rate finder might be a hybrid: 1. make a good initial rate guess 2. do one or two Newton steps, if either finds the root then we're done 3. use the two points from 1) 2) to repeat Secant until convergence - Rob "I count on old friends to remain rational" |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 7 Guest(s)