]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Estimating (linearly) the confidence limits in sensitivity analysis fan charts (refs...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Jun 2013 11:58:55 +0000 (11:58 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Jun 2013 11:58:55 +0000 (11:58 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27520 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/SensitivityDataset.java

index 7eaa62a74a92a47ca108f91765154b723abc3594..b0aceb7471afe39d630ea998e731b215faef5120 100644 (file)
@@ -41,6 +41,7 @@ import org.simantics.utils.datastructures.Pair;
  * Dataset for sensitivity analysis fan charts.\r
  * \r
  * @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
  *\r
  */\r
 public class SensitivityDataset extends XYDataset {\r
@@ -219,27 +220,48 @@ public class SensitivityDataset extends XYDataset {
                         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