[mlpack-svn] r10878 - mlpack/trunk/src/mlpack/core/tree
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sat Dec 17 02:07:30 EST 2011
Author: rcurtin
Date: 2011-12-17 02:07:30 -0500 (Sat, 17 Dec 2011)
New Revision: 10878
Modified:
mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
Log:
Fix use of uninitialized variables.
Modified: mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp 2011-12-17 07:07:12 UTC (rev 10877)
+++ mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp 2011-12-17 07:07:30 UTC (rev 10878)
@@ -44,8 +44,8 @@
box_(other.box())
{
bounds_ = new math::Range[other.Dim()];
- for (size_t i = 0; i < dim_; i++)
- bounds_[i] |= other[i];
+ for (size_t i = 0; i < dim_; i++)
+ bounds_[i] |= other[i];
}
/***
@@ -129,30 +129,36 @@
{
arma::vec point2 = point;
double totalMin = 0;
- //Create the mirrored images. The minimum distance from the bound to a
- //mirrored point is the minimum periodic distance.
+ // Create the mirrored images. The minimum distance from the bound to a
+ // mirrored point is the minimum periodic distance.
arma::vec box = box_;
- for (int i = 0; i < dim_; i++){
+ for (int i = 0; i < dim_; i++)
+ {
point2 = point;
double min = 100000000;
- //Mod the point within the box
+ // Mod the point within the box.
- if (box[i] < 0){
+ if (box[i] < 0)
+ {
box[i] = abs(box[i]);
}
- if (box[i] != 0){
- if (abs(point[i]) > box[i]) {
+ if (box[i] != 0)
+ {
+ if (abs(point[i]) > box[i])
+ {
point2[i] = fmod(point2[i],box[i]);
}
}
- for (int k = 0; k < 3; k++){
+ for (int k = 0; k < 3; k++)
+ {
arma::vec point3 = point2;
- if (k == 1)
- point3[i] += box[i];
- else if (k == 2)
- point3[i] -= box[i];
+ if (k == 1)
+ point3[i] += box[i];
+ else if (k == 2)
+ point3[i] -= box[i];
+
double tempMin;
double sum = 0;
@@ -160,7 +166,7 @@
lower = bounds_[i].Lo() - point3[i];
higher = point3[i] - bounds_[i].Hi();
- sum += pow((lower + fabs(lower)) +
+ sum += pow((lower + fabs(lower)) +
(higher + fabs(higher)), (double) t_pow);
tempMin = pow(sum, 2.0 / (double) t_pow) / 4.0;
@@ -179,42 +185,40 @@
*
* Example: bound1.MinDistance(other) for minimum squared distance.
*/
-
template<int t_pow>
double PeriodicHRectBound<t_pow>::MinDistance(
const PeriodicHRectBound& other) const
{
double totalMin = 0;
- //Create the mirrored images. The minimum distance from the bound to a
- //mirrored point is the minimum periodic distance.
+ // Create the mirrored images. The minimum distance from the bound to a
+ // mirrored point is the minimum periodic distance.
arma::vec box = box_;
PeriodicHRectBound<2> a(other);
-
for (int i = 0; i < dim_; i++)
{
- double min = 100000000;
- if (box[i] < 0)
+ double min = DBL_MAX;
+ if (box[i] < 0)
box[i] = abs(box[i]);
-
- if (box[i] != 0)
+
+ if (box[i] != 0)
{
- if (abs(other[i].Lo()) > box[i])
+ if (abs(other[i].Lo()) > box[i])
a[i].Lo() = fmod(a[i].Lo(),box[i]);
-
- if (abs(other[i].Hi()) > box[i])
- a[i].Hi() = fmod(a[i].Hi(),box[i]);
+
+ if (abs(other[i].Hi()) > box[i])
+ a[i].Hi() = fmod(a[i].Hi(),box[i]);
}
for (int k = 0; k < 3; k++)
{
PeriodicHRectBound<2> b = a;
- if (k == 1)
+ if (k == 1)
{
b[i].Lo() += box[i];
b[i].Hi() += box[i];
}
- else if (k == 2)
+ else if (k == 2)
{
b[i].Lo() -= box[i];
b[i].Hi() -= box[i];
@@ -228,32 +232,32 @@
double lower, higher, lowerLower, lowerHigher, higherLower,
higherHigher;
- //If the bound corsses over the box, split ito two seperate bounds and
- //find thhe minimum distance between them.
- if( b[i].Hi() < b[i].Lo())
+ // If the bound crosses over the box, split ito two seperate bounds and
+ // find the minimum distance between them.
+ if (b[i].Hi() < b[i].Lo())
{
PeriodicHRectBound<2> d(b);
PeriodicHRectBound<2> c(b);
d[i].Lo() = 0;
c[i].Hi() = box[i];
- if (k == 1)
+ if (k == 1)
{
d[i].Lo() += box[i];
c[i].Hi() += box[i];
}
- else if (k == 2)
+ else if (k == 2)
{
d[i].Lo() -= box[i];
c[i].Hi() -= box[i];
}
+
d[i].Hi() = b[i].Hi();
c[i].Lo() = b[i].Lo();
lowerLower = d[i].Lo() - bounds_[i].Hi();
higherLower = bounds_[i].Lo() - d[i].Hi();
-
lowerHigher = c[i].Lo() - bounds_[i].Hi();
higherHigher = bounds_[i].Lo() - c[i].Hi();
@@ -263,23 +267,23 @@
sumHigher += pow((lowerHigher + fabs(lowerHigher)) +
(higherHigher + fabs(higherHigher)), (double) t_pow);
- if (sumLower > sumHigher)
- tempMin = pow(sumHigher, 2.0 / (double) t_pow) / 4.0;
- else
- tempMin = pow(sumLower, 2.0 / (double) t_pow) / 4.0;
+ if (sumLower > sumHigher)
+ tempMin = pow(sumHigher, 2.0 / (double) t_pow) / 4.0;
+ else
+ tempMin = pow(sumLower, 2.0 / (double) t_pow) / 4.0;
}
- else {
+ else
+ {
lower = b[i].Lo() - bounds_[i].Hi();
higher = bounds_[i].Lo() - b[i].Hi();
// We invoke the following:
// x + fabs(x) = max(x * 2, 0)
// (x * 2)^2 / 4 = x^2
- sum += pow((lower + fabs(lower)) +
+ sum += pow((lower + fabs(lower)) +
(higher + fabs(higher)), (double) t_pow);
tempMin = pow(sum, 2.0 / (double) t_pow) / 4.0;
}
-
if (tempMin < min)
min = tempMin;
}
@@ -304,24 +308,24 @@
{
point2 = point;
double max = 0;
- //Mod the point within the box
+ // Mod the point within the box.
- if (box[i] < 0)
+ if (box[i] < 0)
box[i] = abs(box[i]);
-
- if (box[i] != 0)
- if (abs(point[i]) > box[i])
- point2[i] = fmod(point2[i],box[i]);
-
+
+ if (box[i] != 0)
+ if (abs(point[i]) > box[i])
+ point2[i] = fmod(point2[i],box[i]);
+
for (int k = 0; k < 3; k++)
{
arma::vec point3 = point2;
-
- if (k == 1)
- point3[i] += box[i];
- else if (k == 2)
+
+ if (k == 1)
+ point3[i] += box[i];
+ else if (k == 2)
point3[i] -= box[i];
-
+
double tempMax;
double sum = 0;
@@ -358,27 +362,27 @@
for (int i = 0; i < dim_; i++)
{
double max = 0;
- if (box[i] < 0)
+ if (box[i] < 0)
box[i] = abs(box[i]);
-
- if (box[i] != 0)
+
+ if (box[i] != 0)
{
- if (abs(other[i].Lo()) > box[i])
+ if (abs(other[i].Lo()) > box[i])
a[i].Lo() = fmod(a[i].Lo(),box[i]);
-
- if (abs(other[i].Hi()) > box[i])
- a[i].Hi() = fmod(a[i].Hi(),box[i]);
+
+ if (abs(other[i].Hi()) > box[i])
+ a[i].Hi() = fmod(a[i].Hi(),box[i]);
}
for (int k = 0; k < 3; k++)
{
PeriodicHRectBound<2> b = a;
- if (k == 1)
+ if (k == 1)
{
b[i].Lo() += box[i];
b[i].Hi() += box[i];
}
- else if (k == 2)
+ else if (k == 2)
{
b[i].Lo() -= box[i];
b[i].Hi() -= box[i];
@@ -387,28 +391,29 @@
double sum = 0;
double tempMax;
- double sumLower, sumHigher;
+ double sumLower = 0, sumHigher = 0;
- //If the bound corsses over the box, split ito two seperate bounds and
- //find thhe minimum distance between them.
- if( b[i].Hi() < b[i].Lo())
+ // If the bound corsses over the box, split ito two seperate bounds and
+ // find thhe minimum distance between them.
+ if (b[i].Hi() < b[i].Lo())
{
PeriodicHRectBound<2> d(b);
PeriodicHRectBound<2> c(b);
a[i].Lo() = 0;
c[i].Hi() = box[i];
- if (k == 1)
+ if (k == 1)
{
d[i].Lo() += box[i];
c[i].Hi() += box[i];
}
- else if (k == 2)
+ else if (k == 2)
{
d[i].Lo() -= box[i];
c[i].Hi() -= box[i];
}
+
d[i].Hi() = b[i].Hi();
c[i].Lo() = b[i].Lo();
@@ -421,12 +426,12 @@
sumLower += pow(vLower, (double) t_pow);
sumHigher += pow(vHigher, (double) t_pow);
- if (sumLower > sumHigher)
+ if (sumLower > sumHigher)
tempMax = pow(sumHigher, 2.0 / (double) t_pow) / 4.0;
- else
- tempMax = pow(sumLower, 2.0 / (double) t_pow) / 4.0;
+ else
+ tempMax = pow(sumLower, 2.0 / (double) t_pow) / 4.0;
}
- else
+ else
{
double v = fabs(std::max(b.bounds_[i].Hi() - bounds_[i].Lo(),
bounds_[i].Hi() - b.bounds_[i].Lo()));
@@ -498,7 +503,7 @@
v1 = other.bounds_[d].Lo() - bounds_[d].Hi();
v2 = bounds_[d].Lo() - other.bounds_[d].Hi();
// One of v1 or v2 is negative.
- if(v1 >= v2)
+ if (v1 >= v2)
{
v_hi = -v2; // Make it nonnegative.
v_lo = (v1 > 0) ? v1 : 0; // Force to be 0 if negative.
More information about the mlpack-svn
mailing list