You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Italo Maia <it...@gmail.com> on 2012/07/03 21:20:15 UTC

[math] Fit function to data set

I have a nx2 matrix to which I would like to fit a function. For such I
need to define the function parameters (3 in total) that result in the best
R² for the dataset. I'm nowhere familiar with Math commons but I was told
OLSMultipleLinearRegression could do that. I'm in a pitch here as I was
unable to acomplish it. In python, this is easely acomplished as seem in
this example (using scipy)
http://stackoverflow.com/questions/7588371/scipy-leastsq-goodness-of-fit-estimator

How could I do something similar with java math commons? Thanks.

-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Analista de Sistemas / Desenvolvedor Web, Desktop e Mobile (Python, Java,
Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [math] Fit function to data set

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Tue, Jul 03, 2012 at 07:09:30PM -0300, Italo Maia wrote:
> >
> > Did you have a look at the classes in the package
> > "org.apache.commons.math3.optimization" ?
> >
> 
> No, I did not. Let's see...
> 
> Which function?
> >
> 
> This little devil:
> 
> http://dpaste.com/hold/767050/
> 
> *public static double fnc(double t, double a, double b, double c){
>         return Math.log(a) + b * Math.log(t) - c * t;
> }*
> 
> I have *t* in the matrix (first column). Second column are the observed
> values. I need to fit a, b and c.

What you are looking for is probably the "CurveFitter" class (in package
"org.apache.commons.math3.optimization.fitting").

Your function must implement the "ParametricUnivariateFunction" interface
(defined in package "org.apache.commons.math3.analysis").

The optimizers you can use are located in package
"org.apache.commons.math3.optimization.general". [Try the
"LevengergMarquardt" class (using the default constructor).]


HTH,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [math] Fit function to data set

Posted by Italo Maia <it...@gmail.com>.
>
> Did you have a look at the classes in the package
> "org.apache.commons.math3.optimization" ?
>

No, I did not. Let's see...

Which function?
>

This little devil:

http://dpaste.com/hold/767050/

*public static double fnc(double t, double a, double b, double c){
        return Math.log(a) + b * Math.log(t) - c * t;
}*

I have *t* in the matrix (first column). Second column are the observed
values. I need to fit a, b and c.

2012/7/3 Gilles Sadowski <gi...@harfang.homelinux.org>

> org.apache.commons.math3.optimization
>



-- 
"A arrogância é a arma dos fracos."

===========================
Italo Moreira Campelo Maia
Bacharel em Ciência da Computação - UECE
Analista de Sistemas / Desenvolvedor Web, Desktop e Mobile (Python, Java,
Lua)
Coordenador do Pug-CE
-----------------------------------------------------
http://www.italomaia.com/
http://twitter.com/italomaia/
http://eusouolobomau.blogspot.com/
-----------------------------------------------------
Turtle Linux  9.10 - http://tiny.cc/blogturtle910
Turtle Linux 10.10 - http://bit.ly/cEw4ET
===========================

Re: [math] Fit function to data set

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi.

> I have a nx2 matrix to which I would like to fit a function.

Which function?

> For such I
> need to define the function parameters (3 in total) that result in the best
> R² for the dataset. I'm nowhere familiar with Math commons but I was told
> OLSMultipleLinearRegression could do that. I'm in a pitch here as I was
> unable to acomplish it. In python, this is easely acomplished as seem in
> this example (using scipy)
> http://stackoverflow.com/questions/7588371/scipy-leastsq-goodness-of-fit-estimator
> 
> How could I do something similar with java math commons? Thanks.

Did you have a look at the classes in the package
"org.apache.commons.math3.optimization" ?


Regards,
Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org