Package weka.core.neighboursearch
Class BallTree
java.lang.Object
weka.core.neighboursearch.NearestNeighbourSearch
weka.core.neighboursearch.BallTree
- All Implemented Interfaces:
Serializable,AdditionalMeasureProducer,OptionHandler,RevisionHandler,TechnicalInformationHandler
Class implementing the BallTree/Metric Tree algorithm for nearest neighbour search.
The connection to dataset is only a reference. For the tree structure the indexes are stored in an array.
See the implementing classes of different construction methods of the trees for details on its construction.
For more information see also:
Stephen M. Omohundro (1989). Five Balltree Construction Algorithms.
Jeffrey K. Uhlmann (1991). Satisfying general proximity/similarity queries with metric trees. Information Processing Letters. 40(4):175-179. BibTeX:
The connection to dataset is only a reference. For the tree structure the indexes are stored in an array.
See the implementing classes of different construction methods of the trees for details on its construction.
For more information see also:
Stephen M. Omohundro (1989). Five Balltree Construction Algorithms.
Jeffrey K. Uhlmann (1991). Satisfying general proximity/similarity queries with metric trees. Information Processing Letters. 40(4):175-179. BibTeX:
@techreport{Omohundro1989,
author = {Stephen M. Omohundro},
institution = {International Computer Science Institute},
month = {December},
number = {TR-89-063},
title = {Five Balltree Construction Algorithms},
year = {1989}
}
@article{Uhlmann1991,
author = {Jeffrey K. Uhlmann},
journal = {Information Processing Letters},
month = {November},
number = {4},
pages = {175-179},
title = {Satisfying general proximity/similarity queries with metric trees},
volume = {40},
year = {1991}
}
Valid options are:
-C <classname and options> The construction method to employ. Either TopDown or BottomUp (default: weka.core.TopDownConstructor)
- Version:
- $Revision: 10141 $
- Author:
- Ashraf M. Kibriya (amk14[at-the-rate]cs[dot]waikato[dot]ac[dot]nz)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstanceInfo(Instance ins) Adds the given instance's info.Returns the tip text for this property.Returns an enumeration of the additional measure names.Returns the BallTreeConstructor currently in use.double[]Returns the distances of the k nearest neighbours.doublegetMeasure(String additionalMeasureName) Returns the value of the named measure.String[]Gets the current settings of KDtree.Returns the revision string.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.Returns a string describing this nearest neighbour search algorithm.kNearestNeighbours(Instance target, int k) Returns k nearest instances in the current neighbourhood to the supplied instance.Returns an enumeration describing the available options.doubleReturns the depth of the tree.doubleReturns the number of leaves.doubleReturns the size of the tree.nearestNeighbour(Instance target) Returns the nearest instance in the current neighbourhood to the supplied instance.voidsetBallTreeConstructor(BallTreeConstructor constructor) Sets the BallTreeConstructor for building the BallTree (default TopDownConstructor).voidsetInstances(Instances insts) Builds the BallTree based on the given set of instances.voidsetMeasurePerformance(boolean measurePerformance) Sets whether to calculate the performance statistics or not.voidsetOptions(String[] options) Parses a given list of options.voidAdds one instance to the BallTree.Methods inherited from class weka.core.neighboursearch.NearestNeighbourSearch
combSort11, distanceFunctionTipText, getDistanceFunction, getInstances, getMeasurePerformance, getPerformanceStats, measurePerformanceTipText, quickSort, setDistanceFunction
-
Constructor Details
-
BallTree
public BallTree()Creates a new instance of BallTree. -
BallTree
Creates a new instance of BallTree. It also builds the tree on supplied set of Instances.- Parameters:
insts- The instances/points on which the BallTree should be built on.
-
-
Method Details
-
globalInfo
Returns a string describing this nearest neighbour search algorithm.- Overrides:
globalInfoin classNearestNeighbourSearch- Returns:
- a description of the algorithm for displaying in the explorer/experimenter gui
-
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:
getTechnicalInformationin interfaceTechnicalInformationHandler- Returns:
- the technical information about this class
-
kNearestNeighbours
Returns k nearest instances in the current neighbourhood to the supplied instance. >k instances can be returned if there is more than one instance at the kth boundary (i.e. if there are more than 1 instance with the same distance as the kth nearest neighbour).- Specified by:
kNearestNeighboursin classNearestNeighbourSearch- Parameters:
target- The instance to find the k nearest neighbours for.k- The number of nearest neighbours to find.- Returns:
- The k nearest neighbours of the given target instance (>k nearest neighbours, if there are more instances that have same distance as the kth nearest neighbour).
- Throws:
Exception- If the neighbours could not be found.
-
nearestNeighbour
Returns the nearest instance in the current neighbourhood to the supplied instance.- Specified by:
nearestNeighbourin classNearestNeighbourSearch- Parameters:
target- The instance to find the nearest neighbour for.- Returns:
- The nearest neighbour of the given target instance.
- Throws:
Exception- if the nearest neighbour could not be found.
-
getDistances
Returns the distances of the k nearest neighbours. The kNearestNeighbours or nearestNeighbour must always be called before calling this function. If this function is called before calling either the kNearestNeighbours or the nearestNeighbour, then it throws an exception. If, however, any one of the two functions is called at any point in the past, then no exception is thrown and the distances of NN(s) from the training set for the last supplied target instance (to either one of the nearestNeighbour functions) is/are returned.- Specified by:
getDistancesin classNearestNeighbourSearch- Returns:
- array containing the distances of the nearestNeighbours. The length and ordering of the array is the same as that of the instances returned by nearestNeighbour functions.
- Throws:
Exception- if called before calling kNearestNeighbours or nearestNeighbours.
-
update
Adds one instance to the BallTree. This involves creating/updating the structure to reflect the newly added training instance- Specified by:
updatein classNearestNeighbourSearch- Parameters:
ins- The instance to be added. Usually the newly added instance in the training set.- Throws:
Exception- If the instance cannot be added to the tree.
-
addInstanceInfo
Adds the given instance's info. This implementation updates the attributes' range datastructures of EuclideanDistance class.- Overrides:
addInstanceInfoin classNearestNeighbourSearch- Parameters:
ins- The instance to add the information of. Usually this is the test instance supplied to update the range of attributes in the distance function.
-
setInstances
Builds the BallTree based on the given set of instances.- Overrides:
setInstancesin classNearestNeighbourSearch- Parameters:
insts- The insts for which the BallTree is to be built.- Throws:
Exception- If some error occurs while building the BallTree
-
ballTreeConstructorTipText
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
getBallTreeConstructor
Returns the BallTreeConstructor currently in use.- Returns:
- The BallTreeConstructor currently in use.
-
setBallTreeConstructor
Sets the BallTreeConstructor for building the BallTree (default TopDownConstructor).- Parameters:
constructor- The new BallTreeConstructor.
-
measureTreeSize
public double measureTreeSize()Returns the size of the tree.- Returns:
- the size of the tree
-
measureNumLeaves
public double measureNumLeaves()Returns the number of leaves.- Returns:
- the number of leaves
-
measureMaxDepth
public double measureMaxDepth()Returns the depth of the tree.- Returns:
- the number of rules
-
enumerateMeasures
Returns an enumeration of the additional measure names.- Specified by:
enumerateMeasuresin interfaceAdditionalMeasureProducer- Overrides:
enumerateMeasuresin classNearestNeighbourSearch- Returns:
- an enumeration of the measure names
-
getMeasure
Returns the value of the named measure.- Specified by:
getMeasurein interfaceAdditionalMeasureProducer- Overrides:
getMeasurein classNearestNeighbourSearch- Parameters:
additionalMeasureName- the name of the measure to query for its value.- Returns:
- the value of the named measure.
- Throws:
IllegalArgumentException- if the named measure is not supported.
-
setMeasurePerformance
public void setMeasurePerformance(boolean measurePerformance) Sets whether to calculate the performance statistics or not.- Overrides:
setMeasurePerformancein classNearestNeighbourSearch- Parameters:
measurePerformance- This should be true if performance statistics are to be calculated.
-
listOptions
Returns an enumeration describing the available options.- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classNearestNeighbourSearch- Returns:
- an enumeration of all the available options.
-
setOptions
Parses a given list of options. Valid options are:-C <classname and options> The construction method to employ. Either TopDown or BottomUp (default: weka.core.TopDownConstructor)
- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classNearestNeighbourSearch- Parameters:
options- the list of options as an array of strings- Throws:
Exception- if an option is not supported
-
getOptions
Gets the current settings of KDtree.- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classNearestNeighbourSearch- Returns:
- an array of strings suitable for passing to setOptions
-
getRevision
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-