From: miettinen Date: Tue, 11 Jun 2013 11:58:55 +0000 (+0000) Subject: Estimating (linearly) the confidence limits in sensitivity analysis fan charts (refs... X-Git-Tag: 1.8.1~295 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=266b0f45ecf59ad10abcd88d7aeee6d88035698d;p=simantics%2Fsysdyn.git Estimating (linearly) the confidence limits in sensitivity analysis fan charts (refs #4324). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27520 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityDataset.java index 7eaa62a7..b0aceb74 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityDataset.java @@ -41,6 +41,7 @@ import org.simantics.utils.datastructures.Pair; * Dataset for sensitivity analysis fan charts. * * @author Teemu Lempinen + * @author Tuomas Miettinen * */ public class SensitivityDataset extends XYDataset { @@ -219,27 +220,48 @@ public class SensitivityDataset extends XYDataset { Collections.sort(sorter); int sorterSize = sorter.size(); - + int intervals = sorterSize - 1; + // MEDIAN + double medianX = series.get(0).values[0][i]; + double medianY = sorter.get(sorterSize/2); median.add( - series.get(0).values[0][i], - sorter.get(sorterSize/2), - sorter.get(sorterSize/2), - sorter.get(sorterSize/2) + medianX, + medianY, + medianY, + medianY ); // CONFIDENCE BOUNDS for(int j = 0; j < yIntervalSeries.length; j++) { - YIntervalSeries yis = yIntervalSeries[j]; + YIntervalSeries yis = yIntervalSeries[j]; double percent = properties.getConfidenceBounds().get(j).getPercent() / 100; - if(n >= (1 / percent) * 2) - yis.add( - series.get(0).values[0][i], - sorter.get(sorterSize/2), - sorter.get((int)(sorterSize / 2.0 - sorterSize * percent / 2.0)), - sorter.get((int)(sorterSize / 2.0 + sorterSize * percent / 2.0 - 1)) - ); - + if(n >= (1 / percent) * 2) { + // Estimate the confidence limits + double indexLow = (1 - percent) * intervals / 2; + int indexLowLow = (int)Math.floor(indexLow); + int indexLowHigh = (int)Math.ceil(indexLow); + double valueLowLow = sorter.get(indexLowLow); + double valueLowHigh = sorter.get(indexLowHigh); + double decimalLow = indexLow - indexLowLow; + // Linear interpolation; to decrease execution time, use interpolation of degree 0, + // but I didn't find the current approach too time consuming in a simple test. + double estimateLow = (valueLowHigh - valueLowLow) * decimalLow + valueLowLow; + + double indexHigh = (1 + percent) * intervals / 2;; + int indexHighLow = (int)Math.floor(indexHigh); + int indexHighHigh = (int)Math.ceil(indexHigh); + double valueHighLow = sorter.get(indexHighLow); + double valueHighHigh = sorter.get(indexHighHigh); + double decimalHigh = 1 - decimalLow; + double estimateHigh = (valueHighHigh - valueHighLow) * decimalHigh + valueHighLow; + yis.add( + medianX, + medianY, + estimateLow, + estimateHigh + ); + } } }