Class BallNode

java.lang.Object
weka.core.neighboursearch.balltrees.BallNode
All Implemented Interfaces:
Serializable, RevisionHandler

public class BallNode extends Object implements Serializable, RevisionHandler
Class representing a node of a BallTree.
Version:
$Revision: 8034 $
Author:
Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    The end index of the portion of the master index array, which stores indices of the instances/points the node contains.
    The left child of the node.
    int
    The node number/id.
    int
    The number of instances/points in the node.
    The right child of the node.
    int
    The attribute that splits this node (not always used).
    double
    The value of m_SpiltAttrib that splits this node (not always used).
    int
    The start index of the portion of the master index array, which stores the indices of the instances/points the node contains.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BallNode(int nodeNumber)
    Constructor.
    BallNode(int start, int end, int nodeNumber)
    Creates a new instance of BallNode.
    BallNode(int start, int end, int nodeNumber, Instance pivot, double radius)
    Creates a new instance of BallNode.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Instance
    calcCentroidPivot(int[] instList, Instances insts)
    Calculates the centroid pivot of a node.
    static Instance
    calcCentroidPivot(int start, int end, int[] instList, Instances insts)
    Calculates the centroid pivot of a node.
    static Instance
    calcPivot(BallNode child1, BallNode child2, Instances insts)
    Calculates the centroid pivot of a node based on its two child nodes (if merging two nodes).
    static double
    calcRadius(int[] instList, Instances insts, Instance pivot, DistanceFunction distanceFunction)
    Calculates the radius of node.
    static double
    calcRadius(int start, int end, int[] instList, Instances insts, Instance pivot, DistanceFunction distanceFunction)
    Calculates the radius of a node.
    static double
    calcRadius(BallNode child1, BallNode child2, Instance pivot, DistanceFunction distanceFunction)
    Calculates the radius of a node based on its two child nodes (if merging two nodes).
    Returns the pivot/centre of the node's ball.
    double
    Returns the radius of the node's ball.
    Returns the revision string.
    boolean
    Returns true if the node is a leaf node (if both its left and right child are null).
    int
    Returns the number of instances in the hyper-spherical region of this node.
    void
    Sets the pivot/centre of this nodes ball.
    void
    setRadius(double radius)
    Sets the radius of the node's ball.
    void
    setStartEndIndices(int start, int end)
    Sets the the start and end index of the portion of the master index array that is assigned to this node.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • m_Start

      public int m_Start
      The start index of the portion of the master index array, which stores the indices of the instances/points the node contains.
    • m_End

      public int m_End
      The end index of the portion of the master index array, which stores indices of the instances/points the node contains.
    • m_NumInstances

      public int m_NumInstances
      The number of instances/points in the node.
    • m_NodeNumber

      public int m_NodeNumber
      The node number/id.
    • m_SplitAttrib

      public int m_SplitAttrib
      The attribute that splits this node (not always used).
    • m_SplitVal

      public double m_SplitVal
      The value of m_SpiltAttrib that splits this node (not always used).
    • m_Left

      public BallNode m_Left
      The left child of the node.
    • m_Right

      public BallNode m_Right
      The right child of the node.
  • Constructor Details

    • BallNode

      public BallNode(int nodeNumber)
      Constructor.
      Parameters:
      nodeNumber - The node's number/id.
    • BallNode

      public BallNode(int start, int end, int nodeNumber)
      Creates a new instance of BallNode.
      Parameters:
      start - The begining index of the portion of the master index array belonging to this node.
      end - The end index of the portion of the master index array belonging to this node.
      nodeNumber - The node's number/id.
    • BallNode

      public BallNode(int start, int end, int nodeNumber, Instance pivot, double radius)
      Creates a new instance of BallNode.
      Parameters:
      start - The begining index of the portion of the master index array belonging to this node.
      end - The end index of the portion of the master index array belonging to this node.
      nodeNumber - The node's number/id.
      pivot - The pivot/centre of the node's ball.
      radius - The radius of the node's ball.
  • Method Details

    • isALeaf

      public boolean isALeaf()
      Returns true if the node is a leaf node (if both its left and right child are null).
      Returns:
      true if the node is a leaf node.
    • setStartEndIndices

      public void setStartEndIndices(int start, int end)
      Sets the the start and end index of the portion of the master index array that is assigned to this node.
      Parameters:
      start - The start index of the master index array.
      end - The end index of the master indext array.
    • setPivot

      public void setPivot(Instance pivot)
      Sets the pivot/centre of this nodes ball.
      Parameters:
      pivot - The centre/pivot.
    • getPivot

      public Instance getPivot()
      Returns the pivot/centre of the node's ball.
      Returns:
      The ball pivot/centre.
    • setRadius

      public void setRadius(double radius)
      Sets the radius of the node's ball.
      Parameters:
      radius - The radius of the nodes ball.
    • getRadius

      public double getRadius()
      Returns the radius of the node's ball.
      Returns:
      Radius of node's ball.
    • numInstances

      public int numInstances()
      Returns the number of instances in the hyper-spherical region of this node.
      Returns:
      The number of instances in the node.
    • calcCentroidPivot

      public static Instance calcCentroidPivot(int[] instList, Instances insts)
      Calculates the centroid pivot of a node. The node is given in the form of an indices array that contains the indices of the points inside the node.
      Parameters:
      instList - The indices array pointing to the instances in the node.
      insts - The actual instances. The instList points to instances in this object.
      Returns:
      The calculated centre/pivot of the node.
    • calcCentroidPivot

      public static Instance calcCentroidPivot(int start, int end, int[] instList, Instances insts)
      Calculates the centroid pivot of a node. The node is given in the form of the portion of an indices array that contains the indices of the points inside the node.
      Parameters:
      start - The start index marking the start of the portion belonging to the node.
      end - The end index marking the end of the portion in the indices array that belongs to the node.
      instList - The indices array pointing to the instances in the node.
      insts - The actual instances. The instList points to instances in this object.
      Returns:
      The calculated centre/pivot of the node.
    • calcRadius

      public static double calcRadius(int[] instList, Instances insts, Instance pivot, DistanceFunction distanceFunction) throws Exception
      Calculates the radius of node.
      Parameters:
      instList - The indices array containing the indices of the instances inside the node.
      insts - The actual instances object. instList points to instances in this object.
      pivot - The centre/pivot of the node.
      distanceFunction - The distance fuction to use to calculate the radius.
      Returns:
      The radius of the node.
      Throws:
      Exception - If there is some problem in calculating the radius.
    • calcRadius

      public static double calcRadius(int start, int end, int[] instList, Instances insts, Instance pivot, DistanceFunction distanceFunction) throws Exception
      Calculates the radius of a node.
      Parameters:
      start - The start index of the portion in indices array that belongs to the node.
      end - The end index of the portion in indices array that belongs to the node.
      instList - The indices array holding indices of instances.
      insts - The actual instances. instList points to instances in this object.
      pivot - The centre/pivot of the node.
      distanceFunction - The distance function to use to calculate the radius.
      Returns:
      The radius of the node.
      Throws:
      Exception - If there is some problem calculating the radius.
    • calcPivot

      public static Instance calcPivot(BallNode child1, BallNode child2, Instances insts) throws Exception
      Calculates the centroid pivot of a node based on its two child nodes (if merging two nodes).
      Parameters:
      child1 - The first child of the node.
      child2 - The second child of the node.
      insts - The set of instances on which the tree is (or is to be) built.
      Returns:
      The centre/pivot of the node.
      Throws:
      Exception - If there is some problem calculating the pivot.
    • calcRadius

      public static double calcRadius(BallNode child1, BallNode child2, Instance pivot, DistanceFunction distanceFunction) throws Exception
      Calculates the radius of a node based on its two child nodes (if merging two nodes).
      Parameters:
      child1 - The first child of the node.
      child2 - The second child of the node.
      pivot - The centre/pivot of the node.
      distanceFunction - The distance function to use to calculate the radius
      Returns:
      The radius of the node.
      Throws:
      Exception - If there is some problem in calculating the radius.
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Returns:
      the revision