@Test public void testRollupVariance() throws IOException { int size = TestData.DOUBLE_SRC.length; int GROUPS = 4; int windowSize = size/GROUPS; double[][] input = new double[GROUPS][windowSize]; int count = 0; int i = 0; int j = 0; for (double val : TestData.DOUBLE_SRC) { input[i][j] = val; j++; count++; if (count % windowSize == 0) { i++; j = 0; } } List<BasicRollup> basicRollups = new ArrayList<BasicRollup>(); List<Results> resultsList = new ArrayList<Results>(); for (i = 0; i < GROUPS; i++) { Results r = new Results(); Points<SimpleNumber> inputSlice = new Points<SimpleNumber>(); int timeOffset = 0; for (double val : input[i]) { inputSlice.add(new Points.Point<SimpleNumber>(123456789L + timeOffset++, new SimpleNumber(val))); } BasicRollup basicRollup = BasicRollup.buildRollupFromRawSamples(inputSlice); r.expectedVariance = computeRawVariance(input[i]); r.computedVariance = basicRollup.getVariance().toDouble(); r.expectedAverage = computeRawAverage(input[i]); r.computedAverage = basicRollup.getAverage().toDouble(); basicRollups.add(basicRollup); resultsList.add(r); } for (i = 0; i < GROUPS; i++) { Results result = resultsList.get(i); assertWithinErrorPercent(result.computedAverage, result.expectedAverage); assertWithinErrorPercent(result.computedVariance, result.expectedVariance); } Points<BasicRollup> inputData = new Points<BasicRollup>(); inputData.add(new Points.Point<BasicRollup>(123456789L, basicRollups.get(0))); inputData.add(new Points.Point<BasicRollup>(123456790L, basicRollups.get(1))); BasicRollup basicRollup10min_0 = BasicRollup.buildRollupFromRollups(inputData); assertWithinErrorPercent(basicRollup10min_0.getAverage().toDouble(), computeRawAverage(ArrayUtils.addAll(input[0], input[1]))); assertWithinErrorPercent(basicRollup10min_0.getVariance().toDouble(), computeRawVariance(ArrayUtils.addAll(input[0], input[1]))); inputData = new Points<BasicRollup>(); inputData.add(new Points.Point<BasicRollup>(123456789L, basicRollups.get(2))); inputData.add(new Points.Point<BasicRollup>(123456790L, basicRollups.get(3))); BasicRollup basicRollup10min_1 = BasicRollup.buildRollupFromRollups(inputData); assertWithinErrorPercent(basicRollup10min_1.getAverage().toDouble(), computeRawAverage(ArrayUtils.addAll(input[2], input[3]))); assertWithinErrorPercent(basicRollup10min_1.getVariance().toDouble(), computeRawVariance(ArrayUtils.addAll(input[2], input[3]))); inputData = new Points<BasicRollup>(); inputData.add(new Points.Point<BasicRollup>(123456789L, basicRollup10min_0)); inputData.add(new Points.Point<BasicRollup>(123456790L, basicRollup10min_1)); BasicRollup basicRollup20min_0 = BasicRollup.buildRollupFromRollups(inputData); assertWithinErrorPercent(basicRollup20min_0.getAverage().toDouble(), computeRawAverage(TestData.DOUBLE_SRC)); assertWithinErrorPercent(basicRollup20min_0.getVariance().toDouble(), computeRawVariance(TestData.DOUBLE_SRC)); }
@Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); }
Variance extends AbstractRollupStat { @Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); } }
Variance extends AbstractRollupStat { @Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); } Variance(); @SuppressWarnings("unused") // used by Jackson  Variance(double value); }
Variance extends AbstractRollupStat { @Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); } Variance(); @SuppressWarnings("unused") // used by Jackson  Variance(double value); @Override boolean equals(Object otherObject); @Override boolean isFloatingPoint(); String toString(); @Override double toDouble(); @Override long toLong(); @Override byte getStatType(); }
Variance extends AbstractRollupStat { @Override public double toDouble() { if (needsCompute) compute(); return super.toDouble(); } Variance(); @SuppressWarnings("unused") // used by Jackson  Variance(double value); @Override boolean equals(Object otherObject); @Override boolean isFloatingPoint(); String toString(); @Override double toDouble(); @Override long toLong(); @Override byte getStatType();  }