Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7F9D9F784 for ; Fri, 31 May 2013 10:57:23 +0000 (UTC) Received: (qmail 85270 invoked by uid 500); 31 May 2013 10:57:22 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 85052 invoked by uid 500); 31 May 2013 10:57:22 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 85001 invoked by uid 99); 31 May 2013 10:57:20 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 May 2013 10:57:20 +0000 Date: Fri, 31 May 2013 10:57:20 +0000 (UTC) From: "Gilles (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (MATH-985) BicubicSpline interpolation returns unexpected values (BicubicSplineInterpolator/BicubicSplineInterpolationFunction) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/MATH-985?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gilles updated MATH-985: ------------------------ Attachment: math985.png I've attached a plot of your example, comparing the old and new code. There are still discrepancies with the original data, but this happens "only" on the border of the interpolation range. I don't know whether this is expected or not. I'm going to replace the unit tests that now fail; that they succeeded with a buggy code proves their uselessness :(. You are warmly welcome to suggest some tests that properly demonstrate expectations from this algorithm. > BicubicSpline interpolation returns unexpected values (BicubicSplineInterpolator/BicubicSplineInterpolationFunction) > -------------------------------------------------------------------------------------------------------------------- > > Key: MATH-985 > URL: https://issues.apache.org/jira/browse/MATH-985 > Project: Commons Math > Issue Type: Bug > Affects Versions: 3.1.1 > Environment: Windows 7 64 bit, 64 bit JVM > Reporter: Johnathan Kool > Attachments: math985.png > > > I've been testing out the Tricubic spline functions, and have been getting some strange values. I dug down a bit, and it seems like they start at the Bicubic level. SplineInterpolator/PolynomialSplineFunction seem to be returning correct values. I set up a block of data that increases linearly, so you'd expect the interpolated values to follow the same trend, except the values tend to overshoot to half the distance between knot points, and then undershoot for the remaining half. Probably the easiest thing would be to show some tests. First - 1D which works fine: > {code:title=SplineTest.java|borderStyle=solid} > import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; > import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; > public class SplineTest { > double[] x = new double[]{.52,.54,.56,.58,.6}; > double[] y = new double[]{76,77,78,79,80}; > > public static void main(String[] args){ > SplineTest st = new SplineTest(); > st.go(); > } > > public void go(){ > SplineInterpolator si = new SplineInterpolator(); > PolynomialSplineFunction sf = si.interpolate(x, y); > > System.out.println(sf.value(0.52)); > System.out.println(sf.value(0.5225)); > System.out.println(sf.value(0.525)); > System.out.println(sf.value(0.5275)); > System.out.println(sf.value(0.53)); > System.out.println(sf.value(0.5325)); > System.out.println(sf.value(0.535)); > System.out.println(sf.value(0.5375)); > System.out.println(sf.value(0.54)); > System.out.println(sf.value(0.5425)); > System.out.println(sf.value(0.545)); > System.out.println(sf.value(0.5475)); > System.out.println(sf.value(0.55)); > System.out.println(sf.value(0.5525)); > System.out.println(sf.value(0.555)); > System.out.println(sf.value(0.5575)); > System.out.println(sf.value(0.56)); > } > } > {code} > and next, 2D which doesn't: > {code:title=BicubicSplineTest.java|borderStyle=solid} > import org.apache.commons.math3.analysis.interpolation.BicubicSplineInterpolatingFunction; > import org.apache.commons.math3.analysis.interpolation.BicubicSplineInterpolator; > public class BicubicSplineTest { > double[] x = new double[]{0,1,2}; > double[] y = new double[]{.52,.54,.56,.58,.6}; > double[] v1 = new double[]{76,77,78,79,80}; > double[][] v2 = new double[][]{v1,v1,v1}; > > public static void main(String[] args){ > BicubicSplineTest bt = new BicubicSplineTest(); > bt.go(); > } > > public void go(){ > BicubicSplineInterpolator bi = new BicubicSplineInterpolator(); > BicubicSplineInterpolatingFunction bf = bi.interpolate(x, y, v2); > > System.out.println(bf.value(1, 0.52)); > System.out.println(bf.value(1, 0.5225)); > System.out.println(bf.value(1, 0.525)); > System.out.println(bf.value(1, 0.5275)); > System.out.println(bf.value(1, 0.53)); > System.out.println(bf.value(1, 0.5325)); > System.out.println(bf.value(1, 0.535)); > System.out.println(bf.value(1, 0.5375)); > System.out.println(bf.value(1, 0.54)); > System.out.println(bf.value(1, 0.5425)); > System.out.println(bf.value(1, 0.545)); > System.out.println(bf.value(1, 0.5475)); > System.out.println(bf.value(1, 0.55)); > System.out.println(bf.value(1, 0.5525)); > System.out.println(bf.value(1, 0.555)); > System.out.println(bf.value(1, 0.5575)); > System.out.println(bf.value(1, 0.56)); > } > } > {code} > The data points increase from 76 to 80 in a linear way. Incrementing by 1/8 the distance to the next point, the 1D spline returns: > 76.0 > 76.125 > 76.25 > 76.375 > 76.5 > 76.625 > 76.75 > 76.875 > 77.0 > 77.125 > 77.25 > 77.375 > 77.5 > 77.625 > 77.75 > 77.875 > 78.0 > The 2D spline returns: > 76.0 > 80.14453124999996 > 80.84375000000003 > 79.24609375000007 > 76.50000000000003 > 73.75390625000007 > 72.15625000000001 > 72.85546874999996 > 76.99999999999997 > 81.14453124999993 > 81.84374999999997 > 80.24609375000006 > 77.50000000000003 > 74.75390625000009 > 73.15625000000004 > 73.85546874999997 > 78.0 > Even though it's still effectively a 1D problem. I'm not sure exactly what's causing it - maybe something when multiplying the coefficients, but thought I should flag it. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira