public class BallTree extends NearestNeighbourSearch implements TechnicalInformationHandler
@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)
NearestNeighbourSearch.MyHeap, NearestNeighbourSearch.MyHeapElement, NearestNeighbourSearch.NeighborList, NearestNeighbourSearch.NeighborNode| Modifier and Type | Field and Description |
|---|---|
protected double[] |
m_Distances
Array holding the distances of the nearest neighbours.
|
protected int[] |
m_InstList
The instances indices sorted inorder of appearence in the tree from left
most leaf node to the right most leaf node.
|
protected int |
m_MaxInstancesInLeaf
The maximum number of instances in a leaf.
|
protected BallNode |
m_Root
The root node of the BallTree.
|
protected BallTreeConstructor |
m_TreeConstructor
The constructor method to use to build the tree.
|
protected TreePerformanceStats |
m_TreeStats
Tree Stats variables.
|
m_DistanceFunction, m_Instances, m_kNN, m_MeasurePerformance, m_Stats| Constructor and Description |
|---|
BallTree()
Creates a new instance of BallTree.
|
BallTree(Instances insts)
Creates a new instance of BallTree.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addInstanceInfo(Instance ins)
Adds the given instance's info.
|
java.lang.String |
ballTreeConstructorTipText()
Returns the tip text for this property.
|
protected void |
buildTree()
Builds the BallTree on the supplied set of
instances/points (supplied with setInstances(Instances)
method and referenced by the m_Instances field).
|
java.util.Enumeration<java.lang.String> |
enumerateMeasures()
Returns an enumeration of the additional measure names.
|
BallTreeConstructor |
getBallTreeConstructor()
Returns the BallTreeConstructor currently in use.
|
double[] |
getDistances()
Returns the distances of the k nearest neighbours.
|
double |
getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure.
|
java.lang.String[] |
getOptions()
Gets the current settings of KDtree.
|
java.lang.String |
getRevision()
Returns the revision string.
|
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.
|
java.lang.String |
globalInfo()
Returns a string describing this nearest neighbour search algorithm.
|
Instances |
kNearestNeighbours(Instance target,
int k)
Returns k nearest instances in the current neighbourhood to the supplied
instance.
|
java.util.Enumeration<Option> |
listOptions()
Returns an enumeration describing the available options.
|
double |
measureMaxDepth()
Returns the depth of the tree.
|
double |
measureNumLeaves()
Returns the number of leaves.
|
double |
measureTreeSize()
Returns the size of the tree.
|
Instance |
nearestNeighbour(Instance target)
Returns the nearest instance in the current neighbourhood to the supplied
instance.
|
protected void |
nearestNeighbours(NearestNeighbourSearch.MyHeap heap,
BallNode node,
Instance target,
int k)
Does NN search according to Moore's method.
|
void |
setBallTreeConstructor(BallTreeConstructor constructor)
Sets the BallTreeConstructor for building the BallTree
(default TopDownConstructor).
|
void |
setInstances(Instances insts)
Builds the BallTree based on the given set of instances.
|
void |
setMeasurePerformance(boolean measurePerformance)
Sets whether to calculate the performance statistics or not.
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options
|
void |
update(Instance ins)
Adds one instance to the BallTree.
|
combSort11, distanceFunctionTipText, getDistanceFunction, getInstances, getMeasurePerformance, getPerformanceStats, measurePerformanceTipText, partition, quickSort, setDistanceFunctionprotected int[] m_InstList
protected int m_MaxInstancesInLeaf
protected TreePerformanceStats m_TreeStats
protected BallNode m_Root
protected BallTreeConstructor m_TreeConstructor
protected double[] m_Distances
public BallTree()
public BallTree(Instances insts)
insts - The instances/points on which the BallTree
should be built on.public java.lang.String globalInfo()
globalInfo in class NearestNeighbourSearchpublic TechnicalInformation getTechnicalInformation()
getTechnicalInformation in interface TechnicalInformationHandlerprotected void buildTree()
throws java.lang.Exception
java.lang.Exception - If no instances are supplied
(m_Instances is null), or if some other error in the
supplied BallTreeConstructor occurs while building
the tree.public Instances kNearestNeighbours(Instance target, int k) throws java.lang.Exception
kNearestNeighbours in class NearestNeighbourSearchtarget - The instance to find the k nearest neighbours for.k - The number of nearest neighbours to find.java.lang.Exception - If the neighbours could not be found.protected void nearestNeighbours(NearestNeighbourSearch.MyHeap heap, BallNode node, Instance target, int k) throws java.lang.Exception
heap - MyHeap object to store/update NNs found during the search.node - The BallNode to do the NN search on.target - The target instance for which the NNs are required.k - The number of NNs to find.java.lang.Exception - If the structure of the BallTree is not correct,
or if there is some problem putting NNs in the heap.public Instance nearestNeighbour(Instance target) throws java.lang.Exception
nearestNeighbour in class NearestNeighbourSearchtarget - The instance to find the nearest neighbour for.java.lang.Exception - if the nearest neighbour could not be found.public double[] getDistances()
throws java.lang.Exception
getDistances in class NearestNeighbourSearchjava.lang.Exception - if called before calling kNearestNeighbours
or nearestNeighbours.public void update(Instance ins) throws java.lang.Exception
update in class NearestNeighbourSearchins - The instance to be added. Usually the newly added instance in the
training set.java.lang.Exception - If the instance cannot be added to the tree.public void addInstanceInfo(Instance ins)
addInstanceInfo in class NearestNeighbourSearchins - The instance to add the information of. Usually this is
the test instance supplied to update the range of
attributes in the distance function.public void setInstances(Instances insts) throws java.lang.Exception
setInstances in class NearestNeighbourSearchinsts - The insts for which the BallTree is to be
built.java.lang.Exception - If some error occurs while
building the BallTreepublic java.lang.String ballTreeConstructorTipText()
public BallTreeConstructor getBallTreeConstructor()
public void setBallTreeConstructor(BallTreeConstructor constructor)
constructor - The new BallTreeConstructor.public double measureTreeSize()
public double measureNumLeaves()
public double measureMaxDepth()
public java.util.Enumeration<java.lang.String> enumerateMeasures()
enumerateMeasures in interface AdditionalMeasureProducerenumerateMeasures in class NearestNeighbourSearchpublic double getMeasure(java.lang.String additionalMeasureName)
getMeasure in interface AdditionalMeasureProducergetMeasure in class NearestNeighbourSearchadditionalMeasureName - the name of the measure to query for
its value.java.lang.IllegalArgumentException - if the named measure is not supported.public void setMeasurePerformance(boolean measurePerformance)
setMeasurePerformance in class NearestNeighbourSearchmeasurePerformance - This should be true if performance
statistics are to be calculated.public java.util.Enumeration<Option> listOptions()
listOptions in interface OptionHandlerlistOptions in class NearestNeighbourSearchpublic void setOptions(java.lang.String[] options)
throws java.lang.Exception
-C <classname and options> The construction method to employ. Either TopDown or BottomUp (default: weka.core.TopDownConstructor)
setOptions in interface OptionHandlersetOptions in class NearestNeighbourSearchoptions - the list of options as an array of stringsjava.lang.Exception - if an option is not supportedpublic java.lang.String[] getOptions()
getOptions in interface OptionHandlergetOptions in class NearestNeighbourSearchpublic java.lang.String getRevision()
getRevision in interface RevisionHandler