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.
|
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).
|
Enumeration |
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(String additionalMeasureName)
Returns the value of the named measure.
|
String[] |
getOptions()
Gets the current settings of KDtree.
|
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.
|
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.
|
Enumeration |
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(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, setDistanceFunction
protected 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 String globalInfo()
globalInfo
in class NearestNeighbourSearch
public TechnicalInformation getTechnicalInformation()
getTechnicalInformation
in interface TechnicalInformationHandler
protected void buildTree() throws Exception
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 Exception
kNearestNeighbours
in class NearestNeighbourSearch
target
- The instance to find the k nearest neighbours for.k
- The number of nearest neighbours to find.Exception
- If the neighbours could not be found.protected void nearestNeighbours(NearestNeighbourSearch.MyHeap heap, BallNode node, Instance target, int k) throws 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.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 Exception
nearestNeighbour
in class NearestNeighbourSearch
target
- The instance to find the nearest neighbour for.Exception
- if the nearest neighbour could not be found.public double[] getDistances() throws Exception
getDistances
in class NearestNeighbourSearch
Exception
- if called before calling kNearestNeighbours
or nearestNeighbours.public void update(Instance ins) throws Exception
update
in class NearestNeighbourSearch
ins
- The instance to be added. Usually the newly added instance in the
training set.Exception
- If the instance cannot be added to the tree.public void addInstanceInfo(Instance ins)
addInstanceInfo
in class NearestNeighbourSearch
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.public void setInstances(Instances insts) throws Exception
setInstances
in class NearestNeighbourSearch
insts
- The insts for which the BallTree is to be
built.Exception
- If some error occurs while
building the BallTreepublic String ballTreeConstructorTipText()
public BallTreeConstructor getBallTreeConstructor()
public void setBallTreeConstructor(BallTreeConstructor constructor)
constructor
- The new BallTreeConstructor.public double measureTreeSize()
public double measureNumLeaves()
public double measureMaxDepth()
public Enumeration enumerateMeasures()
enumerateMeasures
in interface AdditionalMeasureProducer
enumerateMeasures
in class NearestNeighbourSearch
public double getMeasure(String additionalMeasureName)
getMeasure
in interface AdditionalMeasureProducer
getMeasure
in class NearestNeighbourSearch
additionalMeasureName
- the name of the measure to query for
its value.IllegalArgumentException
- if the named measure is not supported.public void setMeasurePerformance(boolean measurePerformance)
setMeasurePerformance
in class NearestNeighbourSearch
measurePerformance
- This should be true if performance
statistics are to be calculated.public Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class NearestNeighbourSearch
public void setOptions(String[] options) throws Exception
-C <classname and options> The construction method to employ. Either TopDown or BottomUp (default: weka.core.TopDownConstructor)
setOptions
in interface OptionHandler
setOptions
in class NearestNeighbourSearch
options
- the list of options as an array of stringsException
- if an option is not supportedpublic String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class NearestNeighbourSearch
public String getRevision()
getRevision
in interface RevisionHandler
Copyright © 2015 University of Waikato, Hamilton, NZ. All rights reserved.