| 1 | package de.uka.ipd.sdq.pipesandfilters.framework.filters; |
| 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 | * |
| 9 | * The Filter is still experimental! |
| 10 | * |
| 11 | * @author Philipp Merkle |
| 12 | * |
| 13 | */ |
| 14 | public class MCRWarmUpFilter extends Filter { |
| 15 | |
| 16 | private int minIndex = 0; |
| 17 | |
| 18 | public List<Double> filter(List<Double> samples) { |
| 19 | |
| 20 | if (samples.size() <= 150){ |
| 21 | System.out.println("MCRWarmUpFilter Warning: Too few samples to get a meaningful result."); |
| 22 | } |
| 23 | |
| 24 | int truncatedSamplesSize = samples.size(); |
| 25 | double truncatedSamplesSum = 0; |
| 26 | for (Double d : samples) { |
| 27 | truncatedSamplesSum += d; |
| 28 | } |
| 29 | |
| 30 | double minValue = Double.MAX_VALUE; |
| 31 | |
| 32 | for (int i = 0; i < samples.size() - 1; i++) { |
| 33 | int remaining = samples.size() - i; |
| 34 | double factor = 1 / Math.pow(remaining, 3.0); |
| 35 | |
| 36 | double truncatedSampleMean = truncatedSamplesSum |
| 37 | / truncatedSamplesSize; |
| 38 | double sum = 0; |
| 39 | for (int j = i + 1; j < samples.size(); j++) { |
| 40 | sum += Math.pow(samples.get(j) - truncatedSampleMean, 2.0); |
| 41 | } |
| 42 | double d = factor * sum; |
| 43 | |
| 44 | if (d < minValue) { |
| 45 | // System.out.println(i + ": " + d); |
| 46 | minIndex = i; |
| 47 | minValue = d; |
| 48 | } |
| 49 | |
| 50 | truncatedSamplesSize--; |
| 51 | truncatedSamplesSum -= samples.get(0); |
| 52 | } |
| 53 | |
| 54 | if (minIndex > samples.size() / 3){ |
| 55 | //TODO: Kriterium nachschauen und logger |
| 56 | System.out.println("MCRWarmUpFilter Warning: Truncation point is in the last two thirds of the samples, so the confidence in this result is low."); |
| 57 | } |
| 58 | |
| 59 | // TODO Create new list? |
| 60 | return samples.subList(minIndex, samples.size() - 1); |
| 61 | } |
| 62 | |
| 63 | public int getTruncationIndex() { |
| 64 | return minIndex; |
| 65 | } |
| 66 | } |