the problem is not with fitting, but with a scale of your y: E13 to E22 get the log, and it may work better then.
On Thu, Oct 14, 2010 at 12:16 PM, Christiaan <[email protected]>wrote: > > Hi, > I am reposting this issue since the original one through nabble forums > somehow didn't get accepted, so I am hoping this one is;-) I am currently > evaluating whether commons Math can be used in our project for regression > analysis. Based on an earlier thread I've tried to apply natural > exponential > curve fitting: > > http://apache-commons.680414.n4.nabble.com/MATH-Need-help-on-math-libraries-for-curve-generation-td1050024.html#a1050024 > > The results are not really promising. If I generate y values for this > function: > y = 20 + 10*e^(2*x) > > the result is: > y = 1.040425114042751E13 + 21.13 * e^(1.7x) > RMS:2.895606396069334E25 > > which isn't a good fit. Any ideas if and how this can be improved? > > initialGuess = new double[] {1,1,1}; > Exp function is like this: > > public class NaturalExp2D implements ParametricRealFunction { > > @Override > public double value(double x, double[] coeffs) throws > FunctionEvaluationException { > double a = coeffs[0]; > double b = coeffs[1]; > double c = coeffs[2]; > double value = a + b*Math.exp(c * x); > return value; > } > > @Override > public double[] gradient(double x, double[] coeffs) throws > FunctionEvaluationException { > double[] gradient = new double[3]; > double a = coeffs[0]; > double b = coeffs[1]; > double c = coeffs[2]; > gradient[0] = 1.0; // this is dy/da > final double exp = Math.exp(c * x); > gradient[1] = exp; // this is dy/db > gradient[2] = b * x * exp; // this is dy/dc > return gradient; > } > } > > Generated data: > point: 1.0 - 93.89056099 function: 1.0404251140543246E13 > point: 2.0 - 565.9815003 function: 1.0404251141061297E13 > point: 3.0 - 4054.287935 function: 1.0404251143898256E13 > point: 4.0 - 29829.57987 function: 1.0404251159434023E13 > point: 5.0 - 220284.6579 function: 1.040425124451111E13 > point: 6.0 - 1627567.914 function: 1.0404251710410879E13 > point: 7.0 - 1.202606284E7 function: 1.0404254261774613E13 > point: 8.0 - 8.886112521E7 function: 1.0404268233571447E13 > point: 9.0 - 6.565997114E8 function: 1.040434474602795E13 > point: 10.0 - 4.851651974E9 function: 1.040476374410452E13 > point: 11.0 - 3.5849128481E10 function: 1.0407058264450576E13 > point: 12.0 - 2.64891E11 function: 1.0419623533631664E13 > point: 13.0 - 1.9573E12 function: 1.0488433553061055E13 > point: 14.0 - 1.44626E13 function: 1.086525148713279E13 > point: 15.0 - 1.06865E14 function: 1.292878462686391E13 > point: 16.0 - 7.8963E14 function: 2.4229119971194812E13 > point: 17.0 - 5.83462E15 function: 8.611209942795956E13 > point: 18.0 - 4.31123E16 function: 4.249961262960237E14 > point: 19.0 - 3.18559E17 function: 2.2807953246289075E15 > point: 20.0 - 2.35385E18 function: 1.2443536532475274E16 > point: 21.0 - 1.73927E19 function: 6.8096814619047912E16 > point: 22.0 - 1.28516E20 function: 3.7286570506270682E17 > point: 23.0 - 9.49612E20 function: 2.04184334260224461E18 > point: 24.0 - 7.01674E21 function: 1.1181510946313906E19 > point: 25.0 - 5.18471E22 function: 6.123222584353946E19 > point: 26.0 - 3.83101E23 function: 3.353203185774627E20 > point: 27.0 - 2.83075E24 function: 1.8362835462312472E21 > point: 28.0 - 2.09166E25 function: 1.0055869403818766E22 > point: 29.0 - 1.54554E26 function: 5.506802588140335E22 > > kind regards, > Christiaan > -- > View this message in context: > http://apache-commons.680414.n4.nabble.com/Math-Exponential-curve-fitting-problem-tp2995629p2995629.html > Sent from the Commons - User mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
