org.dmg.pmml.NormDiscrete Java Examples
The following examples show how to use
org.dmg.pmml.NormDiscrete.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExpressionUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
static public FieldValue evaluateNormDiscrete(NormDiscrete normDiscrete, EvaluationContext context){ FieldValue value = context.evaluate(ensureField(normDiscrete)); if(FieldValueUtil.isMissing(value)){ return FieldValueUtil.create(TypeInfos.CATEGORICAL_DOUBLE, normDiscrete.getMapMissingTo()); } NormDiscrete.Method method = normDiscrete.getMethod(); switch(method){ case INDICATOR: { boolean equals = value.equals(normDiscrete); return (equals ? FieldValues.CATEGORICAL_DOUBLE_ONE : FieldValues.CATEGORICAL_DOUBLE_ZERO); } default: throw new UnsupportedAttributeException(normDiscrete, method); } }
Example #2
Source File: ValueParser.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction visit(NormDiscrete normDiscrete){ FieldName name = normDiscrete.getField(); if(name == null){ throw new MissingAttributeException(normDiscrete, PMMLAttributes.NORMDISCRETE_FIELD); } parseValue(name, normDiscrete); return super.visit(normDiscrete); }
Example #3
Source File: UnsupportedMarkupInspector.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction visit(NormDiscrete normDiscrete){ NormDiscrete.Method method = normDiscrete.getMethod(); switch(method){ case THERMOMETER: report(new UnsupportedAttributeException(normDiscrete, method)); break; default: break; } return super.visit(normDiscrete); }
Example #4
Source File: FieldReferenceFinder.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public VisitorAction visit(NormDiscrete normDiscrete){ process(normDiscrete.getField()); return super.visit(normDiscrete); }
Example #5
Source File: ExpressionUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static FieldValue evaluateExpression(Expression expression, EvaluationContext context){ if(expression instanceof Constant){ return evaluateConstant((Constant)expression); } else if(expression instanceof FieldRef){ return evaluateFieldRef((FieldRef)expression, context); } else if(expression instanceof NormContinuous){ return evaluateNormContinuous((NormContinuous)expression, context); } else if(expression instanceof NormDiscrete){ return evaluateNormDiscrete((NormDiscrete)expression, context); } else if(expression instanceof Discretize){ return evaluateDiscretize((Discretize)expression, context); } else if(expression instanceof MapValues){ return evaluateMapValues((MapValues)expression, context); } else if(expression instanceof TextIndex){ return evaluateTextIndex((TextIndex)expression, context); } else if(expression instanceof Apply){ return evaluateApply((Apply)expression, context); } else if(expression instanceof Aggregate){ return evaluateAggregate((Aggregate)expression, context); } // End if if(expression instanceof JavaExpression){ return evaluateJavaExpression((JavaExpression)expression, context); } throw new UnsupportedElementException(expression); }
Example #6
Source File: ExpressionUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Test public void evaluateNormDiscrete(){ FieldName name = FieldName.create("x"); Double equals = 1d; Double notEquals = 0d; NormDiscrete stringThree = new NormDiscrete(name, "3"); assertEquals(equals, evaluate(stringThree, name, "3")); assertEquals(notEquals, evaluate(stringThree, name, "1")); stringThree.setMapMissingTo(5d); assertEquals(5d, evaluate(stringThree, name, null)); NormDiscrete integerThree = new NormDiscrete(name, "3"); assertEquals(equals, evaluate(integerThree, name, 3)); assertEquals(notEquals, evaluate(integerThree, name, 1)); NormDiscrete floatThree = new NormDiscrete(name, "3.0"); assertEquals(equals, evaluate(floatThree, name, 3f)); assertEquals(notEquals, evaluate(floatThree, name, 1f)); }
Example #7
Source File: ValueParserTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 2 votes |
@Test public void parseTreeModel(){ DataField dataField = new DataField(FieldName.create("x1"), OpType.CATEGORICAL, DataType.STRING); DataDictionary dataDictionary = new DataDictionary() .addDataFields(dataField); NormDiscrete normDiscrete = new NormDiscrete(dataField.getName(), "1"); DerivedField derivedField = new DerivedField(FieldName.create("global(" + dataField.getName() + ")"), OpType.CATEGORICAL, DataType.STRING, normDiscrete); TransformationDictionary transformationDictionary = new TransformationDictionary() .addDerivedFields(derivedField); SimplePredicate simplePredicate = new SimplePredicate(derivedField.getName(), SimplePredicate.Operator.EQUAL, "1"); Node child = new LeafNode("1", simplePredicate); SimpleSetPredicate simpleSetPredicate = new SimpleSetPredicate(dataField.getName(), SimpleSetPredicate.BooleanOperator.IS_IN, new Array(Array.Type.STRING, "0 1")); Node root = new BranchNode("0", simpleSetPredicate) .addNodes(child); MiningField miningField = new MiningField(dataField.getName()); MiningSchema miningSchema = new MiningSchema() .addMiningFields(miningField); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, miningSchema, null) .setNode(root); PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), dataDictionary) .setTransformationDictionary(transformationDictionary) .addModels(treeModel); List<DataField> dataFields = dataDictionary.getDataFields(); ValueParser parser = new ValueParser(ValueParser.Mode.STRICT); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals("1", normDiscrete.getValue()); assertEquals("1", simplePredicate.getValue()); Array array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of("0", "1"), array.getValue()); dataField.setDataType(DataType.INTEGER); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(1, normDiscrete.getValue()); assertEquals("1", simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertTrue(array instanceof RichComplexArray); assertEquals(ImmutableSet.of(0, 1), array.getValue()); dataField.setDataType(DataType.DOUBLE); derivedField.setDataType(DataType.INTEGER); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(1.0d, normDiscrete.getValue()); assertEquals(1, simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of(0.0d, 1.0d), array.getValue()); dataField.setDataType(DataType.BOOLEAN); derivedField.setDataType(DataType.DOUBLE); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(true, normDiscrete.getValue()); assertEquals(1.0d, simplePredicate.getValue()); array = simpleSetPredicate.getArray(); assertEquals(ImmutableSet.of(false, true), array.getValue()); derivedField.setDataType(DataType.BOOLEAN); parser.applyTo(pmml); dataField = dataFields.get(0); assertEquals(true, normDiscrete.getValue()); assertEquals(true, simplePredicate.getValue()); }