@Override public Data getBuffer() { return new Data(transformer.getBuffer(), data.getHeader(), data.getMap(), data.getDictionary()); }
@Override protected void initializeInternal( final DataDefinition definition, final Data input, final GeneralizationHierarchy[] ahierarchies, final ARXConfiguration config) { // Obtain dictionary final Dictionary dictionary = input.getDictionary(); // Obtain research subset RowSet rSubset = null; if (config.containsCriterion(DPresence.class)) { Set<DPresence> crits = config.getCriteria(DPresence.class); if (crits.size() > 1) { throw new IllegalArgumentException("Only one d-presence criterion supported!"); } for (DPresence dPresence : crits) { rSubset = dPresence.getSubset().getSet(); } } // Create reference to the hierarchies final int[][] data = input.getArray(); hierarchies = new int[data[0].length][][]; for (int i = 0; i < ahierarchies.length; i++) { hierarchies[i] = ahierarchies[i].getArray(); // Column -> Id -> Level -> Output } // Initialize counts cardinalities = new int[data[0].length][][]; for (int i = 0; i < cardinalities.length; i++) { cardinalities[i] = new int[dictionary.getMapping()[i].length][ahierarchies[i].getArray()[0].length]; // Column -> Id -> Level -> Count } for (int i = 0; i < data.length; i++) { // only use the rows contained in the research subset if (rSubset == null || rSubset.contains(i)) { final int[] row = data[i]; for (int column = 0; column < row.length; column++) { cardinalities[column][row[column]][0]++; } } } // Create counts for other levels for (int column = 0; column < hierarchies.length; column++) { final int[][] hierarchy = hierarchies[column]; for (int in = 0; in < hierarchy.length; in++) { final int cardinality = cardinalities[column][in][0]; for (int level = 1; level < hierarchy[in].length; level++) { final int out = hierarchy[in][level]; cardinalities[column][out][level] += cardinality; } } } // Create a cache for the results cache = new double[hierarchies.length][]; for (int i = 0; i < cache.length; i++) { cache[i] = new double[ahierarchies[i].getArray()[0].length]; Arrays.fill(cache[i], NA); } }