AggregatorOnMaxSet extends AbstractAggregator { public AggregatorOnMaxSet(VariableContext varCtx, String onMaxVarName, String targetName, String... setVarNames) { super(Descriptor.NAME, createOutputFeatureNames(onMaxVarName, setVarNames), createOutputFeatureNames(onMaxVarName, setVarNames), createOutputFeatureNames(targetName, setVarNames)); if (varCtx == null) { throw new NullPointerException("varCtx"); } numSetFeatures = setVarNames.length; onMaxIndex = varCtx.getVariableIndex(onMaxVarName); if (onMaxIndex < 0) { throw new IllegalArgumentException("onMaxIndex < 0"); } setIndexes = new int[setVarNames.length]; for (int i = 0; i < setVarNames.length; i++) { int varIndex = varCtx.getVariableIndex(setVarNames[i]); if (varIndex < 0) { throw new IllegalArgumentException("setIndexes[" + i + "] < 0"); } setIndexes[i] = varIndex; } } AggregatorOnMaxSet(VariableContext varCtx, String onMaxVarName, String targetName, String... setVarNames); @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();  }
@Test public void testAggregatorOnMaxSet() { VectorImpl svec = vec(NaN, NaN, NaN, NaN); VectorImpl tvec = vec(NaN, NaN, NaN, NaN); VectorImpl out = vec(NaN, NaN, NaN, NaN); agg.initSpatial(ctx, svec); assertEquals(Float.NEGATIVE_INFINITY, svec.get(0), 0.0f); assertEquals(NaN, svec.get(1), 0.0f); assertEquals(NaN, svec.get(2), 0.0f); assertEquals(NaN, svec.get(3), 0.0f); agg.aggregateSpatial(ctx, obs(4, 7.3f, 0.5f, 1.1f), svec); agg.aggregateSpatial(ctx, obs(5, 0.1f, 2.5f, 1.5f), svec); agg.aggregateSpatial(ctx, obs(6, 5.5f, 4.9f, 1.4f), svec); assertEquals(1.5f, svec.get(0), 1e-5f); assertEquals(5f, svec.get(1), 1e-5f); assertEquals(0.1f, svec.get(2), 1e-5f); assertEquals(2.5f, svec.get(3), 1e-5f); agg.completeSpatial(ctx, 3, svec); assertEquals(1.5f, svec.get(0), 1e-5f); assertEquals(5f, svec.get(1), 1e-5f); assertEquals(0.1f, svec.get(2), 1e-5f); assertEquals(2.5f, svec.get(3), 1e-5f); agg.initTemporal(ctx, tvec); assertEquals(Float.NEGATIVE_INFINITY, tvec.get(0), 0.0f); assertEquals(NaN, tvec.get(1), 0.0f); assertEquals(NaN, tvec.get(2), 0.0f); assertEquals(NaN, tvec.get(3), 0.0f); agg.aggregateTemporal(ctx, vec(0.3f, 4, 0.2f, 9.7f), 3, tvec); agg.aggregateTemporal(ctx, vec(1.1f, 5, 0.1f, 0.3f), 3, tvec); agg.aggregateTemporal(ctx, vec(4.7f, 6, 0.6f, 7.1f), 3, tvec); assertEquals(4.7f, tvec.get(0), 1e-5f); assertEquals(6f, tvec.get(1), 1e-5f); assertEquals(0.6f, tvec.get(2), 1e-5f); assertEquals(7.1f, tvec.get(3), 1e-5f); agg.computeOutput(tvec, out); assertEquals(4.7f, out.get(0), 1e-5f); assertEquals(6f, out.get(1), 1e-5f); assertEquals(0.6f, out.get(2), 1e-5f); assertEquals(7.1f, out.get(3), 1e-5f); }