[mlpack-svn] r17065 - mlpack/trunk/src/mlpack/core/tree/rectangle_tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Aug 18 15:18:50 EDT 2014
Author: rcurtin
Date: Mon Aug 18 15:18:50 2014
New Revision: 17065
Log:
Clarify some difficult ternary operator operations (the compiler should give
something that is resultantly the same code anyway). Also, use the new
HRectBound::Volume() function to simplify some later calculations. Testing
seems to indicate no noticeable slowdown or speedup.
Modified:
mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
Modified: mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp (original)
+++ mlpack/trunk/src/mlpack/core/tree/rectangle_tree/r_tree_split_impl.hpp Mon Aug 18 15:18:50 2014
@@ -226,10 +226,11 @@
double score = 1.0;
for (int k = 0; k < tree.Bound().Dim(); k++)
{
- score *= std::max(tree.Children()[i]->Bound()[k].Hi(),
- tree.Children()[j]->Bound()[k].Hi()) -
- std::min(tree.Children()[i]->Bound()[k].Lo(),
- tree.Children()[j]->Bound()[k].Lo());
+ const double hiMax = std::max(tree.Children()[i]->Bound()[k].Hi(),
+ tree.Children()[j]->Bound()[k].Hi());
+ const double loMin = std::min(tree.Children()[i]->Bound()[k].Lo(),
+ tree.Children()[j]->Bound()[k].Lo());
+ score *= (hiMax - loMin);
}
if (score > worstPairScore)
@@ -307,30 +308,20 @@
// rectangle.
// First, calculate the starting volume.
- double volOne = 1.0;
- double volTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
- {
- volOne *= treeOne->Bound()[i].Width();
- volTwo *= treeTwo->Bound()[i].Width();
- }
+ const double volOne = treeOne->Bound().Volume();
+ const double volTwo = treeTwo->Bound().Volume();
// 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++)
{
- double newVolOne = 1.0;
- double newVolTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
- {
- double c = oldTree->LocalDataset().col(index)[i];
- newVolOne *= treeOne->Bound()[i].Contains(c) ?
- treeOne->Bound()[i].Width() : (c < treeOne->Bound()[i].Lo() ?
- (treeOne->Bound()[i].Hi() - c) : (c - treeOne->Bound()[i].Lo()));
- newVolTwo *= treeTwo->Bound()[i].Contains(c) ?
- treeTwo->Bound()[i].Width() : (c < treeTwo->Bound()[i].Lo() ?
- (treeTwo->Bound()[i].Hi() - c) : (c - treeTwo->Bound()[i].Lo()));
- }
+ HRectBound<> newBoundOne = treeOne->Bound();
+ newBoundOne |= oldTree->LocalDataset().col(index);
+ const double newVolOne = newBoundOne.Volume();
+
+ HRectBound<> newBoundTwo = treeTwo->Bound();
+ newBoundTwo |= oldTree->LocalDataset().col(index);
+ const double newVolTwo = newBoundTwo.Volume();
// Choose the rectangle that requires the lesser increase in volume.
if ((newVolOne - volOne) < (newVolTwo - volTwo))
@@ -450,35 +441,18 @@
// Calculate the increase in volume for assigning this node to each of the
// new rectangles.
- double volOne = 1.0;
- double volTwo = 1.0;
- for (int i = 0; i < oldTree->Bound().Dim(); i++)
- {
- volOne *= treeOne->Bound()[i].Width();
- volTwo *= treeTwo->Bound()[i].Width();
- }
+ const double volOne = treeOne->Bound().Volume();
+ const double volTwo = treeTwo->Bound().Volume();
for (int index = 0; index < end; index++)
{
- double newVolOne = 1.0;
- double newVolTwo = 1.0;
- for (int 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.
- math::Range range = oldTree->Children()[index]->Bound()[i];
- newVolOne *= treeOne->Bound()[i].Contains(range) ?
- treeOne->Bound()[i].Width() : (range.Contains(treeOne->Bound()[i]) ?
- range.Width() : (range.Lo() < treeOne->Bound()[i].Lo() ?
- (treeOne->Bound()[i].Hi() - range.Lo()) : (range.Hi() -
- treeOne->Bound()[i].Lo())));
-
- newVolTwo *= treeTwo->Bound()[i].Contains(range) ?
- treeTwo->Bound()[i].Width() : (range.Contains(treeTwo->Bound()[i]) ?
- range.Width() : (range.Lo() < treeTwo->Bound()[i].Lo() ?
- (treeTwo->Bound()[i].Hi() - range.Lo()) : (range.Hi() -
- treeTwo->Bound()[i].Lo())));
- }
+ HRectBound<> newBoundOne = treeOne->Bound();
+ newBoundOne |= oldTree->Children()[index]->Bound();
+ const double newVolOne = newBoundOne.Volume();
+
+ HRectBound<> newBoundTwo = treeTwo->Bound();
+ newBoundTwo |= oldTree->Children()[index]->Bound();
+ const double newVolTwo = newBoundTwo.Volume();
// Choose the rectangle that requires the lesser increase in volume.
if ((newVolOne - volOne) < (newVolTwo - volTwo))
More information about the mlpack-svn
mailing list