commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 35042] New: - BrentSolver and SecantSolver request boundary values from function twice
Date Tue, 24 May 2005 15:17:22 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35042>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35042

           Summary: BrentSolver and SecantSolver request boundary values
                    from function twice
           Product: Commons
           Version: 1.0 Final
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Math
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: paul.field@db.com


I'm using the BrentSolver class and I noticed that, when I call the solve() 
method,  it requests the boundary values of the initial interval twice from my 
function. The function is quite expensive so it would be good to avoid these 
two duplicate computations.

I had a look at the source code (see below) and I can see that 
the 'verifyBracketing' check requests the boundary values from the function and 
then the 'solve' method itself also requests those values. It looks like the 
SecantSolver will exhibit this behaviour too. Would it be possible to change 
the code so that the values are requested just once?



BrentSolver.class

   public double solve(double min, double max) throws ConvergenceException, 
        FunctionEvaluationException {
        
        clearResult();
        verifyBracketing(min, max, f);
        
        // Index 0 is the old approximation for the root.
        // Index 1 is the last calculated approximation  for the root.
        // Index 2 is a bracket for the root with respect to x1.
        double x0 = min;
        double x1 = max;
        double y0;
        double y1;
        y0 = f.value(x0);  // ******* REQUESTS BOUNDARY (MIN) VALUE HERE ****
        y1 = f.value(x1);  // ******* REQUESTS BOUNDARY (MAX) VALUE HERE ****


UnivariateRealSolverImpl.class:

    protected void verifyBracketing(double lower, double upper, 
            UnivariateRealFunction f) throws FunctionEvaluationException {
        verifyInterval(lower, upper);
        if (!isBracketing(lower, upper, f)) {
            throw new IllegalArgumentException
            ("Function values at endpoints do not have different signs." +
                    "  Endpoints: [" + lower + "," + upper + "]" + 
                    "  Values: [" + f.value(lower) + "," + f.value(upper) 
+ "]");       
        }
    }

    protected boolean isBracketing(double lower, double upper, 
            UnivariateRealFunction f) throws FunctionEvaluationException {
// ******* REQUESTS BOTH BOUNDARY VALUES HERE ****
        return  (f.value(lower) * f.value(upper) < 0);
    }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message