/// <summary> /// Attaches a new leaf node to the supplied node, along /// the specified arc. /// </summary> public DecisionTreeNode addLeafNode(DecisionTreeNode parent, int arcNum, String label, AttributeMask mask, int numTrainingExamplesReachHere, int bestTrainingTargetIndex, int numTrainingEgsCorrectClassUsingBestTrainingIndex, int numTestingEgsCorrectClassUsingBestTrainingIndex, int numTestingExamplesReachHere, int bestTestingTargetIndex, int numTestingEgsCorrectClassUsingBestTestingIndex, int numTrainingEgsCorrectClassUsingBestTestingIndex) { // Create new leaf node. DecisionTreeNode leaf = new DecisionTreeNode(parent, label, null, mask); // Set the node statistics. leaf.setTrainingStats(numTrainingExamplesReachHere, bestTrainingTargetIndex, numTrainingEgsCorrectClassUsingBestTrainingIndex, numTestingEgsCorrectClassUsingBestTrainingIndex); leaf.setTestingStats(numTestingExamplesReachHere, bestTestingTargetIndex, numTestingEgsCorrectClassUsingBestTestingIndex, numTrainingEgsCorrectClassUsingBestTestingIndex); // Update the tree statistics. TrainingCorrect += numTrainingEgsCorrectClassUsingBestTrainingIndex; TestingCorrect += numTestingEgsCorrectClassUsingBestTrainingIndex; // Now, attach the new leaf to the supplied node. if (parent != null) { parent.setChild(arcNum, leaf); } // Add a reference to the new node to the node list. Nodes.Add(leaf); // Determine if the tree is complete. if (findIncompleteNode((DecisionTreeNode)Nodes[0], new int[1]) == null) { Complete = true; } return(leaf); }
/// <summary> /// Attaches a new internal node to the supplied node, /// along the specified arc. /// </summary> /// <param name="parent">The node in the current tree to attach /// the internal node to. If the node is null, the /// new internal node becomes the root of the tree.</param> /// <param name="arcNum">The arc number (or attribute value /// index) along which to attach the new node.</param> /// <param name="attributePosition">The position of the /// attribute used to split at the new node, relative /// to the other attributes in the dataset.</param> /// <param name="att">The attribute used to split at the new /// node.</param> /// <returns>A reference to the new internal node.</returns> public DecisionTreeNode addInternalNode(DecisionTreeNode parent, int arcNum, int attributePosition, Attribute att, AttributeMask mask, int numTrainingExamplesReachHere, int bestTrainingTargetIndex, int numTrainingEgsCorrectClassUsingBestTrainingIndex, int numTestingEgsCorrectClassUsingBestTrainingIndex, int numTestingExamplesReachHere, int bestTestingTargetIndex, int numTestingEgsCorrectClassUsingBestTestingIndex, int numTrainingEgsCorrectClassUsingBestTestingIndex) { // Create a new internal node. DecisionTreeNode internalNode = new DecisionTreeNode(parent, att.getName(), att.getValueNames(), mask); // Set the node statistics. internalNode.setTrainingStats(numTrainingExamplesReachHere, bestTrainingTargetIndex, numTrainingEgsCorrectClassUsingBestTrainingIndex, numTestingEgsCorrectClassUsingBestTrainingIndex); internalNode.setTestingStats(numTestingExamplesReachHere, bestTestingTargetIndex, numTestingEgsCorrectClassUsingBestTestingIndex, numTrainingEgsCorrectClassUsingBestTestingIndex); // Update the tree statistics. InternalNodes++; // Now, attach the new internal node to the supplied node. if (parent != null) { parent.setChild(arcNum, internalNode); } // Add a reference to the new node to the node list. Nodes.Add(internalNode); return(internalNode); }
/// <summary> /// Attaches a new internal node to the supplied node, /// along the specified arc. /// </summary> /// <param name="parent">The node in the current tree to attach /// the internal node to. If the node is null, the /// new internal node becomes the root of the tree.</param> /// <param name="arcNum">The arc number (or attribute value /// index) along which to attach the new node.</param> /// <param name="attributePosition">The position of the /// attribute used to split at the new node, relative /// to the other attributes in the dataset.</param> /// <param name="att">The attribute used to split at the new /// node.</param> /// <returns>A reference to the new internal node.</returns> public DecisionTreeNode addInternalNode(DecisionTreeNode parent, int arcNum, int attributePosition, Attribute att, AttributeMask mask, int numTrainingExamplesReachHere, int bestTrainingTargetIndex, int numTrainingEgsCorrectClassUsingBestTrainingIndex, int numTestingEgsCorrectClassUsingBestTrainingIndex, int numTestingExamplesReachHere, int bestTestingTargetIndex, int numTestingEgsCorrectClassUsingBestTestingIndex, int numTrainingEgsCorrectClassUsingBestTestingIndex) { // Create a new internal node. DecisionTreeNode internalNode = new DecisionTreeNode(parent, att.getName(), att.getValueNames(), mask); // Set the node statistics. internalNode.setTrainingStats(numTrainingExamplesReachHere, bestTrainingTargetIndex, numTrainingEgsCorrectClassUsingBestTrainingIndex, numTestingEgsCorrectClassUsingBestTrainingIndex); internalNode.setTestingStats(numTestingExamplesReachHere, bestTestingTargetIndex, numTestingEgsCorrectClassUsingBestTestingIndex, numTrainingEgsCorrectClassUsingBestTestingIndex); // Update the tree statistics. InternalNodes++; // Now, attach the new internal node to the supplied node. if (parent != null) parent.setChild(arcNum, internalNode); // Add a reference to the new node to the node list. Nodes.Add(internalNode); return internalNode; }
/// <summary> /// Attaches a new leaf node to the supplied node, along /// the specified arc. /// </summary> public DecisionTreeNode addLeafNode(DecisionTreeNode parent, int arcNum, String label, AttributeMask mask, int numTrainingExamplesReachHere, int bestTrainingTargetIndex, int numTrainingEgsCorrectClassUsingBestTrainingIndex, int numTestingEgsCorrectClassUsingBestTrainingIndex, int numTestingExamplesReachHere, int bestTestingTargetIndex, int numTestingEgsCorrectClassUsingBestTestingIndex, int numTrainingEgsCorrectClassUsingBestTestingIndex) { // Create new leaf node. DecisionTreeNode leaf = new DecisionTreeNode(parent, label, null, mask); // Set the node statistics. leaf.setTrainingStats(numTrainingExamplesReachHere, bestTrainingTargetIndex, numTrainingEgsCorrectClassUsingBestTrainingIndex, numTestingEgsCorrectClassUsingBestTrainingIndex); leaf.setTestingStats(numTestingExamplesReachHere, bestTestingTargetIndex, numTestingEgsCorrectClassUsingBestTestingIndex, numTrainingEgsCorrectClassUsingBestTestingIndex); // Update the tree statistics. TrainingCorrect += numTrainingEgsCorrectClassUsingBestTrainingIndex; TestingCorrect += numTestingEgsCorrectClassUsingBestTrainingIndex; // Now, attach the new leaf to the supplied node. if (parent != null) parent.setChild(arcNum, leaf); // Add a reference to the new node to the node list. Nodes.Add(leaf); // Determine if the tree is complete. if (findIncompleteNode((DecisionTreeNode)Nodes[0], new int[1]) == null) { Complete = true; } return leaf; }