public class KD_TreeNode extends TreeNode
The Value
element of the TreeNode
is cast to an double[]
in this class, where each list object is a dimension key value. So the structure
is a MetricDataset
storing one or more MetricValue
s that each store a double[].
This is also the internal conversion if a list of double[] is input, for example.
You can use the addChildNode
method on the root tree to add the nodes to
the structure.
Modifier and Type | Field and Description |
---|---|
protected int |
bucketSize
Tree node capacity, or the maximum number of child nodes in a parent node
|
protected FunctionMetric |
evaluator
For comparing tree values.
|
protected EvaluateMathDef |
mathCompare
Single value math comparisons - simple type
|
protected NodeStats |
nodeStats
Some value stats for the nodes
|
childNodeKeys, childNodes, count, name, parent, value, valueType
Constructor and Description |
---|
KD_TreeNode(int theBucketSize,
java.lang.String theValueType,
FunctionMetric metricEval,
EvaluateMathDef mathEval)
Create a new instance of KD_TreeNode.
|
KD_TreeNode(int theBucketSize,
java.lang.String theValueType,
MetricDataset theValueList,
FunctionMetric metricEval,
EvaluateMathDef mathEval)
Create a new instance of KD_TreeNode.
|
KD_TreeNode(java.lang.String theName,
int theBucketSize,
java.lang.String theValueType,
FunctionMetric metricEval,
EvaluateMathDef mathEval)
Create a new instance of KD_TreeNode.
|
KD_TreeNode(java.lang.String theName,
int theBucketSize,
java.lang.String theValueType,
MetricDataset theValueList,
FunctionMetric metricEval,
EvaluateMathDef mathEval)
Create a new instance of KD_TreeNode.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
addToTree(KD_TreeNode treeNode,
KD_TreeNode levelNode,
int level)
Add the node to the tree.
|
java.lang.Object |
clone()
Clone and return a copy of this object.
|
protected int |
getBestMatchIndex(java.lang.Object treeValue,
KD_TreeNode dimNode,
int dim)
Get the best position to insert the new node in the current list.
|
protected KD_TreeNode |
getBestMatchNode(java.lang.Object treeValue,
int level)
Get the best matching node from the child node list, with the following rules:
1. |
int |
getBucketSize()
Get the bucket size for this node.
|
java.lang.String |
getMathEvaluatorClass()
Get the class type for the math evaluator.
|
java.lang.String |
getMetricEvaluatorClass()
Get the class type for the dataset evaluator.
|
NodeStats |
getNodeStats()
Get the stat values for this node - min, max, median.
|
protected <T> void |
search(java.lang.String dsNode,
MetricDataset dataset,
java.util.ArrayList<KD_TreeNode> kClosest,
java.util.ArrayList<T> distances,
int level,
int k)
Search the tree and return the
k closest matches to the dataset. |
void |
setBucketSize(int theBucketSize)
Set the node bucket size or maximum capacity.
|
void |
setMathEvaluator(EvaluateMathDef theEvaluator)
Set the evaluator for mathematical expressions.
|
void |
setMetricEvaluator(FunctionMetric theEvaluator)
Set the evaluator for comparing datasets.
|
void |
setNodeStats(NodeStats theNodeStats)
Set the node stats.
|
protected void |
updateNodeStats(java.lang.Object dimValue)
Update this node's stats based on the single value for the dimension.
|
addChildNode, addChildNode, clearChildNodes, getChildNode, getChildNodeDeep, getChildNodeKeys, getChildNodes, getChildNodeValue, getChildNodeValueDeep, getCount, getName, getParent, getValue, getValueType, getValueTypeMD, hasChildNode, hasChildNodeDeep, hasChildNodes, hasChildNodeValue, hasChildNodeValueDeep, hasValue, isLeaf, maxDepth, nodesAtLevel, removeChildNode, setChildNodes, setChildNodes, setCount, setParent, setValue, toString, toString, treeValueDeep
protected int bucketSize
protected NodeStats nodeStats
protected EvaluateMathDef mathCompare
protected FunctionMetric evaluator
public KD_TreeNode(int theBucketSize, java.lang.String theValueType, FunctionMetric metricEval, EvaluateMathDef mathEval) throws java.lang.Exception
theBucketSize
- the tree node capacity.theValueType
- the type of value that this node supports.metricEval
- the evaluation function.mathEval
- for simple math comparisons.java.lang.Exception
- any error.public KD_TreeNode(java.lang.String theName, int theBucketSize, java.lang.String theValueType, FunctionMetric metricEval, EvaluateMathDef mathEval) throws java.lang.Exception
theName
- a unique name or ID for the node.theBucketSize
- the tree node capacity.theValueType
- the type of value that this node supports.metricEval
- the evaluation function.mathEval
- for simple math comparisons.java.lang.Exception
- any error.public KD_TreeNode(int theBucketSize, java.lang.String theValueType, MetricDataset theValueList, FunctionMetric metricEval, EvaluateMathDef mathEval) throws java.lang.Exception
theBucketSize
- the tree node capacity.theValueType
- the type of value that this node supports.theValueList
- the list of values for this node.metricEval
- the evaluation function.mathEval
- for simple math comparisons.java.lang.Exception
- any error.public KD_TreeNode(java.lang.String theName, int theBucketSize, java.lang.String theValueType, MetricDataset theValueList, FunctionMetric metricEval, EvaluateMathDef mathEval) throws java.lang.Exception
theName
- a unique name or ID for the node.theBucketSize
- the tree node capacity.theValueType
- the type of value that this node supports.theValueList
- the list of values for this node.metricEval
- the evaluation function.mathEval
- for simple math comparisons.java.lang.Exception
- any error.protected <T> void search(java.lang.String dsNode, MetricDataset dataset, java.util.ArrayList<KD_TreeNode> kClosest, java.util.ArrayList<T> distances, int level, int k) throws java.lang.Exception
k
closest matches to the dataset.dsNode
- name of the node the data belongs to, if already in the tree. This node is not then considered during the search,dataset
- the dataset to compare with, probably from the dataset node.kClosest
- add the k-closest nodes to this list.distances
- list of distances for each stored closest node.level
- the current tree level.k
- the number of matches to return.java.lang.Exception
- any error.protected boolean addToTree(KD_TreeNode treeNode, KD_TreeNode levelNode, int level) throws java.lang.Exception
treeNode
- the node with a list of values of size dimSize
.levelNode
- the node from the last level to add to.level
- the new tree level.java.lang.Exception
- any error.protected KD_TreeNode getBestMatchNode(java.lang.Object treeValue, int level) throws java.lang.Exception
treeValue
- the value to compare with. A single simple value, not a dataset,
which is evaluated using SimpleMathCompare.level
- the level in the tree adding the new node at, +1 from this node.java.lang.Exception
- any error.protected int getBestMatchIndex(java.lang.Object treeValue, KD_TreeNode dimNode, int dim) throws java.lang.Exception
treeValue
- the value to use.dimNode
- node that the list belongs to.dim
- dimension in the tree.java.lang.Exception
- any error.protected void updateNodeStats(java.lang.Object dimValue) throws java.lang.Exception
dimValue
- the dimension value only, not the full n-d list.java.lang.Exception
- any error.public void setBucketSize(int theBucketSize)
theBucketSize
- the bucket size.public int getBucketSize()
public void setNodeStats(NodeStats theNodeStats)
theNodeStats
- the node stats.public NodeStats getNodeStats()
public void setMetricEvaluator(FunctionMetric theEvaluator)
theEvaluator
- the evaluator to use.public void setMathEvaluator(EvaluateMathDef theEvaluator)
theEvaluator
- the evaluator to use.public java.lang.String getMetricEvaluatorClass()
public java.lang.String getMathEvaluatorClass()