use of org.apache.sysml.runtime.transform.OmitAgent in project incubator-systemml by apache.
the class EncoderFactory method createEncoder.
@SuppressWarnings("unchecked")
public static Encoder createEncoder(String spec, String[] colnames, ValueType[] schema, FrameBlock meta) throws DMLRuntimeException {
Encoder encoder = null;
int clen = schema.length;
try {
//parse transform specification
JSONObject jSpec = new JSONObject(spec);
List<Encoder> lencoders = new ArrayList<Encoder>();
//prepare basic id lists (recode, dummycode, pass-through)
//note: any dummycode column requires recode as preparation
List<Integer> rcIDs = Arrays.asList(ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_RECODE)));
List<Integer> dcIDs = Arrays.asList(ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_DUMMYCODE)));
rcIDs = new ArrayList<Integer>(CollectionUtils.union(rcIDs, dcIDs));
List<Integer> binIDs = TfMetaUtils.parseBinningColIDs(jSpec, colnames);
List<Integer> ptIDs = new ArrayList<Integer>(CollectionUtils.subtract(CollectionUtils.subtract(UtilFunctions.getSequenceList(1, clen, 1), rcIDs), binIDs));
List<Integer> oIDs = Arrays.asList(ArrayUtils.toObject(TfMetaUtils.parseJsonIDList(jSpec, colnames, TfUtils.TXMETHOD_OMIT)));
List<Integer> mvIDs = Arrays.asList(ArrayUtils.toObject(TfMetaUtils.parseJsonObjectIDList(jSpec, colnames, TfUtils.TXMETHOD_IMPUTE)));
//create individual encoders
if (!rcIDs.isEmpty()) {
RecodeAgent ra = new RecodeAgent(jSpec, colnames, clen);
ra.setColList(ArrayUtils.toPrimitive(rcIDs.toArray(new Integer[0])));
lencoders.add(ra);
}
if (!ptIDs.isEmpty())
lencoders.add(new EncoderPassThrough(ArrayUtils.toPrimitive(ptIDs.toArray(new Integer[0])), clen));
if (!dcIDs.isEmpty())
lencoders.add(new DummycodeAgent(jSpec, colnames, schema.length));
if (!binIDs.isEmpty())
lencoders.add(new BinAgent(jSpec, colnames, schema.length, true));
if (!oIDs.isEmpty())
lencoders.add(new OmitAgent(jSpec, colnames, schema.length));
if (!mvIDs.isEmpty()) {
MVImputeAgent ma = new MVImputeAgent(jSpec, colnames, schema.length);
ma.initRecodeIDList(rcIDs);
lencoders.add(ma);
}
//create composite decoder of all created encoders
//and initialize meta data (recode, dummy, bin, mv)
encoder = new EncoderComposite(lencoders);
if (meta != null)
encoder.initMetaData(meta);
} catch (Exception ex) {
throw new DMLRuntimeException(ex);
}
return encoder;
}
Aggregations