* Dataset for sensitivity analysis fan charts.\r
* \r
* @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
*\r
*/\r
public class SensitivityDataset extends XYDataset {\r
Collections.sort(sorter);\r
\r
int sorterSize = sorter.size();\r
-\r
+ int intervals = sorterSize - 1;\r
+ \r
// MEDIAN\r
+ double medianX = series.get(0).values[0][i];\r
+ double medianY = sorter.get(sorterSize/2);\r
median.add(\r
- series.get(0).values[0][i], \r
- sorter.get(sorterSize/2),\r
- sorter.get(sorterSize/2),\r
- sorter.get(sorterSize/2)\r
+ medianX, \r
+ medianY,\r
+ medianY,\r
+ medianY\r
);\r
\r
// CONFIDENCE BOUNDS\r
for(int j = 0; j < yIntervalSeries.length; j++) {\r
- YIntervalSeries yis = yIntervalSeries[j];\r
+ YIntervalSeries yis = yIntervalSeries[j];\r
double percent = properties.getConfidenceBounds().get(j).getPercent() / 100;\r
- if(n >= (1 / percent) * 2)\r
- yis.add(\r
- series.get(0).values[0][i], \r
- sorter.get(sorterSize/2),\r
- sorter.get((int)(sorterSize / 2.0 - sorterSize * percent / 2.0)),\r
- sorter.get((int)(sorterSize / 2.0 + sorterSize * percent / 2.0 - 1))\r
- );\r
- \r
+ if(n >= (1 / percent) * 2) {\r
+ // Estimate the confidence limits\r
+ double indexLow = (1 - percent) * intervals / 2;\r
+ int indexLowLow = (int)Math.floor(indexLow);\r
+ int indexLowHigh = (int)Math.ceil(indexLow);\r
+ double valueLowLow = sorter.get(indexLowLow);\r
+ double valueLowHigh = sorter.get(indexLowHigh);\r
+ double decimalLow = indexLow - indexLowLow;\r
+ // Linear interpolation; to decrease execution time, use interpolation of degree 0, \r
+ // but I didn't find the current approach too time consuming in a simple test. \r
+ double estimateLow = (valueLowHigh - valueLowLow) * decimalLow + valueLowLow;\r
+ \r
+ double indexHigh = (1 + percent) * intervals / 2;;\r
+ int indexHighLow = (int)Math.floor(indexHigh);\r
+ int indexHighHigh = (int)Math.ceil(indexHigh);\r
+ double valueHighLow = sorter.get(indexHighLow);\r
+ double valueHighHigh = sorter.get(indexHighHigh);\r
+ double decimalHigh = 1 - decimalLow; \r
+ double estimateHigh = (valueHighHigh - valueHighLow) * decimalHigh + valueHighLow;\r
+ yis.add(\r
+ medianX, \r
+ medianY,\r
+ estimateLow,\r
+ estimateHigh\r
+ );\r
+ }\r
}\r
}\r
\r