You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Ole Ersoy <ol...@gmail.com> on 2011/02/04 03:13:31 UTC
[Math] LevenbergMarquardtOptimizerTest Question
Hi,
I have a few questions regarding the implementation of the quadratic problem in the org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizerTest.
I assume the quadratic is defined as:
f(x) = a*x^2 + b*x + c
This is the implementation of the jacobian function:
private double[][] jacobian(double[] variables) {
double[][] jacobian = new double[x.size()][3];
for (int i = 0; i < jacobian.length; ++i) {
jacobian[i][0] = x.get(i) * x.get(i);
jacobian[i][1] = x.get(i);
jacobian[i][2] = 1.0;
}
return jacobian;
}
It seems like the lines
jacobian[i][0] = x.get(i) * x.get(i);
jacobian[i][1] = x.get(i);
jacobian[i][2] = 1.0;
Really should be:
jacobian[i][0] = 2 * x.get(i) * variables[0];
jacobian[i][1] = variables[1];
jacobian[i][2] = 0;
Does that make sense?
My second question has to do with the value function below:
public double[] value(double[] variables) {
double[] values = new double[x.size()];
for (int i = 0; i < values.length; ++i) {
values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) + variables[2];
}
return values;
}
Should this:
values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) + variables[2];
Really be:
values[i] = (variables[0] * x.get(i)*x.get(i) + variables[1]) * x.get(i) + variables[2];
Thanks,
- Ole
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [Math] LevenbergMarquardtOptimizerTest Question
Posted by Ole Ersoy <ol...@gmail.com>.
Hi Luc,
It all makes sense now - Thanks!
Cheers,
- Ole
On 02/04/2011 02:25 AM, Luc Maisonobe wrote:
> Le 04/02/2011 03:13, Ole Ersoy a écrit :
>> Hi,
>
> Hi Ole,
>
>>
>> I have a few questions regarding the implementation of the quadratic
>> problem in the
>> org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizerTest.
>>
>>
>> I assume the quadratic is defined as:
>> f(x) = a*x^2 + b*x + c
>>
>> This is the implementation of the jacobian function:
>>
>> private double[][] jacobian(double[] variables) {
>> double[][] jacobian = new double[x.size()][3];
>> for (int i = 0; i< jacobian.length; ++i) {
>> jacobian[i][0] = x.get(i) * x.get(i);
>> jacobian[i][1] = x.get(i);
>> jacobian[i][2] = 1.0;
>> }
>> return jacobian;
>> }
>>
>> It seems like the lines
>>
>> jacobian[i][0] = x.get(i) * x.get(i);
>> jacobian[i][1] = x.get(i);
>> jacobian[i][2] = 1.0;
>>
>> Really should be:
>>
>> jacobian[i][0] = 2 * x.get(i) * variables[0];
>> jacobian[i][1] = variables[1];
>> jacobian[i][2] = 0;
>>
>> Does that make sense?
>
> No. The Jacobian is the partial derivatives of the function with respect
> to the parameters a, b and c, not with respect to the free variable x.
> So d(ax^2+bx+c)/da = x^2, d(ax^2+bx+c)/db = x, d(ax^2+bx+c)/dc = 1.
>
>>
>> My second question has to do with the value function below:
>>
>> public double[] value(double[] variables) {
>> double[] values = new double[x.size()];
>> for (int i = 0; i< values.length; ++i) {
>> values[i] = (variables[0] * x.get(i) + variables[1]) *
>> x.get(i) + variables[2];
>> }
>> return values;
>> }
>>
>> Should this:
>>
>> values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) +
>> variables[2];
>>
>> Really be:
>>
>> values[i] = (variables[0] * x.get(i)*x.get(i) + variables[1]) * x.get(i)
>> + variables[2];
>
> The two expressions compute exactly the same value. We have written it
> using Hörner's rule. This is a classical method to evaluate polynomials
> that save some multiplications. Look at the parentheses and you will see
> that indeed variables[0] is multiplied twice by x.get(i), once inside
> the parenthesis, and once outside, after variables[1] has been added.
>
> best regards,
> Luc
>
>>
>> Thanks,
>> - Ole
>>
>> ---------------------------------------------------------------------
>> 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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
Re: [Math] LevenbergMarquardtOptimizerTest Question
Posted by Luc Maisonobe <Lu...@free.fr>.
Le 04/02/2011 03:13, Ole Ersoy a écrit :
> Hi,
Hi Ole,
>
> I have a few questions regarding the implementation of the quadratic
> problem in the
> org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizerTest.
>
>
> I assume the quadratic is defined as:
> f(x) = a*x^2 + b*x + c
>
> This is the implementation of the jacobian function:
>
> private double[][] jacobian(double[] variables) {
> double[][] jacobian = new double[x.size()][3];
> for (int i = 0; i < jacobian.length; ++i) {
> jacobian[i][0] = x.get(i) * x.get(i);
> jacobian[i][1] = x.get(i);
> jacobian[i][2] = 1.0;
> }
> return jacobian;
> }
>
> It seems like the lines
>
> jacobian[i][0] = x.get(i) * x.get(i);
> jacobian[i][1] = x.get(i);
> jacobian[i][2] = 1.0;
>
> Really should be:
>
> jacobian[i][0] = 2 * x.get(i) * variables[0];
> jacobian[i][1] = variables[1];
> jacobian[i][2] = 0;
>
> Does that make sense?
No. The Jacobian is the partial derivatives of the function with respect
to the parameters a, b and c, not with respect to the free variable x.
So d(ax^2+bx+c)/da = x^2, d(ax^2+bx+c)/db = x, d(ax^2+bx+c)/dc = 1.
>
> My second question has to do with the value function below:
>
> public double[] value(double[] variables) {
> double[] values = new double[x.size()];
> for (int i = 0; i < values.length; ++i) {
> values[i] = (variables[0] * x.get(i) + variables[1]) *
> x.get(i) + variables[2];
> }
> return values;
> }
>
> Should this:
>
> values[i] = (variables[0] * x.get(i) + variables[1]) * x.get(i) +
> variables[2];
>
> Really be:
>
> values[i] = (variables[0] * x.get(i)*x.get(i) + variables[1]) * x.get(i)
> + variables[2];
The two expressions compute exactly the same value. We have written it
using Hörner's rule. This is a classical method to evaluate polynomials
that save some multiplications. Look at the parentheses and you will see
that indeed variables[0] is multiplied twice by x.get(i), once inside
the parenthesis, and once outside, after variables[1] has been added.
best regards,
Luc
>
> Thanks,
> - Ole
>
> ---------------------------------------------------------------------
> 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