commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] Updated: (MATH-304) CurveFitter.fit(ParametricRealFunction, double[]) always returns the same value as the initial guess when used with the LevenbergMarquardtOptimizer
Date Wed, 14 Apr 2010 00:06:00 GMT

     [ https://issues.apache.org/jira/browse/MATH-304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Phil Steitz updated MATH-304:
-----------------------------

    Fix Version/s: 2.1

> CurveFitter.fit(ParametricRealFunction, double[]) always returns the same value as the
initial guess when used with the LevenbergMarquardtOptimizer
> ---------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-304
>                 URL: https://issues.apache.org/jira/browse/MATH-304
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>         Environment: Java, Ubuntu 9.04 (64 bit)
>            Reporter: Daren Drummond
>             Fix For: 2.1
>
>
> CurveFitter.fit(ParametricRealFunction, double[]) always returns the same value as the
initial guess when used with the LevenbergMarquardtOptimizer and the length of the initial
guess array is 1.  Here is my example code:
> {code:title=CurveFitter with LevenbergMarquardtOptimizer|borderStyle=solid}
>   LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer();
>   CurveFitter fitter = new CurveFitter(optimizer);
>   fitter.addObservedPoint(2.805d, 0.6934785852953367d);
>   fitter.addObservedPoint(2.74333333333333d, 0.6306772025518496d);
>   fitter.addObservedPoint(1.655d, 0.9474675497289684);
>   fitter.addObservedPoint(1.725d, 0.9013594835804194d);
>   SimpleInverseFunction sif = new SimpleInverseFunction(); // Class provided below
>   double[] initialguess = new double[1];
>   initialguess[0] = 1.0d;
>   double[] bestCoefficients = fitter.fit(sif, initialguess); // <---- ALWAYS RETURNS
A VALUE OF initialguess !
>     /**
>      * This is my implementation of ParametricRealFunction
>      * Implements y = ax^-1 + b for use with an Apache CurveFitter implementation
>       */
>     private class SimpleInverseFunction implements ParametricRealFunction
>     {
>         public double value(double x, double[] doubles) throws FunctionEvaluationException
>         {
>             //y = ax^-1 + b
>             //"double[] must include at least 1 but not more than 2 coefficients."
>             if(doubles == null || doubles.length ==0 || doubles.length > 2) throw
new FunctionEvaluationException(doubles);
>             double a = doubles[0];
>             double b = 0;
>             if(doubles.length >= 2) b = doubles[1];
>             return a * Math.pow(x, -1d) + b;
>         }
>         public double[] gradient(double x, double[] doubles) throws FunctionEvaluationException
>         {
>             //derivative: -ax^-2
>             //"double[] must include at least 1 but not more than 2 coefficients."
>             if(doubles == null || doubles.length ==0 || doubles.length > 2) throw
new FunctionEvaluationException(doubles);
>             double a = doubles[0];
>             double b = 0;
>             if(doubles.length >= 2) b = doubles[1];
>             double derivative = -a * Math.pow(x, -2d);
>             double[]gradientVector = new double[1];
>             gradientVector[0] = derivative;
>             return gradientVector; 
>         }
>     }
> {code} 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message