You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jo...@Actelion.Com on 2004/03/29 16:23:48 UTC

Bug (and fix) on Commons-Math SplineInterpolator

I don't know what the proper way to report a bug but I found the
SplineInterpolator useful for my needs... except that it didn't work (which
was likely for version 0.14)


Here is my fix:



Replace

            double dquot = (yval[1] - yval[0]) / (xval[1] - xval[0]);

            for (int i = 0; i < n - 1; i++) {

                              double dquotNext =

                                     (yval[i + 2] - yval[i + 1]) / (xval[i
+ 2] - xval[i + 1]);

                            b[i] = 6.0 * (dquotNext - dquot);

                            d[i] = 2.0 * (xval[i + 2] - xval[i]);

                            dquot = dquotNext;

                  }





With

            //http://mathworld.wolfram.com/CubicSpline.html

            for (int i = 0; i < n - 1; i++) {

                  b[i] = 3.0 * (yval[i+1] - yval[i]);

                  d[i] = (i>0 && i<n-2)? 4.0: 2.0 ;

            }


I also wrote a PolynomialInterpolator which may be useful if I knew how I
could submit it.

I am looking forward for the first release



Regards,


_________________________
Joel Freyss

*************************************************************************
The information of this e-mail and in any file transmitted with it is
strictly confidential and may be legally privileged.
It is intended solely for the addressee. If you are not the intended
recipient, any copying, distribution or any other use of this e-mail is
prohibited and may be unlawful. In such case, you should please notify the
sender immediately and destroy this e-mail.
The content of this e-mail is not legally binding unless confirmed by
letter. Any views expressed in this message are those of the individual
sender, except where the message states otherwise and the sender is
authorised to state them to be the views of the sender's company.
 For further information about Actelion please see our website at
http://www.actelion.com.
**************************************************************************


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


Re: Bug (and fix) on Commons-Math SplineInterpolator

Posted by Phil Steitz <ph...@steitz.com>.
Al Chou wrote:
> --- Phil Steitz <ph...@steitz.com> wrote:
> 
>>Should be fixed now in CVS.
>>
>>In addition to fixing the impl, I made the following changes:
>>
>>SplineInterpolator.interpolate(double[], double[]) now returns a 
>>PolynomialSplineInterpolator (new class), which has an array of 
>>PolynomialFunctions representing the spline segments.
>>
>>Both PolynomialSplineInterpolator and PolynomialFunction implement the new 
>>DifferentiableUnivariateRealFunction interface. 
>>PolynomialSplineInterpolator exposes its polynomials and knot point arrays 
>>as read-only properties (getters return copies).
>>
>>I added tests to SplineInterpolatorTest (replaces InterpolatorTest) to 
>>verify that the correct coefficients are being computed (in the 
>>"degenerate" cases, testing against analytical values, for the sin case, 
>>using R as a reference) and that the PolynomialSplineFunctions give 
>>consistent values at the knot points and the polynomials "match up" (agree 
>>throgh 2 derivatives) at the knot points.
>>
>>Phil
> 
> 
> 
> Whew, that's a lot of work!  Not to discount any of it, but as I started
> reading the Javadoc for PolynomialSplineFunction I noticed you explicitly say
> 
>     the first two derivatives of "adjacent" polynomials are constrained to
> agree at the knot points
> 
> Isn't that a property more specifically of a cubic spline, or am I just
> ignorant of the definition of splines that use higher (or lower!) order
> polynomials?

Good point.  I suppose that it would be possible to define polynomial 
splines that are not smooth in the sense above.  Also, higher order 
polynomial splines may be constrained to agree through more than 2 
derivatives.  Therefore, I agree that this should be removed from the 
javadoc.  As it says later, the smoothness constraints are not enforced by 
the class in any case.  I will fix this.

Good catch.

Phil


> 
> 
> Al
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business $15K Web Design Giveaway 
> http://promotions.yahoo.com/design_giveaway/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 



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


Re: Bug (and fix) on Commons-Math SplineInterpolator

Posted by Al Chou <ho...@yahoo.com>.
--- Phil Steitz <ph...@steitz.com> wrote:
> Should be fixed now in CVS.
> 
> In addition to fixing the impl, I made the following changes:
> 
> SplineInterpolator.interpolate(double[], double[]) now returns a 
> PolynomialSplineInterpolator (new class), which has an array of 
> PolynomialFunctions representing the spline segments.
> 
> Both PolynomialSplineInterpolator and PolynomialFunction implement the new 
> DifferentiableUnivariateRealFunction interface. 
> PolynomialSplineInterpolator exposes its polynomials and knot point arrays 
> as read-only properties (getters return copies).
> 
> I added tests to SplineInterpolatorTest (replaces InterpolatorTest) to 
> verify that the correct coefficients are being computed (in the 
> "degenerate" cases, testing against analytical values, for the sin case, 
> using R as a reference) and that the PolynomialSplineFunctions give 
> consistent values at the knot points and the polynomials "match up" (agree 
> throgh 2 derivatives) at the knot points.
> 
> Phil


Whew, that's a lot of work!  Not to discount any of it, but as I started
reading the Javadoc for PolynomialSplineFunction I noticed you explicitly say

    the first two derivatives of "adjacent" polynomials are constrained to
agree at the knot points

Isn't that a property more specifically of a cubic spline, or am I just
ignorant of the definition of splines that use higher (or lower!) order
polynomials?


Al

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

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


Re: Bug (and fix) on Commons-Math SplineInterpolator

Posted by Phil Steitz <ph...@steitz.com>.
Should be fixed now in CVS.

In addition to fixing the impl, I made the following changes:

SplineInterpolator.interpolate(double[], double[]) now returns a 
PolynomialSplineInterpolator (new class), which has an array of 
PolynomialFunctions representing the spline segments.

Both PolynomialSplineInterpolator and PolynomialFunction implement the new 
DifferentiableUnivariateRealFunction interface. 
PolynomialSplineInterpolator exposes its polynomials and knot point arrays 
as read-only properties (getters return copies).

I added tests to SplineInterpolatorTest (replaces InterpolatorTest) to 
verify that the correct coefficients are being computed (in the 
"degenerate" cases, testing against analytical values, for the sin case, 
using R as a reference) and that the PolynomialSplineFunctions give 
consistent values at the knot points and the polynomials "match up" (agree 
throgh 2 derivatives) at the knot points.

Phil


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


Re: Bug (and fix) on Commons-Math SplineInterpolator

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Thank you Joel,

It would be good to submit these into bigzilla, you can attach your
changes either as unified diff patches or as java file attachments.

Follow the directions here:

http://jakarta.apache.org/commons/math/developers.html

Cheers,
Mark

On Mon, 2004-03-29 at 09:23, Joel.Freyss@Actelion.Com wrote:
> I don't know what the proper way to report a bug but I found the
> SplineInterpolator useful for my needs... except that it didn't work (which
> was likely for version 0.14)
> 
> 
> Here is my fix:
> 
> 
> 
> Replace
> 
>             double dquot = (yval[1] - yval[0]) / (xval[1] - xval[0]);
> 
>             for (int i = 0; i < n - 1; i++) {
> 
>                               double dquotNext =
> 
>                                      (yval[i + 2] - yval[i + 1]) / (xval[i
> + 2] - xval[i + 1]);
> 
>                             b[i] = 6.0 * (dquotNext - dquot);
> 
>                             d[i] = 2.0 * (xval[i + 2] - xval[i]);
> 
>                             dquot = dquotNext;
> 
>                   }
> 
> 
> 
> 
> 
> With
> 
>             //http://mathworld.wolfram.com/CubicSpline.html
> 
>             for (int i = 0; i < n - 1; i++) {
> 
>                   b[i] = 3.0 * (yval[i+1] - yval[i]);
> 
>                   d[i] = (i>0 && i<n-2)? 4.0: 2.0 ;
> 
>             }
> 
> 
> I also wrote a PolynomialInterpolator which may be useful if I knew how I
> could submit it.
> 
> I am looking forward for the first release
> 
> 
> 
> Regards,
> 
> 
> _________________________
> Joel Freyss
> 
> *************************************************************************
> The information of this e-mail and in any file transmitted with it is
> strictly confidential and may be legally privileged.
> It is intended solely for the addressee. If you are not the intended
> recipient, any copying, distribution or any other use of this e-mail is
> prohibited and may be unlawful. In such case, you should please notify the
> sender immediately and destroy this e-mail.
> The content of this e-mail is not legally binding unless confirmed by
> letter. Any views expressed in this message are those of the individual
> sender, except where the message states otherwise and the sender is
> authorised to state them to be the views of the sender's company.
>  For further information about Actelion please see our website at
> http://www.actelion.com.
> **************************************************************************
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
-- 
Mark R. Diggory
Software Developer - VDC Project
Harvard MIT Data Center
http://www.hmdc.harvard.edu


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