[mlpack] 03/149: Switch int to size_t in order to fix a very large number of warnings.
Barak A. Pearlmutter
barak+git at pearlmutter.net
Sat May 2 09:11:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
bap pushed a commit to branch svn-trunk
in repository mlpack.
commit ec700f71ac6fa987c201a357dd516f85f73da7a3
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date: Thu Sep 11 21:10:55 2014 +0000
Switch int to size_t in order to fix a very large number of warnings.
git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17176 9d5b8971-822b-0410-80eb-d18c1038ef23
---
.../rectangle_tree/dual_tree_traverser_impl.hpp | 38 ++--
.../r_star_tree_descent_heuristic_impl.hpp | 4 +-
.../tree/rectangle_tree/r_star_tree_split_impl.hpp | 68 +++----
.../core/tree/rectangle_tree/r_tree_split_impl.hpp | 48 ++---
.../tree/rectangle_tree/rectangle_tree_impl.hpp | 12 +-
.../rectangle_tree/single_tree_traverser_impl.hpp | 4 +-
.../core/tree/rectangle_tree/x_tree_split_impl.hpp | 211 ++++++++++-----------
7 files changed, 192 insertions(+), 193 deletions(-)
diff --git a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp
index 7214986..1c4bbf3 100644
--- a/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/dual_tree_traverser_impl.hpp
@@ -43,17 +43,17 @@ DualTreeTraverser<RuleType>::Traverse(
{
// Increment the visit counter.
++numVisited;
-
+
// Store the current traversal info.
traversalInfo = rule.TraversalInfo();
-
+
// We now have four options.
// 1) Both nodes are leaf nodes.
// 2) Only the reference node is a leaf node.
// 3) Only the query node is a leaf node.
// 4) Niether node is a leaf node.
// We go through those options in that order.
-
+
if(queryNode.IsLeaf() && referenceNode.IsLeaf())
{
// Evaluate the base case. Do the query points on the outside so we can possibly
@@ -63,13 +63,13 @@ DualTreeTraverser<RuleType>::Traverse(
// Restore the traversal information.
rule.TraversalInfo() = traversalInfo;
const double childScore = rule.Score(queryNode.Points()[query], referenceNode);
-
+
if(childScore == DBL_MAX)
continue; // This point doesn't require a search in this reference node.
-
+
for(size_t ref = 0; ref < referenceNode.Count(); ++ref)
rule.BaseCase(queryNode.Points()[query], referenceNode.Points()[ref]);
-
+
numBaseCases += referenceNode.Count();
}
}
@@ -85,15 +85,15 @@ DualTreeTraverser<RuleType>::Traverse(
Traverse(queryNode.Child(i), referenceNode);
else
numPrunes++;
- }
+ }
}
else if(queryNode.IsLeaf() && !referenceNode.IsLeaf())
{
// We only need to traverse down the reference node. Order does matter here.
-
- // We sort the children of the reference node by their scores.
+
+ // We sort the children of the reference node by their scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
- for(int i = 0; i < referenceNode.NumChildren(); i++)
+ for (size_t i = 0; i < referenceNode.NumChildren(); i++)
{
rule.TraversalInfo() = traversalInfo;
nodesAndScores[i].node = referenceNode.Children()[i];
@@ -102,8 +102,8 @@ DualTreeTraverser<RuleType>::Traverse(
}
std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator);
numScores += nodesAndScores.size();
-
- for(int i = 0; i < nodesAndScores.size(); i++)
+
+ for (size_t i = 0; i < nodesAndScores.size(); i++)
{
rule.TraversalInfo() = nodesAndScores[i].travInfo;
if(rule.Rescore(queryNode, *(nodesAndScores[i].node), nodesAndScores[i].score) < DBL_MAX) {
@@ -119,12 +119,12 @@ DualTreeTraverser<RuleType>::Traverse(
// We need to traverse down both the reference and the query trees.
// We loop through all of the query nodes, and for each of them, we
// loop through the reference nodes to see where we need to descend.
-
- for(int j = 0; j < queryNode.NumChildren(); j++)
+
+ for (size_t j = 0; j < queryNode.NumChildren(); j++)
{
- // We sort the children of the reference node by their scores.
+ // We sort the children of the reference node by their scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
- for(int i = 0; i < referenceNode.NumChildren(); i++)
+ for (size_t i = 0; i < referenceNode.NumChildren(); i++)
{
rule.TraversalInfo() = traversalInfo;
nodesAndScores[i].node = referenceNode.Children()[i];
@@ -133,8 +133,8 @@ DualTreeTraverser<RuleType>::Traverse(
}
std::sort(nodesAndScores.begin(), nodesAndScores.end(), nodeComparator);
numScores += nodesAndScores.size();
-
- for(int i = 0; i < nodesAndScores.size(); i++)
+
+ for (size_t i = 0; i < nodesAndScores.size(); i++)
{
rule.TraversalInfo() = nodesAndScores[i].travInfo;
if(rule.Rescore(queryNode.Child(j), *(nodesAndScores[i].node), nodesAndScores[i].score) < DBL_MAX) {
@@ -151,4 +151,4 @@ DualTreeTraverser<RuleType>::Traverse(
}; // namespace tree
}; // namespace mlpack
-#endif
\ No newline at end of file
+#endif
diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp
index e7f8bc8..e8800ea 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_descent_heuristic_impl.hpp
@@ -113,7 +113,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
// We break ties by choosing the smallest bound.
double minVol = DBL_MAX;
bestIndex = 0;
- for (int i = 0; i < scores.size(); i++)
+ for (size_t i = 0; i < scores.size(); i++)
{
if (scores[i] == minScore)
{
@@ -178,7 +178,7 @@ inline size_t RStarTreeDescentHeuristic::ChooseDescentNode(
// We break ties by choosing the smallest bound.
double minVol = DBL_MAX;
bestIndex = 0;
- for (int i = 0; i < scores.size(); i++)
+ for (size_t i = 0; i < scores.size(); i++)
{
if (scores[i] == minScore)
{
diff --git a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
index d1b5c20..2d771c0 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_star_tree_split_impl.hpp
@@ -98,12 +98,12 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
int bestAxis = 0;
double bestAxisScore = DBL_MAX;
- for (int j = 0; j < tree->Bound().Dim(); j++)
+ for (size_t j = 0; j < tree->Bound().Dim(); j++)
{
double axisScore = 0.0;
// Since we only have points in the leaf nodes, we only need to sort once.
std::vector<SortStruct> sorted(tree->Count());
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->LocalDataset().col(i)[j];
sorted[i].n = i;
@@ -119,14 +119,14 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
std::vector<double> overlapedAreas(tree->MaxLeafSize() -
2 * tree->MinLeafSize() + 2);
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
// The ith arrangement is obtained by placing the first
// tree->MinLeafSize() + i points in one rectangle and the rest in
@@ -139,13 +139,13 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
std::vector<double> minG1(maxG1.size());
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++)
+ for (size_t k = 0; k < tree->Bound().Dim(); k++)
{
minG1[k] = maxG1[k] = tree->LocalDataset().col(sorted[0].n)[k];
minG2[k] = maxG2[k] =
tree->LocalDataset().col(sorted[sorted.size() - 1].n)[k];
- for (int l = 1; l < tree->Count() - 1; l++)
+ for (size_t l = 1; l < tree->Count() - 1; l++)
{
if (l < cutOff)
{
@@ -166,7 +166,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++)
+ for (size_t k = 0; k < maxG1.size(); k++)
{
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
@@ -187,7 +187,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
bestOverlapIndexOnBestAxis = 0;
bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++)
+ for (size_t i = 1; i < areas.size(); i++)
{
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis])
{
@@ -207,7 +207,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
}
std::vector<SortStruct> sorted(tree->Count());
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->LocalDataset().col(i)[bestAxis];
sorted[i].n = i;
@@ -220,7 +220,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
if (tiedOnOverlap)
{
- for (int i = 0; i < tree->Count(); i++)
+ for (size_t i = 0; i < tree->Count(); i++)
{
if (i < bestAreaIndexOnBestAxis + tree->MinLeafSize())
treeOne->InsertPoint(tree->Points()[sorted[i].n]);
@@ -230,7 +230,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
}
else
{
- for (int i = 0; i < tree->Count(); i++)
+ for (size_t i = 0; i < tree->Count(); i++)
{
if (i < bestOverlapIndexOnBestAxis + tree->MinLeafSize())
treeOne->InsertPoint(tree->Points()[sorted[i].n]);
@@ -244,7 +244,7 @@ void RStarTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
size_t index = 0;
while (par->Children()[index] != tree) { index++; }
- assert(index != -1);
+ assert(index != par->NumChildren());
par->Children()[index] = treeOne;
par->Children()[par->NumChildren()++] = treeTwo;
@@ -361,13 +361,13 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
bool lowIsBest = true;
int bestAxis = 0;
double bestAxisScore = DBL_MAX;
- for (int j = 0; j < tree->Bound().Dim(); j++)
+ for (size_t j = 0; j < tree->Bound().Dim(); j++)
{
double axisScore = 0.0;
// We'll do Bound().Lo() now and use Bound().Hi() later.
std::vector<SortStruct> sorted(tree->NumChildren());
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->Children()[i]->Bound()[j].Lo();
sorted[i].n = i;
@@ -383,14 +383,14 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> overlapedAreas(tree->MaxNumChildren() -
2 * tree->MinNumChildren() + 2);
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
// The ith arrangement is obtained by placing the first
// tree->MinNumChildren() + i points in one rectangle and the rest in
@@ -403,7 +403,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> minG1(maxG1.size());
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++)
+ for (size_t k = 0; k < tree->Bound().Dim(); k++)
{
minG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Lo();
maxG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Hi();
@@ -412,7 +412,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
maxG2[k] =
tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Hi();
- for (int l = 1; l < tree->NumChildren() - 1; l++)
+ for (size_t l = 1; l < tree->NumChildren() - 1; l++)
{
if (l < cutOff)
{
@@ -433,7 +433,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++)
+ for (size_t k = 0; k < maxG1.size(); k++)
{
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
@@ -453,7 +453,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
bestAxis = j;
double bestOverlapIndexOnBestAxis = 0;
double bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++)
+ for (size_t i = 1; i < areas.size(); i++)
{
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis])
{
@@ -473,13 +473,13 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
// Now we do the same thing using Bound().Hi() and choose the best of the two.
- for (int j = 0; j < tree->Bound().Dim(); j++)
+ for (size_t j = 0; j < tree->Bound().Dim(); j++)
{
double axisScore = 0.0;
// We'll do Bound().Lo() now and use Bound().Hi() later.
std::vector<SortStruct> sorted(tree->NumChildren());
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->Children()[i]->Bound()[j].Hi();
sorted[i].n = i;
@@ -495,14 +495,14 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> overlapedAreas(tree->MaxNumChildren() -
2 * tree->MinNumChildren() + 2);
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++)
+ for (size_t i = 0; i < areas.size(); i++)
{
// The ith arrangement is obtained by placing the first
// tree->MinNumChildren() + i points in one rectangle and the rest in
@@ -516,7 +516,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++)
+ for (size_t k = 0; k < tree->Bound().Dim(); k++)
{
minG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Lo();
maxG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Hi();
@@ -525,7 +525,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
maxG2[k] =
tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Hi();
- for (int l = 1; l < tree->NumChildren() - 1; l++)
+ for (size_t l = 1; l < tree->NumChildren() - 1; l++)
{
if (l < cutOff)
{
@@ -547,7 +547,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++)
+ for (size_t k = 0; k < maxG1.size(); k++)
{
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
@@ -569,7 +569,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
double bestOverlapIndexOnBestAxis = 0;
double bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++)
+ for (size_t i = 1; i < areas.size(); i++)
{
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis])
{
@@ -591,7 +591,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<SortStruct> sorted(tree->NumChildren());
if (lowIsBest)
{
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->Children()[i]->Bound()[bestAxis].Lo();
sorted[i].n = i;
@@ -599,7 +599,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
else
{
- for (int i = 0; i < sorted.size(); i++)
+ for (size_t i = 0; i < sorted.size(); i++)
{
sorted[i].d = tree->Children()[i]->Bound()[bestAxis].Hi();
sorted[i].n = i;
@@ -613,7 +613,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
if (tiedOnOverlap)
{
- for (int i = 0; i < tree->NumChildren(); i++)
+ for (size_t i = 0; i < tree->NumChildren(); i++)
{
if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, tree->Children()[sorted[i].n]);
@@ -623,7 +623,7 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
else
{
- for (int i = 0; i < tree->NumChildren(); i++)
+ for (size_t i = 0; i < tree->NumChildren(); i++)
{
if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, tree->Children()[sorted[i].n]);
@@ -650,10 +650,10 @@ bool RStarTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
// We have to update the children of each of these new nodes so that they
// record the correct parent.
- for (int i = 0; i < treeOne->NumChildren(); i++)
+ for (size_t i = 0; i < treeOne->NumChildren(); i++)
treeOne->Children()[i]->Parent() = treeOne;
- for (int i = 0; i < treeTwo->NumChildren(); i++)
+ for (size_t i = 0; i < treeTwo->NumChildren(); i++)
treeTwo->Children()[i]->Parent() = treeTwo;
assert(treeOne->Parent()->NumChildren() <= treeOne->MaxNumChildren());
diff --git a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
index 1905a91..22aa7a1 100644
--- a/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
@@ -127,11 +127,11 @@ bool RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
size_t index = 0;
while (par->Children()[index] != tree) { ++index; }
- assert(index != -1);
+ assert(index != par->NumChildren());
par->Children()[index] = treeOne;
par->Children()[par->NumChildren()++] = treeTwo;
- for (int i = 0; i < par->NumChildren(); i++)
+ for (size_t i = 0; i < par->NumChildren(); i++)
assert(par->Children()[i] != tree);
// We only add one at a time, so should only need to test for equality just in
@@ -143,10 +143,10 @@ bool RTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
// We have to update the children of each of these new nodes so that they
// record the correct parent.
- for (int i = 0; i < treeOne->NumChildren(); i++)
+ for (size_t i = 0; i < treeOne->NumChildren(); i++)
treeOne->Children()[i]->Parent() = treeOne;
- for (int i = 0; i < treeTwo->NumChildren(); i++)
+ for (size_t i = 0; i < treeTwo->NumChildren(); i++)
treeTwo->Children()[i]->Parent() = treeTwo;
assert(treeOne->NumChildren() <= treeOne->MaxNumChildren());
@@ -176,9 +176,9 @@ void RTreeSplit<DescentType, StatisticType, MatType>::GetPointSeeds(
// same node. Because we are just using points, we will simply choose the two
// that would create the most voluminous hyperrectangle.
double worstPairScore = -1.0;
- for (int i = 0; i < tree.Count(); i++)
+ for (size_t i = 0; i < tree.Count(); i++)
{
- for (int j = i + 1; j < tree.Count(); j++)
+ for (size_t j = i + 1; j < tree.Count(); j++)
{
const double score = arma::prod(arma::abs(tree.LocalDataset().col(i) -
tree.LocalDataset().col(j)));
@@ -206,12 +206,12 @@ void RTreeSplit<DescentType, StatisticType, MatType>::GetBoundSeeds(
int& jRet)
{
double worstPairScore = -1.0;
- for (int i = 0; i < tree.NumChildren(); i++)
+ for (size_t i = 0; i < tree.NumChildren(); i++)
{
- for (int j = i + 1; j < tree.NumChildren(); j++)
+ for (size_t j = i + 1; j < tree.NumChildren(); j++)
{
double score = 1.0;
- for (int k = 0; k < tree.Bound().Dim(); k++)
+ for (size_t k = 0; k < tree.Bound().Dim(); k++)
{
const double hiMax = std::max(tree.Children()[i]->Bound()[k].Hi(),
tree.Children()[j]->Bound()[k].Hi());
@@ -269,8 +269,8 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignPointDestNode(
oldTree->LocalDataset().col(intI) = oldTree->LocalDataset().col(end);
}
- int numAssignedOne = 1;
- int numAssignedTwo = 1;
+ size_t numAssignedOne = 1;
+ size_t numAssignedTwo = 1;
// In each iteration, we go through all points and find the one that causes
// the least increase of volume when added to one of the rectangles. We then
@@ -302,11 +302,11 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignPointDestNode(
// Find the point that, when assigned to one of the two new rectangles,
// minimizes the increase in volume.
- for (int index = 0; index < end; index++)
+ for (size_t index = 0; index < end; index++)
{
double newVolOne = 1.0;
double newVolTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
+ for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
{
double c = oldTree->LocalDataset().col(index)[i];
newVolOne *= treeOne->Bound()[i].Contains(c) ?
@@ -387,8 +387,8 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignNodeDestNode(
assert(intI != intJ);
- for (int i = 0; i < oldTree->NumChildren(); i++)
- for (int j = i + 1; j < oldTree->NumChildren(); j++)
+ for (size_t i = 0; i < oldTree->NumChildren(); i++)
+ for (size_t j = i + 1; j < oldTree->NumChildren(); j++)
assert(oldTree->Children()[i] != oldTree->Children()[j]);
InsertNodeIntoTree(treeOne, oldTree->Children()[intI]);
@@ -420,8 +420,8 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignNodeDestNode(
for (int i = 0; i < end; i++)
assert(oldTree->Children()[i] != treeTwo->Children()[0]);
- int numAssignTreeOne = 1;
- int numAssignTreeTwo = 1;
+ size_t numAssignTreeOne = 1;
+ size_t numAssignTreeTwo = 1;
// In each iteration, we go through all of the nodes and find the one that
// causes the least increase of volume when added to one of the two new
@@ -437,17 +437,17 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignNodeDestNode(
// new rectangles.
double volOne = 1.0;
double volTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
+ for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
{
volOne *= treeOne->Bound()[i].Width();
volTwo *= treeTwo->Bound()[i].Width();
}
- for (int index = 0; index < end; index++)
+ for (size_t index = 0; index < end; index++)
{
double newVolOne = 1.0;
double newVolTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
+ for (size_t i = 0; i < oldTree->Bound().Dim(); i++)
{
// For each of the new rectangles, find the width in this dimension if
// we add the rectangle at index to the new rectangle.
@@ -523,12 +523,12 @@ void RTreeSplit<DescentType, StatisticType, MatType>::AssignNodeDestNode(
}
}
- for (int i = 0; i < treeOne->NumChildren(); i++)
- for (int j = i + 1; j < treeOne->NumChildren(); j++)
+ for (size_t i = 0; i < treeOne->NumChildren(); i++)
+ for (size_t j = i + 1; j < treeOne->NumChildren(); j++)
assert(treeOne->Children()[i] != treeOne->Children()[j]);
- for (int i = 0; i < treeTwo->NumChildren(); i++)
- for (int j = i + 1; j < treeTwo->NumChildren(); j++)
+ for (size_t i = 0; i < treeTwo->NumChildren(); i++)
+ for (size_t j = i + 1; j < treeTwo->NumChildren(); j++)
assert(treeTwo->Children()[i] != treeTwo->Children()[j]);
}
diff --git a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
index afbb5dc..01e24bd 100644
--- a/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/rectangle_tree_impl.hpp
@@ -139,7 +139,7 @@ template<typename SplitType,
typename MatType>
RectangleTree<SplitType, DescentType, StatisticType, MatType>::~RectangleTree()
{
- for (int i = 0; i < numChildren; i++)
+ for (size_t i = 0; i < numChildren; i++)
delete children[i];
delete localDataset;
@@ -157,7 +157,7 @@ void RectangleTree<SplitType, DescentType, StatisticType, MatType>::SoftDelete()
{
parent = NULL;
- for (int i = 0; i < children.size(); i++)
+ for (size_t i = 0; i < children.size(); i++)
children[i] = NULL;
numChildren = 0;
@@ -192,7 +192,7 @@ void RectangleTree<SplitType, DescentType, StatisticType, MatType>::InsertPoint(
bound |= dataset.col(point);
std::vector<bool> lvls(TreeDepth());
- for (int i = 0; i < lvls.size(); i++)
+ for (size_t i = 0; i < lvls.size(); i++)
lvls[i] = true;
// If this is a leaf node, we stop here and add the point.
@@ -294,7 +294,7 @@ bool RectangleTree<SplitType, DescentType, StatisticType, MatType>::DeletePoint(
root = root->Parent();
std::vector<bool> lvls(root->TreeDepth());
- for (int i = 0; i < lvls.size(); i++)
+ for (size_t i = 0; i < lvls.size(); i++)
lvls[i] = true;
if (numChildren == 0)
@@ -502,7 +502,7 @@ inline size_t RectangleTree<SplitType, DescentType, StatisticType, MatType>::
else
{
size_t n = 0;
- for (int i = 0; i < numChildren; i++)
+ for (size_t i = 0; i < numChildren; i++)
n += children[i]->NumDescendants();
return n;
@@ -669,7 +669,7 @@ void RectangleTree<SplitType, DescentType, StatisticType, MatType>::
children[i] = child->Children()[i];
children[i]->Parent() = this;
}
-
+
numChildren = child->NumChildren();
for (size_t i = 0; i < child->Count(); i++)
diff --git a/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
index 2bae871..68f8f1f 100644
--- a/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/single_tree_traverser_impl.hpp
@@ -52,7 +52,7 @@ SingleTreeTraverser<RuleType>::Traverse(
// This is not a leaf node so we sort the children of this node by their
// scores.
std::vector<NodeAndScore> nodesAndScores(referenceNode.NumChildren());
- for (int i = 0; i < referenceNode.NumChildren(); i++)
+ for (size_t i = 0; i < referenceNode.NumChildren(); i++)
{
nodesAndScores[i].node = referenceNode.Children()[i];
nodesAndScores[i].score = rule.Score(queryIndex, *nodesAndScores[i].node);
@@ -62,7 +62,7 @@ SingleTreeTraverser<RuleType>::Traverse(
// Now iterate through them starting with the best and stopping when we reach
// one that isn't good enough.
- for (int i = 0; i < referenceNode.NumChildren(); i++)
+ for (size_t i = 0; i < referenceNode.NumChildren(); i++)
{
if (rule.Rescore(queryIndex, *nodesAndScores[i].node,
nodesAndScores[i].score) != DBL_MAX)
diff --git a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
index f1530a2..5ab24ff 100644
--- a/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
+++ b/src/mlpack/core/tree/rectangle_tree/x_tree_split_impl.hpp
@@ -30,7 +30,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
// If we are splitting the root node, we need will do things differently so that the constructor
// and other methods don't confuse the end user by giving an address of another node.
if (tree->Parent() == NULL) {
- RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
+ RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
new RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(*tree, false); // We actually want to copy this way. Pointers and everything.
copy->Parent() = tree;
@@ -41,7 +41,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(copy, relevels);
return;
}
-
+
// If we haven't yet reinserted on this level, we try doing so now.
if(relevels[tree->TreeDepth()]) {
relevels[tree->TreeDepth()] = false;
@@ -55,7 +55,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
SplitLeafNode(tree, relevels);
return;
}
-
+
std::vector<sortStruct> sorted(tree->Count());
arma::vec centroid;
tree->Bound().Centroid(centroid); // Modifies centroid.
@@ -63,7 +63,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
sorted[i].d = tree->Bound().Metric().Evaluate(centroid, tree->LocalDataset().col(i));
sorted[i].n = i;
}
-
+
std::sort(sorted.begin(), sorted.end(), structComp);
std::vector<int> pointIndices(p);
for(size_t i = 0; i < p; i++) {
@@ -73,7 +73,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
for(size_t i = 0; i < p; i++) { // We reverse the order again to reinsert the closest points first.
root->InsertPoint(pointIndices[p-1-i], relevels);
}
-
+
// // If we went below min fill, delete this node and reinsert all points.
// if(tree->Count() < tree->MinLeafSize()) {
// std::vector<int> pointIndices(tree->Count());
@@ -84,22 +84,22 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
// for(size_t i = 0; i < pointIndices.size(); i++) {
// root->InsertPoint(pointIndices[i], relevels);
// }
-// //tree->SoftDelete();
+// //tree->SoftDelete();
// }
return;
}
-
+
int bestOverlapIndexOnBestAxis = 0;
int bestAreaIndexOnBestAxis = 0;
bool tiedOnOverlap = false;
int bestAxis = 0;
double bestAxisScore = DBL_MAX;
- for (int j = 0; j < tree->Bound().Dim(); j++) {
+ for (size_t j = 0; j < tree->Bound().Dim(); j++) {
double axisScore = 0.0;
// Since we only have points in the leaf nodes, we only need to sort once.
std::vector<sortStruct> sorted(tree->Count());
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->LocalDataset().col(i)[j];
sorted[i].n = i;
}
@@ -110,26 +110,26 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
std::vector<double> areas(tree->MaxLeafSize() - 2 * tree->MinLeafSize() + 2);
std::vector<double> margins(tree->MaxLeafSize() - 2 * tree->MinLeafSize() + 2);
std::vector<double> overlapedAreas(tree->MaxLeafSize() - 2 * tree->MinLeafSize() + 2);
- for (int i = 0; i < areas.size(); i++) {
+ for (size_t i = 0; i < areas.size(); i++) {
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++) {
- // The ith arrangement is obtained by placing the first tree->MinLeafSize() + i
+ for (size_t i = 0; i < areas.size(); i++) {
+ // The ith arrangement is obtained by placing the first tree->MinLeafSize() + i
// points in one rectangle and the rest in another. Then we calculate the three
// scores for that distribution.
- int cutOff = tree->MinLeafSize() + i;
+ size_t cutOff = tree->MinLeafSize() + i;
// We'll calculate the max and min in each dimension by hand to save time.
std::vector<double> maxG1(tree->Bound().Dim());
std::vector<double> minG1(maxG1.size());
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++) {
+ for (size_t k = 0; k < tree->Bound().Dim(); k++) {
minG1[k] = maxG1[k] = tree->LocalDataset().col(sorted[0].n)[k];
minG2[k] = maxG2[k] = tree->LocalDataset().col(sorted[sorted.size() - 1].n)[k];
- for (int l = 1; l < tree->Count() - 1; l++) {
+ for (size_t l = 1; l < tree->Count() - 1; l++) {
if (l < cutOff) {
if (tree->LocalDataset().col(sorted[l].n)[k] < minG1[k])
minG1[k] = tree->LocalDataset().col(sorted[l].n)[k];
@@ -145,7 +145,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
}
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++) {
+ for (size_t k = 0; k < maxG1.size(); k++) {
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
area2 *= maxG2[k] - minG2[k];
@@ -161,7 +161,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
bestAxis = j;
bestOverlapIndexOnBestAxis = 0;
bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++) {
+ for (size_t i = 1; i < areas.size(); i++) {
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) {
tiedOnOverlap = false;
bestAreaIndexOnBestAxis = i;
@@ -176,7 +176,7 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
}
std::vector<sortStruct> sorted(tree->Count());
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->LocalDataset().col(i)[bestAxis];
sorted[i].n = i;
}
@@ -192,14 +192,14 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
// since a split axis is chosen and then points are assigned based on their value
// along that axis.
if (tiedOnOverlap) {
- for (int i = 0; i < tree->Count(); i++) {
+ for (size_t i = 0; i < tree->Count(); i++) {
if (i < bestAreaIndexOnBestAxis + tree->MinLeafSize())
treeOne->InsertPoint(tree->Points()[sorted[i].n]);
else
treeTwo->InsertPoint(tree->Points()[sorted[i].n]);
}
} else {
- for (int i = 0; i < tree->Count(); i++) {
+ for (size_t i = 0; i < tree->Count(); i++) {
if (i < bestOverlapIndexOnBestAxis + tree->MinLeafSize())
treeOne->InsertPoint(tree->Points()[sorted[i].n]);
else
@@ -209,30 +209,30 @@ void XTreeSplit<DescentType, StatisticType, MatType>::SplitLeafNode(
//Remove this node and insert treeOne and treeTwo
RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* par = tree->Parent();
- int index = -1;
- for (int i = 0; i < par->NumChildren(); i++) {
+ size_t index = par->NumChildren();
+ for (size_t i = 0; i < par->NumChildren(); i++) {
if (par->Children()[i] == tree) {
index = i;
break;
}
}
- assert(index != -1);
+ assert(index != par->NumChildren());
par->Children()[index] = treeOne;
par->Children()[par->NumChildren()++] = treeTwo;
-
+
//We now update the split history of each new node.
treeOne->SplitHistory().history[bestAxis] = true;
treeOne->SplitHistory().lastDimension = bestAxis;
treeTwo->SplitHistory().history[bestAxis] = true;
- treeTwo->SplitHistory().lastDimension = bestAxis;
-
+ treeTwo->SplitHistory().lastDimension = bestAxis;
+
// we only add one at a time, so we should only need to test for equality
// just in case, we use an assert.
assert(par->NumChildren() <= par->MaxNumChildren()+1);
if (par->NumChildren() == par->MaxNumChildren()+1) {
SplitNonLeafNode(par, relevels);
}
-
+
assert(treeOne->Parent()->NumChildren() <= treeOne->Parent()->MaxNumChildren());
assert(treeOne->Parent()->NumChildren() >= treeOne->Parent()->MinNumChildren());
assert(treeTwo->Parent()->NumChildren() <= treeTwo->Parent()->MaxNumChildren());
@@ -260,7 +260,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
// If we are splitting the root node, we need will do things differently so that the constructor
// and other methods don't confuse the end user by giving an address of another node.
if (tree->Parent() == NULL) {
- RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
+ RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* copy =
new RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>(*tree, false); // We actually want to copy this way. Pointers and everything.
copy->Parent() = tree;
@@ -273,21 +273,21 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
// The X tree paper doesn't explain how to handle the split history when reinserting nodes
// and reinserting nodes seems to hurt the performance, so we don't do it.
-
-
+
+
// We find the split axis that will be used if the topological split fails now
// to save CPU time.
-
+
// Find the next split axis.
std::vector<bool> axes(tree->Bound().Dim());
std::vector<int> dimensionsLastUsed(tree->NumChildren());
for(size_t i = 0; i < tree->NumChildren(); i++)
dimensionsLastUsed[i] = tree->Child(i).SplitHistory().lastDimension;
std::sort(dimensionsLastUsed.begin(), dimensionsLastUsed.end());
-
- int lastDim = dimensionsLastUsed[dimensionsLastUsed.size()/2];
- int minOverlapSplitDimension = -1;
-
+
+ size_t lastDim = dimensionsLastUsed[dimensionsLastUsed.size()/2];
+ size_t minOverlapSplitDimension = tree->Bound().Dim();
+
// See if we can use a new dimension.
for(size_t i = lastDim + 1; i < axes.size(); i++) {
axes[i] = true;
@@ -298,8 +298,8 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
break;
}
}
- if(minOverlapSplitDimension == -1) {
- for(size_t i = 0; i < lastDim + 1; i++) {
+ if (minOverlapSplitDimension == tree->Bound().Dim()) {
+ for (size_t i = 0; i < lastDim + 1; i++) {
axes[i] = true;
for(size_t j = 0; j < tree->NumChildren(); j++)
axes[i] = axes[i] & tree->Child(j).SplitHistory().history[i];
@@ -307,15 +307,15 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
minOverlapSplitDimension = i;
break;
}
- }
+ }
}
-
+
bool minOverlapSplitUsesHi = false;
double bestScoreMinOverlapSplit = DBL_MAX;
double areaOfBestMinOverlapSplit = 0;
int bestIndexMinOverlapSplit = 0;
-
-
+
+
int bestOverlapIndexOnBestAxis = 0;
int bestAreaIndexOnBestAxis = 0;
bool tiedOnOverlap = false;
@@ -326,13 +326,13 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
double areaBestOverlapAxis = 0;
double overlapBestAreaAxis = 0;
double areaBestAreaAxis = 0;
-
- for (int j = 0; j < tree->Bound().Dim(); j++) {
+
+ for (size_t j = 0; j < tree->Bound().Dim(); j++) {
double axisScore = 0.0;
// We'll do Bound().Lo() now and use Bound().Hi() later.
std::vector<sortStruct> sorted(tree->NumChildren());
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->Children()[i]->Bound()[j].Lo();
sorted[i].n = i;
}
@@ -343,29 +343,29 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> areas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
std::vector<double> margins(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
std::vector<double> overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
- for (int i = 0; i < areas.size(); i++) {
+ for (size_t i = 0; i < areas.size(); i++) {
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++) {
- // The ith arrangement is obtained by placing the first tree->MinNumChildren() + i
+ for (size_t i = 0; i < areas.size(); i++) {
+ // The ith arrangement is obtained by placing the first tree->MinNumChildren() + i
// points in one rectangle and the rest in another. Then we calculate the three
// scores for that distribution.
- int cutOff = tree->MinNumChildren() + i;
+ size_t cutOff = tree->MinNumChildren() + i;
// We'll calculate the max and min in each dimension by hand to save time.
std::vector<double> maxG1(tree->Bound().Dim());
std::vector<double> minG1(maxG1.size());
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++) {
+ for (size_t k = 0; k < tree->Bound().Dim(); k++) {
minG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Lo();
maxG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Hi();
minG2[k] = tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Lo();
maxG2[k] = tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Hi();
- for (int l = 1; l < tree->NumChildren() - 1; l++) {
+ for (size_t l = 1; l < tree->NumChildren() - 1; l++) {
if (l < cutOff) {
if (tree->Children()[sorted[l].n]->Bound()[k].Lo() < minG1[k])
minG1[k] = tree->Children()[sorted[l].n]->Bound()[k].Lo();
@@ -381,7 +381,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++) {
+ for (size_t k = 0; k < maxG1.size(); k++) {
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
area2 *= maxG2[k] - minG2[k];
@@ -396,7 +396,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
bestAxis = j;
double bestOverlapIndexOnBestAxis = 0;
double bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++) {
+ for (size_t i = 1; i < areas.size(); i++) {
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) {
tiedOnOverlap = false;
bestAreaIndexOnBestAxis = i;
@@ -413,10 +413,10 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
}
}
-
+
// Track the minOverlapSplit data
if(minOverlapSplitDimension != -1 && j == minOverlapSplitDimension) {
- for(int i = 0; i < overlapedAreas.size(); i++) {
+ for(size_t i = 0; i < overlapedAreas.size(); i++) {
if(overlapedAreas[i] < bestScoreMinOverlapSplit) {
bestScoreMinOverlapSplit = overlapedAreas[i];
bestIndexMinOverlapSplit = i;
@@ -427,12 +427,12 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
//Now we do the same thing using Bound().Hi() and choose the best of the two.
- for (int j = 0; j < tree->Bound().Dim(); j++) {
+ for (size_t j = 0; j < tree->Bound().Dim(); j++) {
double axisScore = 0.0;
// We'll do Bound().Lo() now and use Bound().Hi() later.
std::vector<sortStruct> sorted(tree->NumChildren());
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->Children()[i]->Bound()[j].Hi();
sorted[i].n = i;
}
@@ -443,29 +443,29 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<double> areas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
std::vector<double> margins(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
std::vector<double> overlapedAreas(tree->MaxNumChildren() - 2 * tree->MinNumChildren() + 2);
- for (int i = 0; i < areas.size(); i++) {
+ for (size_t i = 0; i < areas.size(); i++) {
areas[i] = 0.0;
margins[i] = 0.0;
overlapedAreas[i] = 0.0;
}
- for (int i = 0; i < areas.size(); i++) {
- // The ith arrangement is obtained by placing the first tree->MinNumChildren() + i
+ for (size_t i = 0; i < areas.size(); i++) {
+ // The ith arrangement is obtained by placing the first tree->MinNumChildren() + i
// points in one rectangle and the rest in another. Then we calculate the three
// scores for that distribution.
- int cutOff = tree->MinNumChildren() + i;
+ size_t cutOff = tree->MinNumChildren() + i;
// We'll calculate the max and min in each dimension by hand to save time.
std::vector<double> maxG1(tree->Bound().Dim());
std::vector<double> minG1(maxG1.size());
std::vector<double> maxG2(maxG1.size());
std::vector<double> minG2(maxG1.size());
- for (int k = 0; k < tree->Bound().Dim(); k++) {
+ for (size_t k = 0; k < tree->Bound().Dim(); k++) {
minG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Lo();
maxG1[k] = tree->Children()[sorted[0].n]->Bound()[k].Hi();
minG2[k] = tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Lo();
maxG2[k] = tree->Children()[sorted[sorted.size() - 1].n]->Bound()[k].Hi();
- for (int l = 1; l < tree->NumChildren() - 1; l++) {
+ for (size_t l = 1; l < tree->NumChildren() - 1; l++) {
if (l < cutOff) {
if (tree->Children()[sorted[l].n]->Bound()[k].Lo() < minG1[k])
minG1[k] = tree->Children()[sorted[l].n]->Bound()[k].Lo();
@@ -481,7 +481,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
double area1 = 1.0, area2 = 1.0;
double oArea = 1.0;
- for (int k = 0; k < maxG1.size(); k++) {
+ for (size_t k = 0; k < maxG1.size(); k++) {
margins[i] += maxG1[k] - minG1[k] + maxG2[k] - minG2[k];
area1 *= maxG1[k] - minG1[k];
area2 *= maxG2[k] - minG2[k];
@@ -497,7 +497,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
lowIsBest = false;
double bestOverlapIndexOnBestAxis = 0;
double bestAreaIndexOnBestAxis = 0;
- for (int i = 1; i < areas.size(); i++) {
+ for (size_t i = 1; i < areas.size(); i++) {
if (overlapedAreas[i] < overlapedAreas[bestOverlapIndexOnBestAxis]) {
tiedOnOverlap = false;
bestAreaIndexOnBestAxis = i;
@@ -514,10 +514,10 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
}
}
-
+
// Track the minOverlapSplit data
if(minOverlapSplitDimension != -1 && j == minOverlapSplitDimension) {
- for(int i = 0; i < overlapedAreas.size(); i++) {
+ for(size_t i = 0; i < overlapedAreas.size(); i++) {
if(overlapedAreas[i] < bestScoreMinOverlapSplit) {
minOverlapSplitUsesHi = true;
bestScoreMinOverlapSplit = overlapedAreas[i];
@@ -530,12 +530,12 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
std::vector<sortStruct> sorted(tree->NumChildren());
if (lowIsBest) {
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->Children()[i]->Bound()[bestAxis].Lo();
sorted[i].n = i;
}
} else {
- for (int i = 0; i < sorted.size(); i++) {
+ for (size_t i = 0; i < sorted.size(); i++) {
sorted[i].d = tree->Children()[i]->Bound()[bestAxis].Hi();
sorted[i].n = i;
}
@@ -552,7 +552,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
bool useMinOverlapSplit = false;
if (tiedOnOverlap) {
if(overlapBestAreaAxis/areaBestAreaAxis < MAX_OVERLAP) {
- for (int i = 0; i < tree->NumChildren(); i++) {
+ for (size_t i = 0; i < tree->NumChildren(); i++) {
if (i < bestAreaIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, tree->Children()[sorted[i].n]);
else
@@ -562,7 +562,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
useMinOverlapSplit = true;
} else {
if(overlapBestOverlapAxis/areaBestOverlapAxis < MAX_OVERLAP) {
- for (int i = 0; i < tree->NumChildren(); i++) {
+ for (size_t i = 0; i < tree->NumChildren(); i++) {
if (i < bestOverlapIndexOnBestAxis + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, tree->Children()[sorted[i].n]);
else
@@ -571,7 +571,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
} else
useMinOverlapSplit = true;
}
-
+
// If the split was not good enough, then we try the minimal overlap split. If that fails, we create
// a "super node" (more accurately we resize this one to make it a super node).
if(useMinOverlapSplit) {
@@ -579,7 +579,7 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
if(minOverlapSplitDimension != -1 && bestScoreMinOverlapSplit / areaOfBestMinOverlapSplit < MAX_OVERLAP) {
std::vector<sortStruct> sorted2(tree->NumChildren());
if (minOverlapSplitUsesHi) {
- for (int i = 0; i < sorted2.size(); i++) {
+ for (size_t i = 0; i < sorted2.size(); i++) {
sorted2[i].d = tree->Children()[i]->Bound()[bestAxis].Hi();
sorted2[i].n = i;
}
@@ -590,31 +590,31 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
}
}
std::sort(sorted2.begin(), sorted2.end(), structComp);
- for (int i = 0; i < tree->NumChildren(); i++) {
+ for (size_t i = 0; i < tree->NumChildren(); i++) {
if (i < bestIndexMinOverlapSplit + tree->MinNumChildren())
InsertNodeIntoTree(treeOne, tree->Children()[sorted[i].n]);
else
InsertNodeIntoTree(treeTwo, tree->Children()[sorted[i].n]);
}
} else {
-
-
-
+
+
+
// We don't create a supernode that would be the only child of the root.
// (Note that if you did try to do so you would need to update the parent field on
// each child of this new node as creating a supernode causes the function to return
// before that is done.
-
+
// I thought commenting out the bellow would make the tree less efficient but would still work.
// It doesn't. I should look into that to see if there is another bug.
-
-
+
+
if(tree->Parent()->Parent() == NULL && tree->Parent()->NumChildren() == 1) {
// We make the root a supernode instead.
tree->Parent()->MaxNumChildren() *= 2;
tree->Parent()->Children().resize(tree->Parent()->MaxNumChildren()+1);
tree->Parent()->NumChildren() = tree->NumChildren();
- for(int i = 0; i < tree->NumChildren(); i++) {
+ for(size_t i = 0; i < tree->NumChildren(); i++) {
tree->Parent()->Children()[i] = tree->Children()[i];
}
delete treeOne;
@@ -623,75 +623,74 @@ bool XTreeSplit<DescentType, StatisticType, MatType>::SplitNonLeafNode(
tree->SoftDelete();
return false;
}
-
-
-
+
+
+
// If we don't have to worry about the root, we just enlarge this node.
tree->MaxNumChildren() *= 2;
tree->Children().resize(tree->MaxNumChildren()+1);
- for(int i = 0; i < tree->NumChildren(); i++)
+ for(size_t i = 0; i < tree->NumChildren(); i++)
tree->Child(i).Parent() = tree;
delete treeOne;
delete treeTwo;
-
- return false;
+
+ return false;
}
}
// Update the split history of each child.
-
+
treeOne->SplitHistory().history[bestAxis] = true;
treeOne->SplitHistory().lastDimension = bestAxis;
treeTwo->SplitHistory().history[bestAxis] = true;
treeTwo->SplitHistory().lastDimension = bestAxis;
-
-
-
-
-
-
-
+
+
+
+
+
+
+
//Remove this node and insert treeOne and treeTwo
RectangleTree<XTreeSplit<DescentType, StatisticType, MatType>, DescentType, StatisticType, MatType>* par = tree->Parent();
- int index = 0;
- for (int i = 0; i < par->NumChildren(); i++) {
+ size_t index = 0;
+ for (size_t i = 0; i < par->NumChildren(); i++) {
if (par->Children()[i] == tree) {
index = i;
break;
}
}
-
+
par->Children()[index] = treeOne;
par->Children()[par->NumChildren()++] = treeTwo;
// we only add one at a time, so we should only need to test for equality
// just in case, we use an assert.
-
+
if(!(par->NumChildren() <= par->MaxNumChildren()+1))
std::cout<<"error " << par->NumChildren() << ", "<<par->MaxNumChildren()+1<<std::endl;
assert(par->NumChildren() <= par->MaxNumChildren()+1);
if (par->NumChildren() == par->MaxNumChildren()+1) {
SplitNonLeafNode(par, relevels);
}
-
- // We have to update the children of each of these new nodes so that they record the
+
+ // We have to update the children of each of these new nodes so that they record the
// correct parent.
- for (int i = 0; i < treeOne->NumChildren(); i++) {
+ for (size_t i = 0; i < treeOne->NumChildren(); i++) {
treeOne->Children()[i]->Parent() = treeOne;
}
- for (int i = 0; i < treeTwo->NumChildren(); i++) {
+ for (size_t i = 0; i < treeTwo->NumChildren(); i++) {
treeTwo->Children()[i]->Parent() = treeTwo;
}
-
-
+
assert(treeOne->Parent()->NumChildren() <= treeOne->Parent()->MaxNumChildren());
assert(treeOne->Parent()->NumChildren() >= treeOne->Parent()->MinNumChildren());
assert(treeTwo->Parent()->NumChildren() <= treeTwo->Parent()->MaxNumChildren());
assert(treeTwo->Parent()->NumChildren() >= treeTwo->Parent()->MinNumChildren());
tree->SoftDelete();
-
+
return false;
}
@@ -712,4 +711,4 @@ void XTreeSplit<DescentType, StatisticType, MatType>::InsertNodeIntoTree(
}; // namespace tree
}; // namespace mlpack
-#endif
+#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git
More information about the debian-science-commits
mailing list