@JsonCreator static public FieldName create(String value){ if(value == null || ("").equals(value)){ throw new IllegalArgumentException(); } WeakReference<FieldName> reference = FieldName.cache.get(value); if(reference != null){ FieldName cachedName = reference.get(); if(cachedName != null){ return cachedName; } } FieldName name = new FieldName(value); FieldName.cache.put(value, new WeakReference<>(name)); return name; }
@JsonCreator static public FieldName create(String value){ if(value == null || ("").equals(value)){ throw new IllegalArgumentException(); } WeakReference<FieldName> reference = FieldName.cache.get(value); if(reference != null){ FieldName cachedName = reference.get(); if(cachedName != null){ return cachedName; } } FieldName name = new FieldName(value); FieldName.cache.put(value, new WeakReference<>(name)); return name; }
PMML pmml = loadSasEmPMML() Visitor invalidSubstringCorrector = new AbstractVisitor(){ @Override public VisitorAction visit(Apply apply){ if(isInvalidSubstring(apply)){ List<Expression> expressions = apply.getExpressions(); expressions.set(2, new FieldRef(new FieldName("FMTWIDTH"))); } return super.visit(apply); } private boolean isInvalidSubstring(Apply apply){ if(("substring").equals(apply.getFunction())){ List<Expression> expressions = apply.getExpressions(); Expression lengthArgument = expressions.get(2); if(lengthArgument instanceof Constant){ Constant constant = (Constant)lengthArgument; return ("FMTWIDTH").equals(constant.getValue()); } } return false; } }; invalidSubstringCorrector.applyTo(pmml);
/** * Create PMML neural output for the neural network models * * @param schema * the schema * @param layerID * which layer the output neuron lies * @return neural outputs */ public static NeuralOutputs getOutputFields(final MiningSchema schema, final int layerID) { List<String> outputID = getSchemaFieldViaUsageType(schema, FieldUsageType.TARGET); NeuralOutputs outputs = new NeuralOutputs(); int outputFieldsNum = outputID.size(); outputs.setNumberOfOutputs(outputFieldsNum); for(int i = 0; i < outputFieldsNum; i++) { DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE); field.withExpression(new FieldRef(new FieldName(outputID.get(i)))); outputs.withNeuralOutputs(new NeuralOutput(field, String.valueOf(layerID + "," + i))); } return outputs; }
private LocalTransformations getLocalTranformations(NeuralNetwork model) { // delete target List<DerivedField> derivedFields = model.getLocalTransformations().getDerivedFields(); // add bias DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).withName(new FieldName( PluginConstants.biasValue)); field.withExpression(new Constant(String.valueOf(PluginConstants.bias))); derivedFields.add(field); return new LocalTransformations().withDerivedFields(derivedFields); }
@Override public Result evaluate(Map<Descriptor, ?> values) throws Exception { org.jpmml.evaluator.Evaluator evaluator = (org.jpmml.evaluator.Evaluator) getModelManager(); Map<FieldName, org.jpmml.evaluator.FieldValue> arguments = new LinkedHashMap<FieldName, org.jpmml.evaluator.FieldValue>(); Map<FieldName, DataField> dataFieldMap = new LinkedHashMap<FieldName, DataField>(); List<Descriptor> descriptors = getDescriptors(); for(Descriptor descriptor : descriptors){ FieldName field = FieldNameUtil.encodeDescriptor(descriptor); DataField dataField = dataFieldMap.get(field); if(dataField == null){ dataField = evaluator.getDataField(field); // For compatibility with generic PMML producer software if(dataField == null){ field = new FieldName(descriptor.getId()); dataField = evaluator.getDataField(field); } // End if if(dataField == null){ throw new IllegalArgumentException(); } dataFieldMap.put(field, dataField); } Object value = values.get(descriptor); org.jpmml.evaluator.FieldValue fieldValue = EvaluatorUtil.prepare(evaluator, field, value); arguments.put(field, fieldValue); } Map<FieldName, ?> result = evaluator.evaluate(arguments); Object targetValue = result.get(evaluator.getTargetField()); return new Result(EvaluatorUtil.decode(targetValue), values); }
.withDefaultValue(defaultValue) .withFieldColumnPairs( new FieldColumnPair(new FieldName(CommonUtils.getSimpleColumnName(config, columnConfigList, segmentExpansions, datasetHeaders)), ELEMENT_ORIGIN)).withInlineTable(inlineTable) .withMapMissingTo(missingValue);
public static PMML encodePMML(FieldName targetField, List<String> targetCategories, FeatureList featureList, List<RegressionTree> regTrees, float base_score){ LSBoostEncoder encoder = new LSBoostEncoder(); if(targetField == null){ targetField = FieldName.create("_target"); } Label label = encodeLabel(targetField, targetCategories, encoder); //todo List<Feature> features = new ArrayList<>(); for (int i=0;i<featureList.size();i++){ FieldName fieldName = new FieldName("feature_"+i); DataField dataField = encoder.createDataField(fieldName, OpType.CONTINUOUS, DataType.FLOAT); Feature feature = new ContinuousFeature(encoder, dataField); features.add(feature); } Schema schema = new Schema(label, features); MiningModel miningModel = encodeMiningModel(regTrees, base_score, schema); PMML pmml = encoder.encodePMML(miningModel); return pmml; }
public static PMML encodePMML(FieldName targetField, List<String> targetCategories, FeatureList featureList, List<List<RegressionTree>> regTrees, float base_score, int numClasses){ LKBoostEncoder encoder = new LKBoostEncoder(); if(targetField == null){ targetField = FieldName.create("_target"); } Label label = encodeLabel(targetField, targetCategories, encoder, numClasses); //todo List<Feature> features = new ArrayList<>(); for (int i=0;i<featureList.size();i++){ FieldName fieldName = new FieldName("feature_"+i); DataField dataField = encoder.createDataField(fieldName, OpType.CONTINUOUS, DataType.FLOAT); Feature feature = new ContinuousFeature(encoder, dataField); features.add(feature); } Schema schema = new Schema(label, features); MiningModel miningModel = encodeMiningModel(regTrees, base_score, schema); PMML pmml = encoder.encodePMML(miningModel); return pmml; }
/** * Create the output field, and set the field name, operation type, data type and feature type * * @param fieldName * - the name of output field * @param opType * - operation type * @param dataType * - data type * @param feature * - result feature type * @return OutputField */ protected OutputField createOutputField(String fieldName, OpType opType, DataType dataType, ResultFeatureType feature) { OutputField outputField = new OutputField(); outputField.withName(new FieldName(fieldName)); outputField.withOptype(opType); outputField.withDataType(dataType); outputField.withFeature(feature); return outputField; }
target.setField(new FieldName(modelConfig.getTargetColumnName()));
target.setField(new FieldName(modelConfig.getTargetColumnName()));
target.setField(new FieldName(modelConfig.getTargetColumnName()));
/** * Create the apply expression for final output, the function is "round" * * @return Apply */ protected Expression createNormExpr() { NormContinuous normContinuous = new NormContinuous(); normContinuous.withField(new FieldName(RAW_RESULT)); normContinuous.withLinearNorms(new LinearNorm().withOrig(0).withNorm(0)); normContinuous.withLinearNorms(new LinearNorm().withOrig(1).withNorm(1000)); return normContinuous; }
protected Expression createNormExpr(int id) { NormContinuous normContinuous = new NormContinuous(); normContinuous.withField(new FieldName(RAW_RESULT + "_" + id)); normContinuous.withLinearNorms(new LinearNorm().withOrig(0).withNorm(0)); normContinuous.withLinearNorms(new LinearNorm().withOrig(1).withNorm(1000)); return normContinuous; } }
List<String> outputFields = getSchemaFieldViaUsageType(schema, FieldUsageType.TARGET); pmmlModel.withTargetFieldName(new FieldName(outputFields.get(0))); table.withTargetCategory(outputFields.get(0));
@Test public void measure(){ DataField left = new DataField(null, null, null); DataField right = new DataField(FieldName.create("x"), OpType.CONTINUOUS, DataType.DOUBLE); assertEquals(getSize(left), getSize(right)); right.setName(new FieldName("x")); assertNotEquals(getSize(left), getSize(right)); }
@Test public void readResolve() throws Exception { FieldName name = FieldName.create("x"); assertTrue(name.isInterned()); FieldName clonedName = SerializationUtil.clone(name); assertTrue(clonedName.isInterned()); assertSame(name, clonedName); name = new FieldName("x"); assertFalse(name.isInterned()); clonedName = SerializationUtil.clone(name); assertTrue(clonedName.isInterned()); assertNotSame(name, clonedName); } }