本文整理汇总了C++中TreeType类的典型用法代码示例。如果您正苦于以下问题:C++ TreeType类的具体用法?C++ TreeType怎么用?C++ TreeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CleanTree
void CleanTree(TreeType& node)
{
node.Stat().LastDistance() = 0.0;
for (size_t i = 0; i < node.NumChildren(); ++i)
CleanTree(node.Child(i));
}
示例2: pruneTree
void CARTTrainer::pruneTree(TreeType & tree){
//Calculate g of all the nodes
measureStrength(tree, 0, 0);
//Find the lowest g of the internal nodes
double g = std::numeric_limits<double>::max();
for(std::size_t i = 0; i != tree.size(); i++){
if(tree[i].leftNodeId > 0 && tree[i].g < g){
//Update g
g = tree[i].g;
}
}
//Prune the nodes with lowest g and make them terminal
for(std::size_t i=0; i != tree.size(); i++){
//Make the internal nodes with the smallest g terminal nodes and prune their children!
if( tree[i].leftNodeId > 0 && tree[i].g == g){
// pruneNode(tree, tree[i].leftNodeId);
// pruneNode(tree, tree[i].rightNodeId);
// //Make the node terminal
tree[i].leftNodeId = 0;
tree[i].rightNodeId = 0;
}
}
}
示例3: DTBStat
DTBStat(const TreeType& node) :
maxNeighborDistance(DBL_MAX),
minNeighborDistance(DBL_MAX),
bound(DBL_MAX),
componentMembership(
((node.NumPoints() == 1) && (node.NumChildren() == 0)) ?
node.Point(0) : -1) { }
示例4: CheckHierarchy
void CheckHierarchy(const TreeType& tree)
{
for (size_t i = 0; i < tree.NumChildren(); i++)
{
BOOST_REQUIRE_EQUAL(&tree, tree.Child(i).Parent());
CheckHierarchy(tree.Child(i));
}
}
示例5: CalculateBound
double FastMKSRules<KernelType, TreeType>::Rescore(TreeType& queryNode,
TreeType& /*referenceNode*/,
const double oldScore) const
{
queryNode.Stat().Bound() = CalculateBound(queryNode);
const double bestKernel = queryNode.Stat().Bound();
return ((1.0 / oldScore) > bestKernel) ? oldScore : DBL_MAX;
}
示例6: FastMKSStat
FastMKSStat(const TreeType& node) :
bound(-DBL_MAX),
lastKernel(0.0),
lastKernelNode(NULL)
{
// Do we have to calculate the centroid?
if (tree::TreeTraits<TreeType>::FirstPointIsCentroid)
{
// If this type of tree has self-children, then maybe the evaluation is
// already done. These statistics are built bottom-up, so the child stat
// should already be done.
if ((tree::TreeTraits<TreeType>::HasSelfChildren) &&
(node.NumChildren() > 0) &&
(node.Point(0) == node.Child(0).Point(0)))
{
selfKernel = node.Child(0).Stat().SelfKernel();
}
else
{
selfKernel = sqrt(node.Metric().Kernel().Evaluate(
node.Dataset().col(node.Point(0)),
node.Dataset().col(node.Point(0))));
}
}
else
{
// Calculate the centroid.
arma::vec center;
node.Center(center);
selfKernel = sqrt(node.Metric().Kernel().Evaluate(center, center));
}
}
示例7: GetSplitPolicy
static int GetSplitPolicy(const TreeType& child,
const size_t axis,
const typename TreeType::ElemType cut)
{
if (child.Bound()[axis].Hi() <= cut)
return AssignToFirstTree;
else if (child.Bound()[axis].Lo() >= cut)
return AssignToSecondTree;
return SplitRequired;
}
示例8: pruneNode
/*
Removes branch with root node id nodeId, incl. the node itself
*/
void CARTTrainer::pruneNode(TreeType & tree, std::size_t nodeId){
std::size_t i = findNode(tree,nodeId);
if(tree[i].leftNodeId>0){
//Prune left branch
pruneNode(tree, tree[i].leftNodeId);
//Prune right branch
pruneNode(tree, tree[i].rightNodeId);
}
//Remove node
tree.erase(tree.begin()+i);
}
示例9: BaseCase
double RangeSearchRules<MetricType, TreeType>::Score(const size_t queryIndex,
TreeType& referenceNode)
{
// We must get the minimum and maximum distances and store them in this
// object.
math::Range distances;
if (tree::TreeTraits<TreeType>::FirstPointIsCentroid)
{
// In this situation, we calculate the base case. So we should check to be
// sure we haven't already done that.
double baseCase;
if (tree::TreeTraits<TreeType>::HasSelfChildren &&
(referenceNode.Parent() != NULL) &&
(referenceNode.Point(0) == referenceNode.Parent()->Point(0)))
{
// If the tree has self-children and this is a self-child, the base case
// was already calculated.
baseCase = referenceNode.Parent()->Stat().LastDistance();
lastQueryIndex = queryIndex;
lastReferenceIndex = referenceNode.Point(0);
}
else
{
// We must calculate the base case by hand.
baseCase = BaseCase(queryIndex, referenceNode.Point(0));
}
// This may be possibly loose for non-ball bound trees.
distances.Lo() = baseCase - referenceNode.FurthestDescendantDistance();
distances.Hi() = baseCase + referenceNode.FurthestDescendantDistance();
// Update last distance calculation.
referenceNode.Stat().LastDistance() = baseCase;
}
else
{
distances = referenceNode.RangeDistance(querySet.unsafe_col(queryIndex));
}
// If the ranges do not overlap, prune this node.
if (!distances.Contains(range))
return DBL_MAX;
// In this case, all of the points in the reference node will be part of the
// results.
if ((distances.Lo() >= range.Lo()) && (distances.Hi() <= range.Hi()))
{
AddResult(queryIndex, referenceNode);
return DBL_MAX; // We don't need to go any deeper.
}
// Otherwise the score doesn't matter. Recursion order is irrelevant in
// range search.
return 0.0;
}
示例10: UpdateAuxiliaryInfo
bool HilbertRTreeAuxiliaryInformation<TreeType, HilbertValueType>::
UpdateAuxiliaryInfo(TreeType* node)
{
if (node->IsLeaf()) // Should already be updated
return true;
TreeType* child = node->Children()[node->NumChildren() - 1];
if (hilbertValue.CompareWith(child->AuxiliaryInfo().hilbertValue()) < 0)
{
hilbertValue.Copy(node,child);
return true;
}
return false;
}
示例11: SearchTree
void SearchTree(TreeType<T>& tree)
{
T input;
cout << "Enter item to search: ";
cin >> input;
tree.SearchItem(input);
}
示例12: DeleteFromTree
void DeleteFromTree(TreeType<T>& tree)
{
T input;
cout << "Enter item to delete: ";
cin >> input;
tree.DeleteItem(input);
}
示例13: InsertItem
void InsertItem(TreeType<T>& tree)
{
cout << "Enter number: ";
T num;
cin >> num;
tree.InsertItem(num);
}
示例14: GetMaxLevel
int GetMaxLevel(const TreeType& tree)
{
int max = 1;
if (!tree.IsLeaf())
{
int m = 0;
for (size_t i = 0; i < tree.NumChildren(); i++)
{
int n = GetMaxLevel(*tree.Children()[i]);
if (n > m)
m = n;
}
max += m;
}
return max;
}
示例15: GetMinLevel
int GetMinLevel(const TreeType& tree)
{
int min = 1;
if (!tree.IsLeaf())
{
int m = INT_MAX;
for (size_t i = 0; i < tree.NumChildren(); i++)
{
int n = GetMinLevel(*tree.Children()[i]);
if (n < m)
m = n;
}
min += m;
}
return min;
}