⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decisiontreenode.java

📁 一个决策树的Applet(转载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   *
   * @param child The 'potential' child of this node.
   *
   * @return The position of the supplied child beneath
   *         this node, or -1 if this is a leaf node
   *         or the node is not a parent of the
   *         child.
   */
  public int getChildPosition( DecisionTreeNode child )
  {
    if( this.isLeaf() ) return -1;

    for( int i = 0; i < m_children.length; i++ )
      if( m_children[i] == child ) return i;

    return -1;
  }

  /**
   * Returns the parent of this node.
   *
   * @return The parent node of this node, or null
   *         if this node has no parent (i.e. is the root
   *         node).
   */
  public DecisionTreeNode getParent()
  {
    return m_parent;
  }

  /**
   * Attaches the supplied node at specified child position.
   * The method does not check to see if a node already
   * exists at the insertion position.
   * If this node is a leaf node, the method has no effect.
   *
   * @throws IndexOutOfBoundsException If the supplied
   *         child number is less than 0 or greater
   *         than the number of possible children (which
   *         is equivalent to the number of attribute
   *         values) at this node.
   */
  public void setChild( int childNum, DecisionTreeNode node )
  {
    if( isLeaf() ) return;

    if( childNum < 0 || childNum > (m_children.length - 1) )
      throw new
        ArrayIndexOutOfBoundsException( "Cannot add " +
          "child at position " + childNum + "." );

    m_children[ childNum ] = node;
  }

  /**
   * Searches through the current node's list of children
   * and attempts to locate a child that matches the
   * supplied child.  If a match is found, the reference
   * to the child is removed, leaving a vacant arc.
   */
  public void removeChild( DecisionTreeNode child )
  {
    // Search through the list of children, looking for a match.
    for( int i = 0; i < m_children.length; i++ ) {
      if( m_children[i] == child ) {
        m_children[i] = null;
        return;
      }
    }
  }

  /**
   * A utility method that detaches this node from
   * its parent node.  Once this method is called,
   * the node will no longer be attached to the tree.
   */
  public void detach()
  {
    if( m_parent != null ) m_parent.removeChild( this );
  }

  /**
   * Sets the internal training statistics for the node.
   *
   * @param numTrainingExamplesReachHere The number of training
   *        examples that reach this node.
   *
   * @param bestTrainingTargetIndex The index for the best
   *        (most common) target attribute value in the
   *        training set.
   *
   * @param numTrainingExamplesCorrectClass The number of training
   *        examples that <i>would be</i> correctly
   *        classified, if this node was a leaf node
   *        (with the most common training target attribute value
   *         in the available examples).
   *
   * @param numTestingExamplesCorrectClass The number of testing
   *        examples that <i>would be</i> correctly
   *        classified, if this node was a leaf node
   *        (with the most common training target attribute value
   *         in the available examples).
   */
  public void
    setTrainingStats( int numTrainingExamplesReachHere,
                      int bestTrainingTargetIndex,
                      int numTrainingExamplesCorrectClass,
                      int numTestingExamplesCorrectClass )
  {
    m_trainEgsReachHere = numTrainingExamplesReachHere;
    m_trainBestTargetIndex = bestTrainingTargetIndex;
    m_trainTrainingCorrectClass = numTrainingExamplesCorrectClass;
    m_trainTestingCorrectClass  = numTestingExamplesCorrectClass;
  }

  /**
   * Returns the number of training examples that reach
   * the node.
   *
   * @return The number of examples from the dataset
   *         that reach the node.
   */
  public int getTrainingEgsAtNode()
  {
    return m_trainEgsReachHere;
  }

  /**
   * Returns the number of training examples that would
   * be correctly classified at this node, if it was
   * a leaf node with the most common training target
   * attribute value.
   */
  public int getTrainingEgsCorrectClassUsingBestTrainingIndex()
  {
    return m_trainTrainingCorrectClass;
  }

  /**
   * Returns the number of testing examples that would
   * be correctly classified at this node, if it was
   * a leaf node with the most common training target
   * attribute value.
   */
  public int getTestingEgsCorrectClassUsingBestTrainingIndex()
  {
    return m_trainTestingCorrectClass;
  }

  /**
   * Sets the internal testing statistics for the node.
   *
   * @param numTestingExamplesReachHere The number of testing
   *        examples that reach this node.
   *
   * @param bestTestingTargetIndex The index for the best
   *        (most common) target attribute value in the
   *        testing set.
   *
   * @param numTestingExamplesCorrectClass The number of testing
   *        examples that <i>would be</i> correctly
   *        classified, if this node was a leaf node
   *        (with the most common testing target attribute value
   *         in the available examples).
   *
   * @param numTrainingExamplesCorrectClass The number of training
   *        examples that <i>would be</i> correctly
   *        classified, if this node was a leaf node
   *        (with the most common training target attribute value
   *         in the available examples).
   */
  public void
    setTestingStats( int numTestingExamplesReachHere,
                     int bestTestingTargetIndex,
                     int numTestingExamplesCorrectClass,
                     int numTrainingExamplesCorrectClass )
  {
    m_testEgsReachHere = numTestingExamplesReachHere;
    m_testBestTargetIndex = bestTestingTargetIndex;
    m_testTestingCorrectClass  = numTestingExamplesCorrectClass;
    m_testTrainingCorrectClass = numTrainingExamplesCorrectClass;
  }

  /**
   * Returns the number of testing examples that reach
   * the node.
   *
   * @return The number of examples from the dataset that reach the node.
   */
  public int getTestingEgsAtNode()
  {
    return m_testEgsReachHere;
  }

  /**
   * Returns the number of training examples that would
   * be correctly classified at this node, if it was
   * a leaf node with the most common testing target
   * attribute value.
   */
  public int getTrainingEgsCorrectClassUsingBestTestingIndex()
  {
    return m_testTrainingCorrectClass;
  }

  /**
   * Returns the number of testing examples that would
   * be correctly classified at this node, if it was
   * a leaf node with the most common testing target
   * attribute value.
   */
  public int getTestingEgsCorrectClassUsingBestTestingIndex()
  {
    return m_testTestingCorrectClass;
  }

  /**
   * Returns the best (most common) testing set
   * target attribute value index.
   */
  public int getTestingBestTarget()
  {
    return m_testBestTargetIndex;
  }

  /**
   * Returns the best (most common) training set
   * target attribute value index.
   */
  public int getTrainingBestTarget()
  {
    return m_trainBestTargetIndex;
  }

  /**
   * Returns the current node flag value or a number less
   * than zero if the node is unflagged. The number '-1'
   * is reserved as a special flag value.
   *
   * @return The current node flag value, or a number < 0
   *         if the node is unflagged.
   */
  public int getFlag()
  {
    return m_nodeFlag;
  }

  /**
   * Flags or unflags the node.  Usually, an algorithm
   * will set the flag to indicate that the node is
   * currently being considered, modified, or used in
   * some other way.
   *
   * @param flagValue The integer value to set the flag to.
   *        If the number is less than zero, the node is
   *        considered unflagged.
   */
  public void setFlag( int flagValue )
  {
    m_nodeFlag = flagValue;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -