You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Roger BAll (JIRA)" <ji...@apache.org> on 2010/02/05 21:34:27 UTC

[jira] Created: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Test for firsst Derivative in PolynomialFunction ERROR
------------------------------------------------------

                 Key: MATH-341
                 URL: https://issues.apache.org/jira/browse/MATH-341
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 2.0
            Reporter: Roger BAll
         Attachments: FirstDerivativePolyNomTest.java

I have written the attached test using our data for generating a curve function

However the first derivative test fails see: testfirstDerivativeComparisonFullPower

Either my test is in error or there is a bug in PolynomialFunction class.


Roger Ball
Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Roger BAll (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Roger BAll updated MATH-341:
----------------------------

    Attachment: FirstDerivativePolyNomTest.java

FirstDerivativePolyNomTest.java

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831637#action_12831637 ] 

Luc Maisonobe commented on MATH-341:
------------------------------------

I will fix the documentation.

The coefficients are valid when the number of points is reduced (for example consider only the 8 or 10 last points, it should work). Also note that polynomials in lagrangian form should really stay in this form and should not be converted to the canonical sum of monomials. It IS ill-conditioned so attempting this for high degree is not advised.

The oscillations you see are not an implementation problem, the mathematical solution is really like this. This is a theoretical problem known as Runge's phenomenon. See for example [http://demonstrations.wolfram.com/RungesPhenomenon/] and especially the high degree versions at the bottom of the page. You will see huge interpolation error at the end of the interval. When using polynomial interpolation, increasing the degree and the number of points but keeping them equidistant does NOT reduce maximal error (in fact for some functions error will tend towards infinity). The expression perfectly fits the sample points you provide but it has no information of what to do between them.

Polynomial interpolation should really be used with care. If you want smoother behavior, you should use several lower degrees polynomials each covering a subrange of your data.


> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Roger BAll (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831690#action_12831690 ] 

Roger BAll commented on MATH-341:
---------------------------------

Looking at "See for example http://demonstrations.wolfram.com/RungesPhenomenon/ " it seems that if you select Chebyshev sample points the error drops dramatically all along the curve. Is this an option in the apache math library?

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe closed MATH-341.
------------------------------

    Resolution: Fixed

added a warning in getCoefficients() method documentation
fixed in subversion repository as of r908190
thanks for reporting the problem

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Roger BAll (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831561#action_12831561 ] 

Roger BAll commented on MATH-341:
---------------------------------

Regarding: 
"So I think there is only a documentation problem: we should warn the user about extracting coefficients in this implementation.

Do you agree with this analysis ?"

Certainly a documentation problem. However, if the coefficients do not result in a curve expression that is valid of the entire range of values for which the curve expression is derived then the curve expression is not really useful in a practical sense. I also the erractic occillations in curve. These occillations are HUGE when comparred to the data. Therefore the expression is not all together valid.

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12831750#action_12831750 ] 

Luc Maisonobe commented on MATH-341:
------------------------------------

You select the points yourself as you provides the x and y arrays, so yes, you can choos points at Chebyshev abscissas.
The array even don't need to be sorted. However, you cannot have two points with the same x value.

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MATH-341) Test for firsst Derivative in PolynomialFunction ERROR

Posted by "Luc Maisonobe (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/MATH-341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830314#action_12830314 ] 

Luc Maisonobe commented on MATH-341:
------------------------------------

I think there are no bugs here.
The first part of the test (method testfirstDerivativeComparison) runs without error.
The second part of the test (method testfirstDerivativeComparisonFullPower) prints coefficients that do not match.

However, the coefficients computed seem wrong to me because
* the getCoefficients method returns an array in increasing degree order (i.e. coeff[0] is the constant term)
* the coefficients array length is d+1 when d is the degree

This implies that the g_coeff array which should contain the coefficients of the derivative must have length myPolyNom.degree() and not myPolyNom.degree()-1 and the following loop should match.  Also the computation of the coefficients of the derivative shoud be:

  g_coeff[i] = f_coeff[i+1] * (i + 1);

instead of

  g_coeff[i] = f_coeff[i]*(myPolyNom.degree()-i);

With these changes, the automatic computation of derivative works.

A first comment on this case is that using polynomial fitting for such functions with large numbers of points shows very large Gibbs oscillations near the interval ends. One way to see this is to draw the curve from the sample points and from evaluation of myPolyNom with x varying from 5 to 30 with a 0.1 step. You will see that the polynomial fits the sample points perfectly, but near interval ends it has HUGE oscillations.

Another comment is that extracting the coefficients from the lagrangian form should be used with caution. Unfortunately, this is written only in the protected computationCoefficients() method javadoc, not in the public getCoefficients() method javadoc ... The computation is ill-conditioned and in fact the coefficients returned in your case are really bad. This could be seen by evaluating the original lagrangian form polynomial and the one reconstructed from the coefficients. The original does match the expected points, the reconstructed one does not.

So I think there is only a documentation problem: we should warn the user about extracting coefficients in this implementation.

Do you agree with this analysis ?

> Test for firsst Derivative in PolynomialFunction ERROR
> ------------------------------------------------------
>
>                 Key: MATH-341
>                 URL: https://issues.apache.org/jira/browse/MATH-341
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Roger BAll
>         Attachments: FirstDerivativePolyNomTest.java
>
>
> I have written the attached test using our data for generating a curve function
> However the first derivative test fails see: testfirstDerivativeComparisonFullPower
> Either my test is in error or there is a bug in PolynomialFunction class.
> Roger Ball
> Creoss Business Solutions 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.