Opened 11 years ago

Closed 9 years ago

#414 closed defect (fixed)

DiscretizedFunction interpolation methods can fail at low end

Reported by: Peter Powers Owned by: Peter Powers
Priority: minor Milestone: OpenSHA 2.0
Component: commons Version:
Keywords: Cc:

Description

The following email documents the problem and describes reproducibility. The best fix will be to delegate all interpolation routines to a static library so that computationally sensitive code is not repeated as much as it is.

So x= {10,20,30,40,50,60,70,80} throw exceptions, as expected.

x = 100 fails due to a sloppy implementation. In fact all three getInterpolatedY*() methods will fail because the valid range of values is EXCLUSIVE of the lower bound, not INCLUSIVE (the valid range is INCLUSIVE of the UPPER bound, however). This is inconsistent with the range check made early in these methods and should be changed. I actually have a class of static interpolation methods (with test cases) that should be swapped for the repetitive code in ArbDiscrFunction?, but haven't had time to focus on that. They also include extrapolation to values outside the function range. Can you work around this issue for now and I'll bump it up my list of things to fix?

As for the behavior of getXIndexBelow(), it's not an issue or an error. I don't think you read my answer below or the java.util.Arrays javadocs, which both explain what -2 means. What does binary search return if no exact match is found?

For x=150, getXIndexBelow() returns 0 (the index below).
For x=100 (or any lower value), getXIndexBelow() returns -1.

On Dec 17, 2012, at 3:42 PM, Nitin Gupta wrote:

Peter,

The issue should be easy to replicate - for the given XY values
100 0.013609
250 0.033695
500 0.059583
1000 0.093446
1500 0.119977
2500 0.163888
3000 0.177374
5000 0.228356
7000 0.265878
10000 0.314945
try finding the Y values for when x= {10,20,30,40,50,60,70,80,100,150,200,250,333,475,700,800,1000,1200,1300,1500,1800,2000,2475,10000} in log-log domain

Issue #1 will be when you try to get interpolated Y value for x = 100.
Issue #2 will be when yu try to get the interpolated value for x = 150.

For issue #2 with -2 returned how can one get a value at this index since it is negative ?

Thanks

On Mon, Dec 17, 2012 at 2:19 PM, Peter Marion Powers <pmpowers@…> wrote:
Hi Nitin,

I've no doubt there could be problems; however, could you please send a simple test case / main method that illustrates the erroneous behavior? This will save us both time as I won't spend time guessing how to replicate an error, only to do it in a different way than you did, and provide an inappropriate or irrelevant answer. It would be great to have a test case for your first question about ArbitrarilyDiscretizedFunc?.getInterpolatedY_inLogXLogYDomain(double).

As for your second question, did you mean to write an x-value between those at index0 and index1? If yes, then I suggest you read the documentation on binary search in as much as positive values are only returned for exact matches, otherwise -(insertion_point)-1 is returned. A search for a value that falls between the first two values in a sorted array returns -2. A search for a value between index1 and index2 would return -3.

Peter

On Dec 17, 2012, at 2:51 PM, Nitin Gupta wrote:

Another issue with the same function "getXIndexBefore", for a x-value within index1 and index 2, binarySearch function returns -2 whereas it should return 1. Something wrong here ?

On Mon, Dec 17, 2012 at 1:30 PM, Nitin Gupta <niting26@…> wrote:
Peter.

There seems some issue with the getInterpolatedY_inLogXLogYDomain function- The function getXIndexBefore returns -1 if value "x" is at index 0. Shouldn't the function getXIndexBeforejust return the variable "ind" ?

Thanks
Nitin

Change History (2)

comment:1 Changed 9 years ago by Kevin Milner

The new interpolation methods implemented in [10918] for #468 also fixes this issue for all interpolation methods. Will close when that fix is merged to trunk.

comment:2 Changed 9 years ago by Kevin Milner

Resolution: fixed
Status: newclosed

Fixes/updates merged to trunk in [10931], closing.

Note: See TracTickets for help on using tickets.