Minor style fixes.
This commit is contained in:
@@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit)
|
||||
// Initialize constants required for the test.
|
||||
const size_t numRows = 500;
|
||||
const size_t numCols = 1000;
|
||||
// Calculation accuracy
|
||||
// Calculation accuracy.
|
||||
const double precision = 1e-15;
|
||||
|
||||
// Make a random dataset and the root object.
|
||||
@@ -106,50 +106,52 @@ BOOST_AUTO_TEST_CASE(CosineNodeCosineSplit)
|
||||
cosines(k) = arma::norm_dot(data.col(rightIndices[j]), splitPoint);
|
||||
|
||||
// Check if the columns assigned to the children agree with the splitting
|
||||
// condition.
|
||||
// Due to miscalculations cosineMax calculated at CosineNodeSplit
|
||||
// may differ from cosineMax below
|
||||
// condition. Due to miscalculations cosineMax calculated by
|
||||
// CosineNodeSplit may differ from cosineMax below, so we have to handle
|
||||
// minor differences.
|
||||
double cosineMax = arma::max(cosines % (cosines < 1.0 + precision));
|
||||
double cosineMin = arma::min(cosines);
|
||||
// If max(cosines) is close to 1.0 cosineMax and cosineMax2 may
|
||||
// differ significantly
|
||||
// differ significantly.
|
||||
double cosineMax2 = arma::max(cosines % (cosines < 1.0 - precision));
|
||||
|
||||
|
||||
if(std::fabs(cosineMax - cosineMax2) < precision)
|
||||
if (std::fabs(cosineMax - cosineMax2) < precision)
|
||||
{
|
||||
// Check with some precision
|
||||
// Check with some precision.
|
||||
for (i = 0; i < leftIndices.size(); i++)
|
||||
BOOST_REQUIRE_LT(cosineMax - cosines(i), cosines(i) - cosineMin + precision);
|
||||
BOOST_REQUIRE_LT(cosineMax - cosines(i),
|
||||
cosines(i) - cosineMin + precision);
|
||||
|
||||
for (j = 0, k = i; j < rightIndices.size(); j++, k++)
|
||||
BOOST_REQUIRE_GT(cosineMax - cosines(k), cosines(k) - cosineMin - precision);
|
||||
BOOST_REQUIRE_GT(cosineMax - cosines(k),
|
||||
cosines(k) - cosineMin - precision);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t numMax1Errors = 0;
|
||||
size_t numMax2Errors = 0;
|
||||
|
||||
// Find errors for cosineMax
|
||||
// Find errors for cosineMax.
|
||||
for (i = 0; i < leftIndices.size(); i++)
|
||||
if(cosineMax - cosines(i) >= cosines(i) - cosineMin + precision)
|
||||
if (cosineMax - cosines(i) >= cosines(i) - cosineMin + precision)
|
||||
numMax1Errors++;
|
||||
|
||||
for (j = 0, k = i; j < rightIndices.size(); j++, k++)
|
||||
if(cosineMax - cosines(k) <= cosines(k) - cosineMin - precision)
|
||||
if (cosineMax - cosines(k) <= cosines(k) - cosineMin - precision)
|
||||
numMax1Errors++;
|
||||
|
||||
// Find errors for cosineMax2
|
||||
// Find errors for cosineMax2.
|
||||
for (i = 0; i < leftIndices.size(); i++)
|
||||
if(cosineMax2 - cosines(i) >= cosines(i) - cosineMin + precision)
|
||||
if (cosineMax2 - cosines(i) >= cosines(i) - cosineMin + precision)
|
||||
numMax2Errors++;
|
||||
|
||||
for (j = 0, k = i; j < rightIndices.size(); j++, k++)
|
||||
if(cosineMax2 - cosines(k) <= cosines(k) - cosineMin - precision)
|
||||
if (cosineMax2 - cosines(k) <= cosines(k) - cosineMin - precision)
|
||||
numMax2Errors++;
|
||||
|
||||
// One of the maximum cosine values should be correct
|
||||
BOOST_REQUIRE_EQUAL(std::min(numMax1Errors,numMax2Errors),0);
|
||||
// One of the maximum cosine values should be correct
|
||||
BOOST_REQUIRE_EQUAL(std::min(numMax1Errors, numMax2Errors), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user