Search in sources :

Example 11 with PMMLSimpleSetPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.

the class ConditionExporter method setValuesFromPMMLSimpleSetPredicate.

private void setValuesFromPMMLSimpleSetPredicate(final SimpleSetPredicate to, final PMMLSimpleSetPredicate from) {
    to.setField(m_derivedFieldMapper.getDerivedFieldName(from.getSplitAttribute()));
    final Enum operator;
    final PMMLSetOperator setOp = from.getSetOperator();
    switch(setOp) {
        case IS_IN:
            operator = SimpleSetPredicate.BooleanOperator.IS_IN;
            break;
        case IS_NOT_IN:
            operator = SimpleSetPredicate.BooleanOperator.IS_NOT_IN;
            break;
        default:
            throw new IllegalStateException("Unknown set operator \"" + setOp + "\".");
    }
    to.setBooleanOperator(operator);
    final Set<String> values = from.getValues();
    ArrayType array = to.addNewArray();
    array.setN(BigInteger.valueOf(values.size()));
    org.w3c.dom.Node arrayNode = array.getDomNode();
    arrayNode.appendChild(arrayNode.getOwnerDocument().createTextNode(setToWhitspaceSeparatedString(values)));
    final org.dmg.pmml.ArrayType.Type.Enum type;
    final PMMLArrayType arrayType = from.getArrayType();
    switch(arrayType) {
        case INT:
            type = ArrayType.Type.INT;
            break;
        case REAL:
            type = ArrayType.Type.REAL;
            break;
        case STRING:
            type = ArrayType.Type.STRING;
            break;
        default:
            throw new IllegalStateException("Unknown array type \"" + arrayType + "\".");
    }
    array.setType(type);
}
Also used : Enum(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) ArrayType(org.dmg.pmml.ArrayType) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) ArrayType(org.dmg.pmml.ArrayType) PMMLArrayType(org.knime.base.node.mine.decisiontree2.PMMLArrayType) PMMLSetOperator(org.knime.base.node.mine.decisiontree2.PMMLSetOperator)

Example 12 with PMMLSimpleSetPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.

the class TreeNodeNominalBinaryCondition method toPMMLPredicate.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate toPMMLPredicate() {
    final PMMLSimpleSetPredicate setPredicate = new PMMLSimpleSetPredicate(getAttributeName(), m_setLogic.getPmmlSetOperator());
    setPredicate.setValues(Arrays.asList(getValues()));
    setPredicate.setArrayType(PMMLArrayType.STRING);
    if (!acceptsMissings()) {
        // if condition rejects missing values return the set predicate
        return setPredicate;
    }
    // otherwise create compound condition that allows missing values
    final PMMLCompoundPredicate compPredicate = new PMMLCompoundPredicate(PMMLBooleanOperator.OR);
    final PMMLSimplePredicate missing = new PMMLSimplePredicate();
    missing.setSplitAttribute(getAttributeName());
    missing.setOperator(PMMLOperator.IS_MISSING);
    compPredicate.addPredicate(setPredicate);
    compPredicate.addPredicate(missing);
    return compPredicate;
}
Also used : PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)

Example 13 with PMMLSimpleSetPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.

the class PMMLExpressionFactory method in.

/**
 * {@inheritDoc}
 */
@Override
public PMMLPredicate in(final Expression left, final Expression right) {
    PMMLSimpleSetPredicate setIn = new PMMLSimpleSetPredicate(expressionToString(left), PMMLSetOperator.IS_IN);
    if (left.getTreeType() == ASTType.ColRef) {
        m_usedColumns.add(expressionToString(left));
    } else {
        throw new UnsupportedOperationException("PMML 4.1 supports only columns before IN.");
    }
    if (!right.isConstant()) {
        throw new UnsupportedOperationException("PMML 4.1 supports only constants in arguments.");
    }
    List<Expression> children = right.getChildren();
    List<String> values = new ArrayList<String>(children.size());
    List<DataType> types = new ArrayList<DataType>(children.size());
    for (Expression child : children) {
        values.add(expressionToString(child));
        types.add(child.getOutputType());
    }
    DataType outputType = RuleEngineNodeModel.computeOutputType(types, false);
    if (outputType.isCompatible(IntValue.class)) {
        setIn.setArrayType(PMMLArrayType.INT);
    } else if (outputType.isCompatible(DoubleValue.class)) {
        setIn.setArrayType(PMMLArrayType.REAL);
    } else {
        setIn.setArrayType(PMMLArrayType.STRING);
    }
    setIn.setValues(values);
    return setIn;
}
Also used : PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) Expression(org.knime.base.node.rules.engine.Expression) DoubleValue(org.knime.core.data.DoubleValue) ArrayList(java.util.ArrayList) DataType(org.knime.core.data.DataType)

Example 14 with PMMLSimpleSetPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.

the class PMMLRuleTranslator method setPredicate.

/**
 * As the predicates can be of different subclasses of {@link PMMLPredicate}, creating them adding their properties
 * to the {@code simpleRule} is done with this method.
 *
 * @param simpleRule An xml {@link SimpleRule} (recently created).
 * @param predicate A {@link PMMLPredicate} with preferably from the Rule versions of
 *            {@link PMMLRuleSimplePredicate} and {@link PMMLRuleCompoundPredicate}.
 * @since 2.12
 */
public void setPredicate(final SimpleRule simpleRule, final PMMLPredicate predicate) {
    if (predicate instanceof PMMLFalsePredicate) {
        simpleRule.addNewFalse();
    } else if (predicate instanceof PMMLTruePredicate) {
        simpleRule.addNewTrue();
    } else if (predicate instanceof PMMLSimplePredicate) {
        PMMLSimplePredicate simple = (PMMLSimplePredicate) predicate;
        SimplePredicate pred = simpleRule.addNewSimplePredicate();
        pred.setField(simple.getSplitAttribute());
        setOperator(pred, simple);
        if (simple.getThreshold() != null) {
            pred.setValue(simple.getThreshold());
        }
    } else if (predicate instanceof PMMLCompoundPredicate) {
        PMMLCompoundPredicate comp = (PMMLCompoundPredicate) predicate;
        CompoundPredicate p = simpleRule.addNewCompoundPredicate();
        setCompound(p, comp);
    } else if (predicate instanceof PMMLSimpleSetPredicate) {
        PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) predicate;
        SimpleSetPredicate s = simpleRule.addNewSimpleSetPredicate();
        setSetPredicate(s, set);
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Example 15 with PMMLSimpleSetPredicate

use of org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate in project knime-core by knime.

the class PMMLRuleTranslator method setPredicate.

/**
 * For an xml {@link CompoundPredicate} ({@code cp}) sets the parameters based on {@code pred}'s properties.
 *
 * @param cp An xml {@link CompoundPredicate}.
 * @param pred The {@link PMMLPredicate} with the rule version subclasses.
 */
private void setPredicate(final CompoundPredicate cp, final PMMLPredicate pred) {
    if (pred instanceof PMMLFalsePredicate) {
        cp.addNewFalse();
    } else if (pred instanceof PMMLTruePredicate) {
        cp.addNewTrue();
    } else if (pred instanceof PMMLSimplePredicate) {
        PMMLSimplePredicate simple = (PMMLSimplePredicate) pred;
        SimplePredicate s = cp.addNewSimplePredicate();
        s.setField(simple.getSplitAttribute());
        setOperator(s, simple);
        s.setValue(simple.getThreshold());
    } else if (pred instanceof PMMLCompoundPredicate) {
        PMMLCompoundPredicate compound = (PMMLCompoundPredicate) pred;
        CompoundPredicate c = cp.addNewCompoundPredicate();
        setCompound(c, compound);
    } else if (pred instanceof PMMLSimpleSetPredicate) {
        PMMLSimpleSetPredicate set = (PMMLSimpleSetPredicate) pred;
        SimpleSetPredicate ss = cp.addNewSimpleSetPredicate();
        setSetPredicate(ss, set);
    }
}
Also used : PMMLTruePredicate(org.knime.base.node.mine.decisiontree2.PMMLTruePredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) CompoundPredicate(org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate) PMMLFalsePredicate(org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate) PMMLSimplePredicate(org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate) SimplePredicate(org.dmg.pmml.SimplePredicateDocument.SimplePredicate) PMMLCompoundPredicate(org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate) PMMLSimpleSetPredicate(org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate) SimpleSetPredicate(org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)

Aggregations

PMMLSimpleSetPredicate (org.knime.base.node.mine.decisiontree2.PMMLSimpleSetPredicate)13 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)12 PMMLCompoundPredicate (org.knime.base.node.mine.decisiontree2.PMMLCompoundPredicate)9 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)9 PMMLFalsePredicate (org.knime.base.node.mine.decisiontree2.PMMLFalsePredicate)8 PMMLTruePredicate (org.knime.base.node.mine.decisiontree2.PMMLTruePredicate)8 CompoundPredicate (org.dmg.pmml.CompoundPredicateDocument.CompoundPredicate)5 ArrayList (java.util.ArrayList)4 SimplePredicate (org.dmg.pmml.SimplePredicateDocument.SimplePredicate)4 SimpleSetPredicate (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate)4 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)4 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)4 DataCell (org.knime.core.data.DataCell)4 ArrayType (org.dmg.pmml.ArrayType)3 DecisionTreeNodeLeaf (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf)3 LinkedHashSet (java.util.LinkedHashSet)2 Entry (java.util.Map.Entry)2 ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)2 Enum (org.dmg.pmml.SimpleSetPredicateDocument.SimpleSetPredicate.BooleanOperator.Enum)2 PMMLArrayType (org.knime.base.node.mine.decisiontree2.PMMLArrayType)2