AggregatorAverageML extends AbstractAggregator { public AggregatorAverageML(VariableContext ctx, String varName, double weightCoeff) { this(ctx, varName, varName, weightCoeff, false); } AggregatorAverageML(VariableContext ctx, String varName, double weightCoeff);  AggregatorAverageML(VariableContext ctx, String varName, String targetName, double weightCoeff, boolean outputSums); @Override void initSpatial(BinContext ctx, WritableVector vector); @Override void initTemporal(BinContext ctx, WritableVector vector); @Override void aggregateSpatial(BinContext ctx, Observation observationVector, WritableVector spatialVector); @Override void completeSpatial(BinContext ctx, int numObs, WritableVector numSpatialObs); @Override void aggregateTemporal(BinContext ctx, Vector spatialVector, int numSpatialObs,
                                  WritableVector temporalVector); @Override void completeTemporal(BinContext ctx, int numTemporalObs, WritableVector temporalVector); @Override void computeOutput(Vector temporalVector, WritableVector outputVector); @Override String toString(); final static double EPS; }
@Test public void testAggregatorAverageML() { AggregatorAverageML agg = new AggregatorAverageML(new MyVariableContext("b"), "b", 0.5); VectorImpl svec = vec(NaN, NaN); VectorImpl tvec = vec(NaN, NaN, NaN); VectorImpl out = vec(NaN, NaN, NaN, NaN); agg.initSpatial(ctx, svec); assertEquals(0.0f, svec.get(0), 0.0f); assertEquals(0.0f, svec.get(1), 0.0f); agg.aggregateSpatial(ctx, obsNT(1.5f), svec); agg.aggregateSpatial(ctx, obsNT(2.5f), svec); agg.aggregateSpatial(ctx, obsNT(0.5f), svec); assertEquals(log(1.5f) + log(2.5f) + log(0.5f), svec.get(0), 1e-5); assertEquals(log(1.5f) * log(1.5f) + log(2.5f) * log(2.5f) + log(0.5f) * log(0.5f), svec.get(1), 1e-5f); agg.completeSpatial(ctx, 3, svec); assertEquals((log(1.5f) + log(2.5f) + log(0.5f)) / sqrt(3f), svec.get(0), 1e-5f); assertEquals( (log(1.5f) * log(1.5f) + log(2.5f) * log(2.5f) + log(0.5f) * log(0.5f)) / sqrt(3f), svec.get(1), 1e-5f); agg.initTemporal(ctx, tvec); assertEquals(0.0f, tvec.get(0), 0.0f); assertEquals(0.0f, tvec.get(1), 0.0f); assertEquals(0.0f, tvec.get(2), 0.0f); agg.aggregateTemporal(ctx, vec(0.3f, 0.09f), 3, tvec); agg.aggregateTemporal(ctx, vec(0.1f, 0.01f), 2, tvec); agg.aggregateTemporal(ctx, vec(0.2f, 0.04f), 1, tvec); agg.aggregateTemporal(ctx, vec(0.1f, 0.01f), 7, tvec); assertEquals(0.3f + 0.1f + 0.2f + 0.1f, tvec.get(0), 1e-5); assertEquals(0.09f + 0.01f + 0.04f + 0.01f, tvec.get(1), 1e-5); assertEquals(sqrt(3f) + sqrt(2f) + sqrt(1f) + sqrt(7f), tvec.get(2), 1e-5); agg.completeTemporal(ctx, 4, tvec); float mean = 1.114932F; float sigma = 0.119713F; float median = 1.108560F; float mode = 1.095926F; agg.computeOutput(tvec, out); assertEquals(mean, out.get(0), 1e-5f); assertEquals(sigma, out.get(1), 1e-5f); assertEquals(median, out.get(2), 1e-5f); assertEquals(mode, out.get(3), 1e-5f); }