简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM