Currently I just want to fit univariate function such as the following
Python function:

def func(x, a, b, c):
    return a * exp(-b * x) + c


I also tried using SimpleCurveFitter to do
it. MyParametricUnivariateFunction implements ParametricUnivariateFunction
and overrides value and gradient methods (
https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/MyParametricUnivariateFunction.java),
and the gradient array is calculated through numerical differentiation. The
curveFit function in OptimizeUtil class was developed for curve fitting
using SimpleCurveFitter (
https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-math/src/main/java/org/meteoinfo/math/optimize/OptimizeUtil.java#L121).
Then the Jython curve_fit function was implemented (
https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-lab/pylib/mipylib/numeric/optimize/minpack.py#L97
).

I tested curve_fit with a simple function and the result looks ok.
[image: cuve_fit_1.png]

But for the function I mentioned at the beginning, curve_fit can not return
the fitting result.
[image: curve_fit_2.png]

I have no idea how to correct it.

Regards
Yaqiang

On Sun, Jul 31, 2022 at 7:49 PM Gilles Sadowski <gillese...@gmail.com>
wrote:

> Le dim. 31 juil. 2022 à 03:46, Yaqiang Wang <yaqiang.w...@gmail.com> a
> écrit :
> >
> > Gilles,
> >
> > Thanks for your reply! Concretely to the point, I want to implement SciPy
> > curve_fit function using Java and Jython through Apache commons math
> > library. Any idea of it?
>
> I guess that your function is multivariate (?); otherwise you'd use the
> "SimpleCurveFitter" class (from package "o.a.c.math4.legacy.fitting".[1]
>
> The non-linear least-squares utility is defined in package
> "o.a.c.math4.legacy.fitting.leastsquares".[2]
> This functionality lets the user provide
>  * the (multivariate) function
>  * the Jacobian matrix
> Do I understand correctly that you want to implement a utility that
> automatically generates the Jacobian through numerical differentiation
> of the function?
>
> Regards,
> Gilles
>
> [1]
> https://commons.apache.org/proper/commons-math/commons-math4-legacy/apidocs/org/apache/commons/math4/legacy/fitting/SimpleCurveFitter.html
> [2]
> https://commons.apache.org/proper/commons-math/commons-math4-legacy/apidocs/org/apache/commons/math4/legacy/fitting/leastsquares/package-summary.html
>
> > > [...]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
>
>

-- 
*************************************************
Dr. Yaqiang Wang
Chinese Academy of Meteorological Sciences (CAMS)
46, Zhong-Guan-Cun South Avenue
Beijing, 100081
China

yaqiang.w...@gmail.com

www.meteothink.org
**************************************************

Reply via email to