Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exponential Fit with apache commons math

I'm trying to do an exponential fit on various points (x,y) with the formula A*EXP(-BX), trying to find A and B that best suit my points.

double[] xx = curveFitter.fit(new ParametricUnivariateFunction() {
                public double value(double v, double... doubles) {
                    return doubles[0] * Math.exp(-1 * doubles[1] * v);
                }

                public double[] gradient(double v, double... doubles) {
                    return new double[]{v, 1};
                }
            }, new double[]{0, 0});

I get some numbers but they don't fit my points in any way, Can't seem to find any documentation on the above.

Using commons-math3-3.0

like image 595
Rodriguez Avatar asked Oct 29 '12 17:10

Rodriguez


1 Answers

If you are trying to estimate this I suggest you take the log of y which will give you a graph

y' = log(y) = A - B * x;

From this you can calculate the slope and the intercept.

slope = sum((x - mean(x)) * (y' - mean(y')) / sum((x - mean(x))^2) // -B

intercept = mean(y' - x * slope) // A
like image 103
Peter Lawrey Avatar answered Oct 04 '22 14:10

Peter Lawrey