/** * @return The raw inputs extracted from the tuple for all 'active fields' */ @Override public Map<FieldName, Object> extractRawInputs(Tuple tuple) { LOG.debug("Extracting raw inputs from tuple: = [{}]", tuple); final Map<FieldName, Object> rawInputs = new LinkedHashMap<>(); for (FieldName activeField : activeFields) { rawInputs.put(activeField, tuple.getValueByField(activeField.getValue())); } LOG.debug("Raw inputs = [{}]", rawInputs); return rawInputs; }
private static ModelOutputs create(PMML pmmlModel, List<String> streams) { final Set<String> fieldNames = new LinkedHashSet<>(); final Evaluator evaluator = JpmmlFactory.newEvaluator(pmmlModel); for (FieldName predictedField : evaluator.getPredictedFields()) { fieldNames.add(predictedField.getValue()); } for (FieldName outputField : evaluator.getOutputFields()) { fieldNames.add(outputField.getValue()); } final Map<String, Fields> toDeclare = streams.stream() .collect(Collectors.toMap(Function.identity(), (x) -> new Fields(new ArrayList<>(fieldNames)))); return new JpmmlModelOutputs(toDeclare); } }
/** * @param dictionary {@link DataDictionary} from model * @return names of features in order */ public static List<String> getFeatureNames(DataDictionary dictionary) { List<DataField> dataFields = dictionary.getDataFields(); Preconditions.checkArgument(dataFields != null && !dataFields.isEmpty(), "No fields in DataDictionary"); return dataFields.stream().map(field -> field.getName().getValue()).collect(Collectors.toList()); }
/** * @param miningSchema {@link MiningSchema} from a model * @return names of features in order */ public static List<String> getFeatureNames(MiningSchema miningSchema) { return miningSchema.getMiningFields().stream().map(field -> field.getName().getValue()) .collect(Collectors.toList()); }
threshold += Math.ulp(threshold); int featureNumber = featureNames.indexOf(simplePredicate.getField().getValue()); decision = new NumericDecision(featureNumber, threshold, defaultDecision); operator == SimpleSetPredicate.BooleanOperator.IS_IN || operator == SimpleSetPredicate.BooleanOperator.IS_NOT_IN); int featureNumber = featureNames.indexOf(simpleSetPredicate.getField().getValue()); Map<String,Integer> valueEncodingMap = categoricalValueEncodings.getValueEncodingMap(featureNumber);
@Test public void testBuildMiningSchema() { MiningSchema miningSchema = AppPMMLUtils.buildMiningSchema(buildTestSchema()); List<MiningField> miningFields = miningSchema.getMiningFields(); assertEquals(4, miningFields.size()); String[] fieldNames = { "foo", "bar", "baz", "bing" }; for (int i = 0; i < fieldNames.length; i++) { assertEquals(fieldNames[i], miningFields.get(i).getName().getValue()); } assertEquals(MiningField.UsageType.SUPPLEMENTARY, miningFields.get(0).getUsageType()); assertEquals(MiningField.UsageType.PREDICTED, miningFields.get(1).getUsageType()); assertEquals(MiningField.UsageType.SUPPLEMENTARY, miningFields.get(2).getUsageType()); assertEquals(MiningField.UsageType.ACTIVE, miningFields.get(3).getUsageType()); assertEquals(OpType.CATEGORICAL, miningFields.get(1).getOpType()); assertEquals(OpType.CONTINUOUS, miningFields.get(3).getOpType()); }
MiningField miningField = miningFields.get(i); String expectedFeature = expectedFeatureNames.get(i); String featureName = miningField.getName().getValue(); assertEquals("Wrong feature at position " + i, expectedFeature, featureName); if (schema.isNumeric(expectedFeature) || schema.isCategorical(expectedFeature)) {
private static void checkDataField(DataField field, String name, Boolean categorical) { assertEquals(name, field.getName().getValue()); if (categorical == null) { assertNull(field.getOpType()); assertNull(field.getDataType()); } else if (categorical) { assertEquals(OpType.CATEGORICAL, field.getOpType()); assertEquals(DataType.STRING, field.getDataType()); } else { assertEquals(OpType.CONTINUOUS, field.getOpType()); assertEquals(DataType.DOUBLE, field.getDataType()); } }
protected static void checkDataDictionary(InputSchema schema, DataDictionary dataDictionary) { assertNotNull(dataDictionary); assertEquals("Wrong number of features", schema.getNumFeatures(), dataDictionary.getNumberOfFields().intValue()); List<DataField> dataFields = dataDictionary.getDataFields(); assertEquals(schema.getNumFeatures(), dataFields.size()); for (DataField dataField : dataFields) { String featureName = dataField.getName().getValue(); if (schema.isNumeric(featureName)) { assertEquals("Wrong op type for feature " + featureName, OpType.CONTINUOUS, dataField.getOpType()); assertEquals("Wrong data type for feature " + featureName, DataType.DOUBLE, dataField.getDataType()); } else if (schema.isCategorical(featureName)) { assertEquals("Wrong op type for feature " + featureName, OpType.CATEGORICAL, dataField.getOpType()); assertEquals("Wrong data type for feature " + featureName, DataType.STRING, dataField.getDataType()); } else { assertNull(dataField.getOpType()); assertNull(dataField.getDataType()); } } }
@Override public String marshal(FieldName value){ // FieldName corresponds to a simple type in PMML XML Schema. Hence, it is possible to encounter a null instance. if(value == null){ return null; } return value.getValue(); } }
static public String formatKey(Object object){ if(object instanceof FieldName){ FieldName name = (FieldName)object; object = name.getValue(); } // End if return format(object); }
public boolean isInterned(){ WeakReference<FieldName> reference = FieldName.cache.get(getValue()); if(reference != null){ FieldName cachedName = reference.get(); return (cachedName == this); } return false; }
/** * @param miningSchema {@link MiningSchema} from a model * @return names of features in order */ public static List<String> getFeatureNames(MiningSchema miningSchema) { return miningSchema.getMiningFields().stream().map(field -> field.getName().getValue()) .collect(Collectors.toList()); }
public static Integer getTargetFieldNumByName(DataDictionary dataDictionary, String name) { int size = dataDictionary.getNumberOfFields(); for(int i = 0; i < size; i++) { DataField dataField = dataDictionary.getDataFields().get(i); if(dataField.getName().getValue().equals(name)) { return i; } } throw new RuntimeException("Target Field Not Found: " + name); }
private String filter(String value){ FieldName name = (value != null ? FieldName.create(value) : null); name = filter(name); return (name != null ? name.getValue() : null); } }
private static List<String> getSchemaFieldViaUsageType(final MiningSchema schema, final FieldUsageType type) { List<String> targetFields = new ArrayList<String>(); for(MiningField f: schema.getMiningFields()) { FieldUsageType uType = f.getUsageType(); if(uType == type) targetFields.add(f.getName().getValue()); } return targetFields; }
public void updateType(FieldName name, OpType opType, DataType dataType){ DataField dataField = getDataField(name); if(dataField == null){ throw new IllegalArgumentException(name.getValue()); } dataField.setOpType(opType); dataField.setDataType(dataType); }
@Override public OutputField getField(){ Output output = getOutput(); FieldName name = getName(); OutputField outputField = OutputUtil.getOutputField(output, name); if(outputField == null){ throw new IllegalArgumentException(name.getValue()); } return outputField; }
@Override public OutputField getField(){ Output output = getOutput(); FieldName name = getName(); OutputField outputField = OutputUtil.getOutputField(output, name); if(outputField == null){ throw new IllegalArgumentException(name.getValue()); } return outputField; }
public Feature getFeature(FieldName name){ List<? extends Feature> features = getFeatures(); for(Feature feature : features){ if((feature.getName()).equals(name)){ return feature; } } throw new IllegalArgumentException(name.getValue()); }