private static void checkNode(Node node) { assertNotNull(node.getId()); List<ScoreDistribution> scoreDists = node.getScoreDistributions(); int numDists = scoreDists.size(); assertEquals(node.getRecordCount().doubleValue(), leftChild.getRecordCount() + rightChild.getRecordCount()); assertEquals(node.getId() + "+", rightChild.getId()); assertEquals(node.getId() + "-", leftChild.getId()); checkNode(rightChild); checkNode(leftChild);
@Override public VisitorAction visit(Node node){ Integer id = Integer.valueOf(node.getId()); Object value = values.get(id); if(value != null){ value = ScalarUtil.decode(value); addExtension((Node & HasExtensions)node, ValueUtil.formatValue(value)); } return super.visit(node); } };
@Override public void enterNode(Node node){ String id = node.getId(); Object score = node.getScore(); String defaultChild = node.getDefaultChild(); Node secondChild = children.get(1); if((defaultChild).equals(firstChild.getId())){ children = swapChildren(node); } else if((defaultChild).equals(secondChild.getId())){
@Override public void enterNode(Node node){ String id = node.getId(); Object score = node.getScore(); String defaultChild = node.getDefaultChild(); Node secondChild = children.get(1); if((defaultChild).equals(firstChild.getId())){ children = swapChildren(node); } else if((defaultChild).equals(secondChild.getId())){
@Override public void enterNode(Node node){ String id = node.getId(); Object score = node.getScore(); String defaultChild = node.getDefaultChild(); Node secondChild = children.get(1); if((defaultChild).equals(firstChild.getId())){ children = swapChildren(node); } else if((defaultChild).equals(secondChild.getId())){
@Override public VisitorAction visit(Node node){ Deque<PMMLObject> parents = getParents(); int depth = 0; Iterator<PMMLObject> it = parents.iterator(); while(true){ PMMLObject parent = it.next(); if(parent instanceof Node){ depth++; continue; } TreeModel treeModel = (TreeModel)parent; Segment segment = (Segment)it.next(); Double recordCount = node.getRecordCount(); if(recordCount == null){ recordCount = 0d; } printRow(segment.getId(), node.getId(), recordCount, depth); break; } return super.visit(node); }
private Trail handleDefaultChild(Trail trail, Node node, EvaluationContext context){ // "The defaultChild missing value strategy requires the presence of the defaultChild attribute in every non-leaf Node" String defaultChild = node.getDefaultChild(); if(defaultChild == null){ throw new MissingAttributeException(node, PMMLAttributes.NODE_DEFAULTCHILD); } trail.addMissingLevel(); List<Node> children = node.getNodes(); for(int i = 0, max = children.size(); i < max; i++){ Node child = children.get(i); String id = child.getId(); if(id != null && (id).equals(defaultChild)){ // The predicate of the referenced Node is not evaluated return handleTrue(trail, child, context); } } // "Only Nodes which are immediate children of the respective Node can be referenced" throw new InvalidAttributeException(node, PMMLAttributes.NODE_DEFAULTCHILD, defaultChild); }
@Override public VisitorAction visit(Node node){ if(node.getScore() != null){ double nodeDepth = 0d; Deque<PMMLObject> parents = getParents(); for(PMMLObject parent : parents){ if(!(parent instanceof Node)){ break; } nodeDepth++; } double nodeSample = this.nodeSamples[Integer.parseInt(node.getId())]; double averagePathLength = (corrected ? correctedAveragePathLength(nodeSample) : averagePathLength(nodeSample)); node.setScore(nodeDepth + averagePathLength); } return super.visit(node); } };
@Override public void enterNode(Node node){ String id = node.getId(); Object score = node.getScore();
@Override public void enterNode(Node node){ String id = node.getId(); Object score = node.getScore();
private void encodeNode(org.dmg.pmml.tree.Node parent, int index, Schema schema){ parent.setId(String.valueOf(index + 1)); Node node = allNodes.get(index); if(!node.isLeaf()){ int splitIndex = node.getFeatureIndex(); Feature feature = schema.getFeature(splitIndex); org.dmg.pmml.tree.Node leftChild = new org.dmg.pmml.tree.Node() .setPredicate(encodePredicate(feature, node, true)); encodeNode(leftChild, node.getLeftChild().getId(), schema); org.dmg.pmml.tree.Node rightChild = new org.dmg.pmml.tree.Node() .setPredicate(encodePredicate(feature, node, false)); encodeNode(rightChild, node.getRightChild().getId(), schema); parent.addNodes(leftChild, rightChild); boolean defaultLeft = false; parent.setDefaultChild(defaultLeft ? leftChild.getId() : rightChild.getId()); } else { float value = (float)node.getValue(); parent.setScore(ValueUtil.formatValue(value)); } }
@Override public void enterNode(Node node){ String id = node.getId(); String score = node.getScore();
static public ComplexNode toComplexNode(Node node){ ComplexNode result = new ComplexNode() .setId(node.getId()) .setScore(node.getScore()) .setRecordCount(node.getRecordCount()) .setDefaultChild(node.getDefaultChild()) .setPredicate(node.getPredicate()); if(node.hasNodes()){ (result.getNodes()).addAll(node.getNodes()); } // End if if(node.hasScoreDistributions()){ (result.getScoreDistributions()).addAll(node.getScoreDistributions()); } return result; } }
value.setId(node.getId()); value.setScore(node.getScore()); value.setRecordCount(node.getRecordCount());
value.setId(node.getId()); value.setScore(node.getScore()); value.setRecordCount(node.getRecordCount());