Package weka.core.neighboursearch.balltrees

# Class MiddleOutConstructor

java.lang.Object
weka.core.neighboursearch.balltrees.BallTreeConstructor
weka.core.neighboursearch.balltrees.MiddleOutConstructor

All Implemented Interfaces:
  `Serializable`, `OptionHandler`, `Randomizable`, `RevisionHandler`, `TechnicalInformationHandler`

public class MiddleOutConstructor extends BallTreeConstructor implements Randomizable, TechnicalInformationHandler
The class that builds a BallTree middle out.
For more information see also:
Andrew W. Moore: The Anchors Hierarchy: Using the Triangle Inequality to Survive High Dimensional Data. In: UAI '00: Proceedings of the 16th Conference on Uncertainty in Artificial Intelligence, San Francisco, CA, USA, 397-405, 2000.
Ashraf Masood Kibriya (2007). Fast Algorithms for Nearest Neighbour Search. Hamilton, New Zealand.

BibTeX:

     @inproceedings{Moore2000,
        address = {San Francisco, CA, USA},
        author = {Andrew W. Moore},
        booktitle = {UAI '00: Proceedings of the 16th Conference on Uncertainty in Artificial Intelligence},
        pages = {397-405},
        publisher = {Morgan Kaufmann Publishers Inc.},
        title = {The Anchors Hierarchy: Using the Triangle Inequality to Survive High Dimensional Data},
        year = {2000}
     }

     @mastersthesis{Kibriya2007,
        address = {Hamilton, New Zealand},
        author = {Ashraf Masood Kibriya},
        school = {Department of Computer Science, School of Computing and Mathematical Sciences, University of Waikato},
        title = {Fast Algorithms for Nearest Neighbour Search},
        year = {2007}
     }

Valid options are:

     -S <num>
      The seed for the random number generator used
      in selecting random anchor.
     (default: 1)

     -R
      Use randomly chosen initial anchors.

Version:
  $Revision: 11269 $
Author:
  Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MiddleOutConstructor()`
  Creates a new instance of MiddleOutConstructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int[]`
  `addInstance(BallNode node, Instance inst)`
  Adds an instance to the tree.
  `BallNode`
  `buildTree()`
  Builds a ball tree middle out.
  `Instance`
  `calcPivot(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list2, Instances insts)`
  Calculates the centroid pivot of a node based on the list of points that it contains (tbe two lists of its children are provided).
  `Instance`
  `calcPivot(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node2, Instances insts)`
  /** Calculates the centroid pivot of a node based on its two child nodes (if merging two nodes).
  `double`
  `calcRadius(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list2, Instance pivot, Instances insts)`
  Calculates the radius of a node based on the list of points that it contains (the two lists of its children are provided).
  `double`
  `calcRadius(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode n1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode n2)`
  Calculates the radius of a node based on its two child nodes (if merging two nodes).
  `void`
  `checkIndicesList(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list, int startidx, int endidx)`
  Checks whether if the points in an index list are in some specified of the master index array.
  `String[]`
  `getOptions()`
  Gets the current settings of this BallTree MiddleOutConstructor.
  `String`
  `getRevision()`
  Returns the revision string.
  `int`
  `getSeed()`
  Returns the seed for random number generator.
  `TechnicalInformation`
  `getTechnicalInformation()`
  Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
  `String`
  `globalInfo()`
  Returns a string describing this nearest neighbour search algorithm.
  `String`
  `initialAnchorRandomTipText()`
  Returns the tip text for this property.
  `boolean`
  `isInitialAnchorRandom()`
  Gets whether if the initial anchor is chosen randomly.
  `Enumeration<Option>`
  `listOptions()`
  Returns an enumeration describing the available options.
  `String`
  `printInsts(int startIdx, int endIdx)`
  For printing indices in some given portion of the master index array.
  `String`
  `printList(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList points)`
  For printing indices in a given point list.
  `String`
  `seedTipText()`
  Returns the tip text for this property.
  `void`
  `setInitialAnchorRandom(boolean randomInitialAnchor)`
  Sets whether if the initial anchor is chosen randomly.
  `void`
  `setInstanceList(int[] instList)`
  Sets the master index array that points to instances in m_Instances, so that only this array is manipulated, and m_Instances is left untouched.
  `void`
  `setInstances(Instances insts)`
  Sets the instances on which the tree is to be built.
  `void`
  `setInterAnchorDistances(Vector<weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode> anchors, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode newAnchor, Vector<double[]> anchorDistances)`
  Sets the distances of a supplied new anchor to all the rest of the previous anchor points.
  `void`
  `setMaxInstancesInLeaf(int num)`
  Sets the maximum number of instances allowed in a leaf.
  `void`
  `setOptions(String[] options)`
  Parses a given list of options.
  `void`
  `setPoints(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node, int startIdx, int endIdx, int[] indices)`
  Sets the points of an anchor node.
  `void`
  `setSeed(int seed)`
  Sets the seed for random number generator (that is used for selecting the first anchor point randomly).
  `boolean`
  `stealPoints(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode newAnchor, Vector<weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode> anchors, Vector<double[]> anchorDistances)`
  Removes points from old anchors that are nearer to the given new anchor and adds them to the list of points of the new anchor.

  ### Methods inherited from class weka.core.neighboursearch.balltrees.BallTreeConstructor

  `containChildBallsTipText, getContainChildBalls, getMaxDepth, getMaxInstancesInLeaf, getMaxRelativeLeafRadius, getNumLeaves, getNumNodes, maxInstancesInLeafTipText, maxRelativeLeafRadiusTipText, setContainChildBalls, setEuclideanDistanceFunction, setMaxRelativeLeafRadius`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MiddleOutConstructor

    public MiddleOutConstructor()
    Creates a new instance of MiddleOutConstructor.

- ## Method Details

  - ### globalInfo

    public String globalInfo()
    Returns a string describing this nearest neighbour search algorithm.
    Returns:
      a description of the algorithm for displaying in the explorer/experimenter gui

  - ### getTechnicalInformation

    public TechnicalInformation getTechnicalInformation()
    Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
    Specified by:
      `getTechnicalInformation` in interface `TechnicalInformationHandler`
    Returns:
      the technical information about this class

  - ### buildTree

    public BallNode buildTree() throws Exception
    Builds a ball tree middle out.
    Specified by:
      `buildTree` in class `BallTreeConstructor`
    Returns:
      The root node of the tree.
    Throws:
      `Exception` - If there is problem building the tree.

  - ### setPoints

    public void setPoints(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node, int startIdx, int endIdx, int[] indices)
    Sets the points of an anchor node. It takes the indices of points from the given portion of an index array and stores those indices, together with their distances to the given anchor node, in the point index list of the anchor node.
    Parameters:
      `node` - The node in which the points are needed to be set.
      `startIdx` - The start of the portion in the given index array (the master index array).
      `endIdx` - The end of the portion in the given index array.
      `indices` - The index array.

  - ### setInterAnchorDistances

    public void setInterAnchorDistances(Vector<weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode> anchors, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode newAnchor, Vector<double[]> anchorDistances) throws Exception
    Sets the distances of a supplied new anchor to all the rest of the previous anchor points.
    Parameters:
      `anchors` - The old anchor points.
      `newAnchor` - The new anchor point.
      `anchorDistances` - The vector to store the distances of newAnchor to each of the old anchors.
    Throws:
      `Exception` - If there is some problem in calculating the distances.

  - ### stealPoints

    public boolean stealPoints(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode newAnchor, Vector<weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode> anchors, Vector<double[]> anchorDistances)
    Removes points from old anchors that are nearer to the given new anchor and adds them to the list of points of the new anchor.
    Parameters:
      `newAnchor` - The new anchor.
      `anchors` - The old anchors.
      `anchorDistances` - The distances of new anchor to each of the old anchors.
    Returns:
      true if any points are removed from the old anchors

  - ### calcPivot

    public Instance calcPivot(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode node2, Instances insts)
    /** Calculates the centroid pivot of a node based on its two child nodes (if merging two nodes).
    Parameters:
      `node1` - The first child.
      `node2` - The second child.
      `insts` - The set of instances on which the tree is being built (as dataset header information is required).
    Returns:
      The centroid pivot of a node.

  - ### calcPivot

    public Instance calcPivot(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list2, Instances insts)
    Calculates the centroid pivot of a node based on the list of points that it contains (tbe two lists of its children are provided).
    Parameters:
      `list1` - The point index list of first child.
      `list2` - The point index list of second child.
      `insts` - The insts object on which the tree is being built (for header information).
    Returns:
      The centroid pivot of the node.

  - ### calcRadius

    public double calcRadius(weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode n1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.TempNode n2)
    Calculates the radius of a node based on its two child nodes (if merging two nodes).
    Parameters:
      `n1` - The first child of the node.
      `n2` - The second child of the node.
    Returns:
      The radius of the node.
    Throws:
      `Exception`

  - ### calcRadius

    public double calcRadius(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list1, weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list2, Instance pivot, Instances insts)
    Calculates the radius of a node based on the list of points that it contains (the two lists of its children are provided).
    Parameters:
      `list1` - The point index list of first child.
      `list2` - The point index list of second child.
      `pivot` - The centre/pivot of the node.
      `insts` - The instances on which the tree is being built (for header info).
    Returns:
      The radius of the node.

  - ### addInstance

    public int[] addInstance(BallNode node, Instance inst) throws Exception
    Adds an instance to the tree. This implementation of MiddleOutConstructor doesn't support addition of instances to already built tree, hence it always throws an exception.
    Specified by:
      `addInstance` in class `BallTreeConstructor`
    Parameters:
      `node` - The root of the tree to which the instance is to be added.
      `inst` - The instance to add to the tree.
    Returns:
      The updated master index array after adding the instance.
    Throws:
      `Exception` - Always as this implementation of MiddleOutConstructor doesn't support addition of instances after batch construction of the tree.

  - ### setMaxInstancesInLeaf

    public void setMaxInstancesInLeaf(int num) throws Exception
    Sets the maximum number of instances allowed in a leaf.
    Overrides:
      `setMaxInstancesInLeaf` in class `BallTreeConstructor`
    Parameters:
      `num` - The maximum number of instances allowed in a leaf.
    Throws:
      `Exception` - If the num is < 2, as the method cannot work for < 2 instances.

  - ### setInstances

    public void setInstances(Instances insts)
    Sets the instances on which the tree is to be built.
    Overrides:
      `setInstances` in class `BallTreeConstructor`
    Parameters:
      `insts` - The instances on which to build the ball tree.

  - ### setInstanceList

    public void setInstanceList(int[] instList)
    Sets the master index array that points to instances in m_Instances, so that only this array is manipulated, and m_Instances is left untouched.
    Overrides:
      `setInstanceList` in class `BallTreeConstructor`
    Parameters:
      `instList` - The master index array.

  - ### initialAnchorRandomTipText

    public String initialAnchorRandomTipText()
    Returns the tip text for this property.
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### isInitialAnchorRandom

    public boolean isInitialAnchorRandom()
    Gets whether if the initial anchor is chosen randomly.
    Returns:
      true if the initial anchor is a random one.

  - ### setInitialAnchorRandom

    public void setInitialAnchorRandom(boolean randomInitialAnchor)
    Sets whether if the initial anchor is chosen randomly. If not then if it is the furthest point from the mean/centroid.
    Parameters:
      `randomInitialAnchor` - Should be true if the first anchor is to be chosen randomly.

  - ### seedTipText

    public String seedTipText()
    Returns the tip text for this property.
    Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui

  - ### getSeed

    public int getSeed()
    Returns the seed for random number generator.
    Specified by:
      `getSeed` in interface `Randomizable`
    Returns:
      The random number seed.

  - ### setSeed

    public void setSeed(int seed)
    Sets the seed for random number generator (that is used for selecting the first anchor point randomly).
    Specified by:
      `setSeed` in interface `Randomizable`
    Parameters:
      `seed` - The seed.

  - ### listOptions

    public Enumeration<Option> listOptions()
    Returns an enumeration describing the available options.
    Specified by:
      `listOptions` in interface `OptionHandler`
    Overrides:
      `listOptions` in class `BallTreeConstructor`
    Returns:
      an enumeration of all the available options.

  - ### setOptions

    public void setOptions(String[] options) throws Exception
    Parses a given list of options. Valid options are:

         -S <num>
          The seed for the random number generator used
          in selecting random anchor.
         (default: 1)

         -R
          Use randomly chosen initial anchors.

    Specified by:
      `setOptions` in interface `OptionHandler`
    Overrides:
      `setOptions` in class `BallTreeConstructor`
    Parameters:
      `options` - the list of options as an array of strings
    Throws:
      `Exception` - if an option is not supported

  - ### getOptions

    public String[] getOptions()
    Gets the current settings of this BallTree MiddleOutConstructor.
    Specified by:
      `getOptions` in interface `OptionHandler`
    Overrides:
      `getOptions` in class `BallTreeConstructor`
    Returns:
      an array of strings suitable for passing to setOptions

  - ### checkIndicesList

    public void checkIndicesList(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList list, int startidx, int endidx) throws Exception
    Checks whether if the points in an index list are in some specified of the master index array.
    Parameters:
      `list` - The point list.
      `startidx` - The start of the portion in master index array.
      `endidx` - The end of the portion in master index array.
    Throws:
      `Exception` - If some point in the point list is not in the specified portion of master index array.

  - ### printInsts

    public String printInsts(int startIdx, int endIdx)
    For printing indices in some given portion of the master index array.
    Parameters:
      `startIdx` - The start of the portion in master index array.
      `endIdx` - The end of the portion in master index array.
    Returns:
      The string containing the indices in specified portion of the master index array.

  - ### printList

    public String printList(weka.core.neighboursearch.balltrees.MiddleOutConstructor.MyIdxList points)
    For printing indices in a given point list.
    Parameters:
      `points` - The point list.
    Returns:
      String containing indices of the points in the point list.

  - ### getRevision

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