You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by jeesh <mi...@gmail.com> on 2011/07/03 14:47:43 UTC

[Math] Jacobian Matrix of f(x,y)

Hi everyone,
I'm somewhat new to java, but I'm looking to build a least squares
optimization routine for a 2D Gaussian Fit based on this link (about half
way down) http://commons.apache.org/math/userguide/optimization.html.  

Just a general question - how would I go about structuring the Jacobian
matrix for a two component function?

Any help would be appreciated.

--
View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3641890.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


Re: [Math] Jacobian Matrix of f(x,y)

Posted by jeesh <mi...@gmail.com>.
Thanks a lot Luc!  I'm an undergrad with some limited math background but no
programming experience (before this project) so your help has really been
invaluable.

Keep up the good work,
Michael



On Mon, Jul 4, 2011 at 2:45 PM, Luc Maisonobe [via Apache Commons] <
ml-node+3644310-2041674435-249529@n4.nabble.com> wrote:

> Hi Jeesh,
>
>
> Le 04/07/2011 19:47, jeesh a écrit :
> > Thanks!  I've got it to work!  One more quick question - how would I take
> the
> > function&  parameters that the algorithm just spat out and then find the
> > global max z value (and associated x,y coordinate) of the function?
>
> If I understand your needs, this is an additional, independent problem
> from the former one. In the former problem, you had some sampling points
> and wanted to have the parameters of your Gaussian.
>
> Now you have a perfectly defined Gaussian function, using the parameters
> you have estimated from the first problem, and you want to find the
> maximum of this function. Is this right ?
>
> If this is right, then you can simply compute analytically the maximum
> since Gaussian function is really simple. Lets say you defined your
> Gaussian function from parameters p0, p1, p2, p3, p4 as follows:
>
>   g(x, y) = p0 * exp(-(x-p1)^2/p2 - (y-p3)^2/p4)
>
> Then the maximum is at (xmax, ymax) = (p1, p3) and the corresponding
> zmax value is p0.
>
> If you had a much more difficult function for which solving analytically
> the extremum is not feasible, then you should use another optimization
> algorithm (like PowellOptimizer or CMAESOptimizer) that deal with
> multivariate real-valued functions.
>
> Luc
>
> >
> > --
> > View this message in context:
> http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3644174.html
>
> > Sent from the Commons - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3644310&i=0>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3644310&i=1>
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3644310&i=2>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3644310&i=3>
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3644310.html
>  To unsubscribe from [Math] Jacobian Matrix of f(x,y), click here<http://apache-commons.680414.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3641890&code=bWljaGFlbHdvbmc4NjY4QGdtYWlsLmNvbXwzNjQxODkwfDIxMTA1MTgzODc=>.
>
>



-- 
Michael Wong


--
View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3644377.html
Sent from the Commons - User mailing list archive at Nabble.com.

Re: [Math] Jacobian Matrix of f(x,y)

Posted by Luc Maisonobe <Lu...@free.fr>.
Hi Jeesh,


Le 04/07/2011 19:47, jeesh a écrit :
> Thanks!  I've got it to work!  One more quick question - how would I take the
> function&  parameters that the algorithm just spat out and then find the
> global max z value (and associated x,y coordinate) of the function?

If I understand your needs, this is an additional, independent problem 
from the former one. In the former problem, you had some sampling points 
and wanted to have the parameters of your Gaussian.

Now you have a perfectly defined Gaussian function, using the parameters 
you have estimated from the first problem, and you want to find the 
maximum of this function. Is this right ?

If this is right, then you can simply compute analytically the maximum 
since Gaussian function is really simple. Lets say you defined your 
Gaussian function from parameters p0, p1, p2, p3, p4 as follows:

  g(x, y) = p0 * exp(-(x-p1)^2/p2 - (y-p3)^2/p4)

Then the maximum is at (xmax, ymax) = (p1, p3) and the corresponding 
zmax value is p0.

If you had a much more difficult function for which solving analytically 
the extremum is not feasible, then you should use another optimization 
algorithm (like PowellOptimizer or CMAESOptimizer) that deal with 
multivariate real-valued functions.

Luc

>
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3644174.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


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


Re: [Math] Jacobian Matrix of f(x,y)

Posted by jeesh <mi...@gmail.com>.
Thanks!  I've got it to work!  One more quick question - how would I take the
function & parameters that the algorithm just spat out and then find the
global max z value (and associated x,y coordinate) of the function?

--
View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3644174.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


Re: [Math] Jacobian Matrix of f(x,y)

Posted by jeesh <mi...@gmail.com>.
Thanks for the quick replies.  I'll see if I can get that to work and let
you know.

On Sun, Jul 3, 2011 at 10:54 AM, Luc Maisonobe [via Apache Commons] <
ml-node+3642029-1270943118-249529@n4.nabble.com> wrote:

> Le 03/07/2011 14:47, jeesh a écrit :
> > Hi everyone,
>
> Hi Jeesh,
>
> > I'm somewhat new to java, but I'm looking to build a least squares
> > optimization routine for a 2D Gaussian Fit based on this link (about half
>
> > way down) http://commons.apache.org/math/userguide/optimization.html.
> >
> > Just a general question - how would I go about structuring the Jacobian
> > matrix for a two component function?
>
> You can organize the rows as you want. In the quadratic example of the
> user guide page you cite, the rows correspond to simply to different
> measurement points. For simplicity, they have been put in x increasing
> order, but they could have been put in any order. So in your case, you
> could choose something like:
>
>    index 0  : (x0, y0)
>    index 1  : (x0, y1)
>    index 2  : (x0, y2)
>    ...
>    index n-1: (x0, yn-1)
>    index n  : (x1, y0)
>    index n+1: (x1, y1)
>    ...
>
> or the other way round:
>
>    index 0  : (x0, y0)
>    index 1  : (x1, y0)
>    index 2  : (x2, y0)
>    ...
>    index m-1: (xm-1, y0)
>    index m  : (x0, y1)
>    index m+1: (x1, y1)
>    ...
>
> or even a random order, and your (xi,yj) samples may even not be
> regularly spaced but could be random points.
>
> Once you have chose some ordering, you should use the same order for the
> rows of the jacobian matrix and the values of the function as returned
> by the respectively the jacobian method and the value method of your
> DifferentiableMultivariateVectorialFunction implementation. The same
> order should also be used for the target array you pass to the optimize
> method of the optimizer.
>
> best regards,
> Luc
>
> >
> > Any help would be appreciated.
> >
> > --
> > View this message in context:
> http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3641890.html
> > Sent from the Commons - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3642029&i=0>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3642029&i=1>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3642029&i=2>
> For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=3642029&i=3>
>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3642029.html
>  To unsubscribe from [Math] Jacobian Matrix of f(x,y), click here<http://apache-commons.680414.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3641890&code=bWljaGFlbHdvbmc4NjY4QGdtYWlsLmNvbXwzNjQxODkwfDIxMTA1MTgzODc=>.
>
>



-- 
Michael Wong


--
View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3642470.html
Sent from the Commons - User mailing list archive at Nabble.com.

Re: [Math] Jacobian Matrix of f(x,y)

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 03/07/2011 14:47, jeesh a écrit :
> Hi everyone,

Hi Jeesh,

> I'm somewhat new to java, but I'm looking to build a least squares
> optimization routine for a 2D Gaussian Fit based on this link (about half
> way down) http://commons.apache.org/math/userguide/optimization.html.
>
> Just a general question - how would I go about structuring the Jacobian
> matrix for a two component function?

You can organize the rows as you want. In the quadratic example of the 
user guide page you cite, the rows correspond to simply to different 
measurement points. For simplicity, they have been put in x increasing 
order, but they could have been put in any order. So in your case, you 
could choose something like:

   index 0  : (x0, y0)
   index 1  : (x0, y1)
   index 2  : (x0, y2)
   ...
   index n-1: (x0, yn-1)
   index n  : (x1, y0)
   index n+1: (x1, y1)
   ...

or the other way round:

   index 0  : (x0, y0)
   index 1  : (x1, y0)
   index 2  : (x2, y0)
   ...
   index m-1: (xm-1, y0)
   index m  : (x0, y1)
   index m+1: (x1, y1)
   ...

or even a random order, and your (xi,yj) samples may even not be 
regularly spaced but could be random points.

Once you have chose some ordering, you should use the same order for the 
rows of the jacobian matrix and the values of the function as returned 
by the respectively the jacobian method and the value method of your 
DifferentiableMultivariateVectorialFunction implementation. The same 
order should also be used for the target array you pass to the optimize 
method of the optimizer.

best regards,
Luc

>
> Any help would be appreciated.
>
> --
> View this message in context: http://apache-commons.680414.n4.nabble.com/Math-Jacobian-Matrix-of-f-x-y-tp3641890p3641890.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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