| 1 | package de.uka.ipd.sdq.statistics; |
| 2 | |
| 3 | import java.util.List; |
| 4 | |
| 5 | /** |
| 6 | * Implements the "Marginal Confidence Rule" (MCR) for filtering the warm-up |
| 7 | * period of a steady state simulation. |
| 8 | * <p> |
| 9 | * Please note that there is no common interface for warm-up filters so far! |
| 10 | * Thus the interface will likely change soon. |
| 11 | * |
| 12 | * @author Philipp Merkle |
| 13 | * |
| 14 | */ |
| 15 | public class MCRWarmUpFilter { |
| 16 | |
| 17 | private int minIndex = 0; |
| 18 | |
| 19 | public List<Double> filter(List<Double> samples) { |
| 20 | |
| 21 | if (samples.size() <= 150){ |
| 22 | System.out.println("MCRWarmUpFilter Warning: Too few samples to get a meaningful result."); |
| 23 | } |
| 24 | |
| 25 | int truncatedSamplesSize = samples.size(); |
| 26 | double truncatedSamplesSum = 0; |
| 27 | for (Double d : samples) { |
| 28 | truncatedSamplesSum += d; |
| 29 | } |
| 30 | |
| 31 | double minValue = Double.MAX_VALUE; |
| 32 | |
| 33 | for (int i = 0; i < samples.size() - 1; i++) { |
| 34 | int remaining = samples.size() - i; |
| 35 | double factor = 1 / Math.pow(remaining, 3.0); |
| 36 | |
| 37 | double truncatedSampleMean = truncatedSamplesSum |
| 38 | / truncatedSamplesSize; |
| 39 | double sum = 0; |
| 40 | for (int j = i + 1; j < samples.size(); j++) { |
| 41 | sum += Math.pow(samples.get(j) - truncatedSampleMean, 2.0); |
| 42 | } |
| 43 | double d = factor * sum; |
| 44 | |
| 45 | if (d < minValue) { |
| 46 | // System.out.println(i + ": " + d); |
| 47 | minIndex = i; |
| 48 | minValue = d; |
| 49 | } |
| 50 | |
| 51 | truncatedSamplesSize--; |
| 52 | truncatedSamplesSum -= samples.get(0); |
| 53 | } |
| 54 | |
| 55 | if (minIndex > samples.size() / 3){ |
| 56 | //TODO: Kriterium nachschauen und logger |
| 57 | System.out.println("MCRWarmUpFilter Warning: Truncation point is in the last two thirds of the samples, so the confidence in this result is low."); |
| 58 | } |
| 59 | |
| 60 | // TODO Create new list? |
| 61 | return samples.subList(minIndex, samples.size() - 1); |
| 62 | } |
| 63 | |
| 64 | public int getTruncationIndex() { |
| 65 | return minIndex; |
| 66 | } |
| 67 | } |