Re: Brent solver change.

Posted by Francis Duffy on
URL: http://quantlib.414.s1.nabble.com/Brent-solver-change-tp13747p13751.html

Hi,
 
You are right. This change was made in the HEAD in response to a query to the quantlib-dev group on 26/07/2012. The change is shown below.
 
Regards,
Francis.
 
>svn diff -r {2012-07-26}:HEAD QuantLib\ql\math\solvers1d\brent.hpp
Index: QuantLib/ql/math/solvers1d/brent.hpp
===================================================================
--- QuantLib/ql/math/solvers1d/brent.hpp        (revision 18300)
+++ QuantLib/ql/math/solvers1d/brent.hpp        (revision 18376)
@@ -46,11 +46,22 @@
             Real min1, min2;
             Real froot, p, q, r, s, xAcc1, xMid;
-            // dummy assignements to avoid compiler warning
-            Real d = 0.0, e = 0.0;
-            root_ = xMax_;
-            froot = fxMax_;
+            // we want to start with root_ (which equals the guess) on
+            // one side of the bracket and both xMin_ and xMax_ on the
+            // other.
+            froot = f(root_);
+            ++evaluationNumber_;
+            if (froot * fxMin_ < 0) {
+                xMax_ = xMin_;
+                fxMax_ = fxMin_;
+            } else {
+                xMin_ = xMax_;
+                fxMin_ = fxMax_;
+            }
+            Real d = root_- xMax_;
+            Real e = d;
+
             while (evaluationNumber_<=maxEvaluations_) {
                 if ((froot > 0.0 && fxMax_ > 0.0) ||
                     (froot < 0.0 && fxMax_ < 0.0)) {

 
On Thu, Nov 29, 2012 at 7:11 PM, cf16r <[hidden email]> wrote:
additional issue is that Brent method doesn't take in to account initial guess.
when you call Brent solveImpl method through solver1d.solve with guess as one of the arguments, root_ is set to this value in solve() but just after entering solveImpl() it is changed back to root_=xMax_ without any checking whether guess is correct.
in this scenario I think there is also need to call f(root_) before returning solution.

regards,
cf16



------------------------------------------------------------------------------
Keep yourself connected to Go Parallel:
VERIFY Test and improve your parallel project with help from experts
and peers. http://goparallel.sourceforge.net
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users