You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Hank Grabowski (JIRA)" <ji...@apache.org> on 2014/09/13 15:25:33 UTC
[jira] [Comment Edited] (MATH-1138) BicubicSplineInterpolator is
returning incorrect interpolated values
[ https://issues.apache.org/jira/browse/MATH-1138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14132695#comment-14132695 ]
Hank Grabowski edited comment on MATH-1138 at 9/13/14 1:25 PM:
---------------------------------------------------------------
I have been investigating this much further. The good news is that from what I can tell the implementation of this function is in line with the Wikipedia article it is based on. The bad news is that this is just not working. The unit tests associated with this aren't even passing a basic 2D linear function test. It should be getting identical results to the expected values. These aren't even close.
I re-implemented the WIkipedia implementation in Octave and I get the same results the Apache Math function does. I rederived the equations from the Wikipedia article and confirmed that the coefficients being used are the correct. It's just not working though.
I looked into how Octave performs the same function. They do not do it this way. They do it by building up from a series of cubic splines. I have a mechanism for implementing it in that way and could take a crack at it if you would like. I know I just joined the Apache project here so let me know what the proper path forward would be to get this assigned to me and contribute it back.
If I do get it, I intend to reform the unit tests so that they have more appropriate tolerances for the functions listed. Even the ones that are passing are doing so because their tolerances are jacked up way too high, which isn't really testing the function numerical accuracy at all.
was (Author: hankg):
I have been investigating this much further. The good news is that from what I can tell the implementation of this function is in line with the Wikipedia article it is based on. The bad news is that this is just not working. The unit tests associated with this aren't even passing a basic 2D linear function test. It should be getting identical results to the expected values. These aren't even close.
I re-implemented the WIkipedia implementation in Octave and I get the same results the Apache Math function does. I rederived the equations from the Wikipedia article and confirmed that the coefficients being used are the correct. It's just not working though.
I looked into how Octave performs the same function. They do not do it this way. They do it by building up from a series of linear cubic splines. I have a mechanism for implementing it in that way and could take a crack at it if you would like. I know I just joined the Apache project here so let me know what the proper path forward would be to get this assigned to me and contribute it back.
If I do get it, I intend to reform the unit tests so that they have more appropriate tolerances for the functions listed. Even the ones that are passing are doing so because their tolerances are jacked up way too high, which isn't really testing the function numerical accuracy at all.
> BicubicSplineInterpolator is returning incorrect interpolated values
> --------------------------------------------------------------------
>
> Key: MATH-1138
> URL: https://issues.apache.org/jira/browse/MATH-1138
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.3
> Reporter: Adam Bedrossian
> Attachments: Interpolated Values from CM and MatLab.docx
>
>
> I have encountered a use case with the BicubicSplineInterpolator where the interpolated values that are being returned seem incorrect. Furthermore, the values do not match those generated by MatLab using the interp2 'cubic' method.
> Here is a snippet of code that uses the interpolator:
> double[] xValues = new double[] {36, 36.001, 36.002};
> double[] yValues = new double[] {-108.00, -107.999, -107.998};
> double[][] fValues = new double[][] {{1915, 1906, 1931},
> {1877, 1889, 1894},
> {1878, 1873, 1888}};
> BicubicSplineInterpolator interpolator = new BicubicSplineInterpolator();
> BicubicSplineInterpolatingFunction interpolatorFunction = interpolator.interpolate(xValues, yValues, fValues);
> double[][] results = new double[9][9];
> double x = 36;
> int arrayIndexX = 0, arrayIndexY = 0;
> while(x <= 36.002) {
> double y = -108;
> arrayIndexY = 0;
> while (y <= -107.998) {
> results[arrayIndexX][arrayIndexY] = interpolatorFunction.value(x, y);
> System.out.println(results[arrayIndexX][arrayIndexY]);
> y = y + 0.00025;
> arrayIndexY++;
> }
> x = x + 0.00025;
> arrayIndexX++;
> }
> Attached is a grid showing x and y values and the corresponding interpolated value from both commons math and MatLab.
> The values produced by commons math are far off from those created by MatLab.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)