You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kurt Pernstich <ku...@gmail.com> on 2012/05/31 16:55:02 UTC

[math] PolynomialFitter.fit() stalls

Hi, in certain cases I ran into the problem that the PolynomialFitter.fit()
method stalls, meaning that it does not return, nor throw an Exception. Is
there a way to tell the PolynomialFitter to iterate only N-times to ensure
that my program does not stall?

Maybe I should note that when I used a LevenbergMarquardOptimizer instead
of a GaussNewtonOptimizer the fit worked fine for the limited number of
test cases considered, but this is not a guarantee that the
LevenbergMarquardOptimizer will work for all cases.

Here is a test case that stalls the PolynomialFitter.fit() on my machine:

PolynomialFitter RshuntFitter = new PolynomialFitter(1, new
GaussNewtonOptimizer());
RshuntFitter.addObservedPoint(-0.2, -7.12442E-13);
RshuntFitter.addObservedPoint(-0.199, -4.33397E-13);
RshuntFitter.addObservedPoint(-0.198, -2.823E-13);
RshuntFitter.addObservedPoint(-0.197, -1.40405E-13);
RshuntFitter.addObservedPoint(-0.196, -7.80821E-15);
RshuntFitter.addObservedPoint(-0.195, 6.20484E-14);
RshuntFitter.addObservedPoint(-0.194, 7.24673E-14);
RshuntFitter.addObservedPoint(-0.193, 1.47152E-13);
RshuntFitter.addObservedPoint(-0.192, 1.9629E-13);
RshuntFitter.addObservedPoint(-0.191, 2.12038E-13);
RshuntFitter.addObservedPoint(-0.19, 2.46906E-13);
RshuntFitter.addObservedPoint(-0.189, 2.77495E-13);
RshuntFitter.addObservedPoint(-0.188, 2.51281E-13);
RshuntFitter.addObservedPoint(-0.187, 2.64001E-13);
RshuntFitter.addObservedPoint(-0.186, 2.8882E-13);
RshuntFitter.addObservedPoint(-0.185, 3.13604E-13);
RshuntFitter.addObservedPoint(-0.184, 3.14248E-13);
RshuntFitter.addObservedPoint(-0.183, 3.1172E-13);
RshuntFitter.addObservedPoint(-0.182, 3.12912E-13);
RshuntFitter.addObservedPoint(-0.181, 3.06761E-13);
RshuntFitter.addObservedPoint(-0.18, 2.8559E-13);
RshuntFitter.addObservedPoint(-0.179, 2.86806E-13);
RshuntFitter.addObservedPoint(-0.178, 2.985E-13);
RshuntFitter.addObservedPoint(-0.177, 2.67148E-13);
RshuntFitter.addObservedPoint(-0.176, 2.94173E-13);
RshuntFitter.addObservedPoint(-0.175, 3.27528E-13);
RshuntFitter.addObservedPoint(-0.174, 3.33858E-13);
RshuntFitter.addObservedPoint(-0.173, 2.97511E-13);
RshuntFitter.addObservedPoint(-0.172, 2.8615E-13);
RshuntFitter.addObservedPoint(-0.171, 2.84624E-13);
PolynomialFunction RshuntFit = new PolynomialFunction(RshuntFitter.fit());

Thanks for your help,
Kurt

Re: [math] PolynomialFitter.fit() stalls

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

> > 
> 
> [snip test case]
> 
> > This looks like a bug. Could you please open a ticket on the bug tracking
> > system[1]? Once the issue is created, you should also upload a fully contained
> > unit test demonstrating the problem.
> 
> This is most likely related to the GaussNewtonOptimizer

Yes, hence my request to provide a fully-working self-contained unit tests
that displays the problem.

> (hasn't there
> been a change recently?).

No.

> 
> The test case runs through successfully with the
> LevenbergMarquardtOptimizer.

So?


Regards,
Gilles

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


Re: [math] PolynomialFitter.fit() stalls

Posted by Thomas Neidhart <th...@gmail.com>.
On 05/31/2012 06:12 PM, Gilles Sadowski wrote:
> Hi.
> 

[snip test case]

> This looks like a bug. Could you please open a ticket on the bug tracking
> system[1]? Once the issue is created, you should also upload a fully contained
> unit test demonstrating the problem.

This is most likely related to the GaussNewtonOptimizer (hasn't there
been a change recently?).

The test case runs through successfully with the
LevenbergMarquardtOptimizer.

Thomas

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


Re: [math] PolynomialFitter.fit() stalls

Posted by Kurt Pernstich <ku...@gmail.com>.
Hi, thanks for your quick response !!

My guess is that it will throw an exception if you wait long enough. ;-)
>
Well, not within 90 min ...


This looks like a bug. Could you please open a ticket on the bug tracking
> system[1]? Once the issue is created, you should also upload a fully
> contained
> unit test demonstrating the problem.
>

Done: https://issues.apache.org/jira/browse/MATH-798

Thanks a lot,
Kurt

Re: [math] PolynomialFitter.fit() stalls

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
On Thu, May 31, 2012 at 07:00:58PM +0200, Thomas Neidhart wrote:
> On 05/31/2012 06:12 PM, Gilles Sadowski wrote:
> > Hi.
> > 
> >> Hi, in certain cases I ran into the problem that the PolynomialFitter.fit()
> >> method stalls, meaning that it does not return, nor throw an Exception. Is
> >> there a way to tell the PolynomialFitter to iterate only N-times to ensure
> >> that my program does not stall?
> > 
> > My guess is that it will throw an exception if you wait long enough. ;-)
> 
> In fact it will run forever ;-)

No it shouldn't. If the convergence criterion is never met it will throw an
exception after exhausting all the evaluations (which in the
"PolynomialFitter" is set to Integer.MAX_VALUE). Will be long but not
forever. :-)

> 
> With the default settings there is no criteria to stop the optimization
> process (but you can provide your own ConvergenceChecker which takes
> also iterations into account).

There is a default criterion: it is defined by a default instance of
"SimpleVectorValueChecker".

> 
> After further digging into this, I have seen that the two optimizers
> (GaussNewton, LevenbergMarquardt) use different convergence criteria,
> with the Gauss one being stricter.
> 
> So when providing your test case with the same default settings as for
> the LM than it works also for the GN case:
> 
> PolynomialFitter RshuntFitter =
>    new PolynomialFitter(1, new GaussNewtonOptimizer(
>      new SimplePointChecker(10e-10, Precision.SAFE_MIN)));

Here the checker use the "point" while the default one uses the "value".
It doesn't give an explanation as to why one works and the other not.
One can just deduce that, if there is no bug in optimizer, the convergence
criterion is too stringent for the problem at hand.

> [...]

Best,
Gilles

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


Re: [math] PolynomialFitter.fit() stalls

Posted by Thomas Neidhart <th...@gmail.com>.
On 05/31/2012 06:12 PM, Gilles Sadowski wrote:
> Hi.
> 
>> Hi, in certain cases I ran into the problem that the PolynomialFitter.fit()
>> method stalls, meaning that it does not return, nor throw an Exception. Is
>> there a way to tell the PolynomialFitter to iterate only N-times to ensure
>> that my program does not stall?
> 
> My guess is that it will throw an exception if you wait long enough. ;-)

In fact it will run forever ;-)

With the default settings there is no criteria to stop the optimization
process (but you can provide your own ConvergenceChecker which takes
also iterations into account).

After further digging into this, I have seen that the two optimizers
(GaussNewton, LevenbergMarquardt) use different convergence criteria,
with the Gauss one being stricter.

So when providing your test case with the same default settings as for
the LM than it works also for the GN case:

PolynomialFitter RshuntFitter =
   new PolynomialFitter(1, new GaussNewtonOptimizer(
     new SimplePointChecker(10e-10, Precision.SAFE_MIN)));

In fact the LM optimizer uses two different convergence criteria (the
provided ConvergenceChecker and additional ones that are provided at
construction time) and uses both in the optimization process.

Thomas

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


Re: [math] PolynomialFitter.fit() stalls

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

> Hi, in certain cases I ran into the problem that the PolynomialFitter.fit()
> method stalls, meaning that it does not return, nor throw an Exception. Is
> there a way to tell the PolynomialFitter to iterate only N-times to ensure
> that my program does not stall?

My guess is that it will throw an exception if you wait long enough. ;-)

> 
> Maybe I should note that when I used a LevenbergMarquardOptimizer instead
> of a GaussNewtonOptimizer the fit worked fine for the limited number of
> test cases considered, but this is not a guarantee that the
> LevenbergMarquardOptimizer will work for all cases.
> 
> Here is a test case that stalls the PolynomialFitter.fit() on my machine:
> 
> PolynomialFitter RshuntFitter = new PolynomialFitter(1, new
> GaussNewtonOptimizer());
> RshuntFitter.addObservedPoint(-0.2, -7.12442E-13);
> RshuntFitter.addObservedPoint(-0.199, -4.33397E-13);
> RshuntFitter.addObservedPoint(-0.198, -2.823E-13);
> RshuntFitter.addObservedPoint(-0.197, -1.40405E-13);
> RshuntFitter.addObservedPoint(-0.196, -7.80821E-15);
> RshuntFitter.addObservedPoint(-0.195, 6.20484E-14);
> RshuntFitter.addObservedPoint(-0.194, 7.24673E-14);
> RshuntFitter.addObservedPoint(-0.193, 1.47152E-13);
> RshuntFitter.addObservedPoint(-0.192, 1.9629E-13);
> RshuntFitter.addObservedPoint(-0.191, 2.12038E-13);
> RshuntFitter.addObservedPoint(-0.19, 2.46906E-13);
> RshuntFitter.addObservedPoint(-0.189, 2.77495E-13);
> RshuntFitter.addObservedPoint(-0.188, 2.51281E-13);
> RshuntFitter.addObservedPoint(-0.187, 2.64001E-13);
> RshuntFitter.addObservedPoint(-0.186, 2.8882E-13);
> RshuntFitter.addObservedPoint(-0.185, 3.13604E-13);
> RshuntFitter.addObservedPoint(-0.184, 3.14248E-13);
> RshuntFitter.addObservedPoint(-0.183, 3.1172E-13);
> RshuntFitter.addObservedPoint(-0.182, 3.12912E-13);
> RshuntFitter.addObservedPoint(-0.181, 3.06761E-13);
> RshuntFitter.addObservedPoint(-0.18, 2.8559E-13);
> RshuntFitter.addObservedPoint(-0.179, 2.86806E-13);
> RshuntFitter.addObservedPoint(-0.178, 2.985E-13);
> RshuntFitter.addObservedPoint(-0.177, 2.67148E-13);
> RshuntFitter.addObservedPoint(-0.176, 2.94173E-13);
> RshuntFitter.addObservedPoint(-0.175, 3.27528E-13);
> RshuntFitter.addObservedPoint(-0.174, 3.33858E-13);
> RshuntFitter.addObservedPoint(-0.173, 2.97511E-13);
> RshuntFitter.addObservedPoint(-0.172, 2.8615E-13);
> RshuntFitter.addObservedPoint(-0.171, 2.84624E-13);
> PolynomialFunction RshuntFit = new PolynomialFunction(RshuntFitter.fit());

This looks like a bug. Could you please open a ticket on the bug tracking
system[1]? Once the issue is created, you should also upload a fully contained
unit test demonstrating the problem.

Thanks,
Gilles

[1] https://issues.apache.org/jira/browse/MATH

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