[mlpack-svn] r10855 - in mlpack/trunk/src/mlpack: core/tree methods/gmm tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Dec 16 12:38:40 EST 2011
Author: vlad321
Date: 2011-12-16 12:38:39 -0500 (Fri, 16 Dec 2011)
New Revision: 10855
Modified:
mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
mlpack/trunk/src/mlpack/tests/allkfn_test.cpp
mlpack/trunk/src/mlpack/tests/allknn_test.cpp
mlpack/trunk/src/mlpack/tests/aug_lagrangian_test.cpp
mlpack/trunk/src/mlpack/tests/cli_test.cpp
mlpack/trunk/src/mlpack/tests/emst_test.cpp
mlpack/trunk/src/mlpack/tests/gmm_test.cpp
mlpack/trunk/src/mlpack/tests/kernel_test.cpp
mlpack/trunk/src/mlpack/tests/lars_test.cpp
mlpack/trunk/src/mlpack/tests/lbfgs_test.cpp
mlpack/trunk/src/mlpack/tests/load_save_test.cpp
mlpack/trunk/src/mlpack/tests/nca_test.cpp
mlpack/trunk/src/mlpack/tests/radical_test.cpp
mlpack/trunk/src/mlpack/tests/range_search_test.cpp
mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp
mlpack/trunk/src/mlpack/tests/sort_policy_test.cpp
mlpack/trunk/src/mlpack/tests/tree_test.cpp
mlpack/trunk/src/mlpack/tests/union_find_test.cpp
Log:
Formatting for the entire /tests.
Modified: mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/core/tree/periodichrectbound_impl.hpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -39,9 +39,14 @@
* Copy constructor.
*/
template<int t_pow>
-PeriodicHRectBound<t_pow>::PeriodicHRectBound(const PeriodicHRectBound& other)
+PeriodicHRectBound<t_pow>::PeriodicHRectBound(const PeriodicHRectBound& other) :
+ dim_(other.Dim()),
+ box_(other.box())
{
- // not done yet
+ bounds_ = new math::Range[other.Dim()];
+ for (size_t i = 0; i < dim_; i++) {
+ bounds_[i] |= other[i];
+ }
}
/***
@@ -117,7 +122,7 @@
/**
* Calculates minimum bound-to-point squared distance.
- */
+ *
template<int t_pow>
double PeriodicHRectBound<t_pow>::MinDistance(const arma::vec& point) const
{
@@ -139,13 +144,65 @@
}
return pow(sum, 2.0 / (double) t_pow);
+}*/
+
+template<int t_pow>
+double PeriodicHRectBound<t_pow>::MinDistance(const arma::vec& point) const
+{
+ arma::vec point2 = point;
+ double total_min = 0;
+ //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++){
+ point2 = point;
+ double min = 100000000;
+ //Mod the point within the box
+
+ 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]);
+ }
+ }
+
+ 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];
+ }
+
+ double temp_min;
+ double sum = 0;
+
+ double lower, higher;
+ lower = bounds_[i].Lo() - point3[i];
+ higher = point3[i] - bounds_[i].Hi();
+
+ sum += pow((lower + fabs(lower)) + (higher + fabs(higher)), (double) t_pow);
+ temp_min = pow(sum, 2.0 / (double) t_pow) / 4.0;
+
+ if( temp_min < min)
+ min = temp_min;
+ }
+
+ total_min += min;
+ }
+ return total_min;
+
}
/**
* Calculates minimum bound-to-bound squared distance.
*
* Example: bound1.MinDistance(other) for minimum squared distance.
- */
+ *
+
template<int t_pow>
double PeriodicHRectBound<t_pow>::MinDistance(
const PeriodicHRectBound& other) const
@@ -175,42 +232,173 @@
}
return pow(sum, 2.0 / (double) t_pow) / 4.0;
+}*/
+
+template<int t_pow>
+double PeriodicHRectBound<t_pow>::MinDistance(
+ const PeriodicHRectBound& other) const
+{
+ double total_min = 0;
+ //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) {
+ box[i] = abs(box[i]);
+ }
+ if (box[i] != 0) {
+ 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]);
+ }
+ }
+
+ for (int k = 0; k < 3; k++){
+ PeriodicHRectBound<2> b = a;
+ if (k == 1) {
+ b[i].Lo() += box[i];
+ b[i].Hi() += box[i];
+ }
+ else if (k == 2) {
+ b[i].Lo() -= box[i];
+ b[i].Hi() -= box[i];
+ }
+
+ double sum = 0;
+ double temp_min;
+ double sum_lower = 0;
+ double sum_higher = 0;
+// math::Range mbound = bounds_[i];
+// math::Range obound = b[i];
+
+ double lower, higher, lower_lower, lower_higher, higher_lower,
+ higher_higher;
+
+ //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> a(b);
+ PeriodicHRectBound<2> c(b);
+ double upper = b[i].Hi();
+ double low = b[i].Lo();
+ a[i].Lo() = 0;
+ c[i].Hi() = box[i];
+
+ if (k == 1) {
+ a[i].Lo() += box[i];
+ c[i].Hi() += box[i];
+ }
+ else if (k == 2) {
+ a[i].Lo() -= box[i];
+ c[i].Hi() -= box[i];
+ }
+ a[i].Hi() = b[i].Hi();
+ c[i].Lo() = b[i].Lo();
+
+ lower_lower = a[i].Lo() - bounds_[i].Hi();
+ higher_lower = bounds_[i].Lo() - a[i].Hi();
+
+
+ lower_higher = c[i].Lo() - bounds_[i].Hi();
+ higher_higher = bounds_[i].Lo() - c[i].Hi();
+
+ sum_lower += pow((lower_lower + fabs(lower_lower)) +
+ (higher_lower + fabs(higher_lower)), (double) t_pow);
+
+ sum_higher += pow((lower_higher + fabs(lower_higher)) +
+ (higher_higher + fabs(higher_higher)), (double) t_pow);
+
+ if (sum_lower > sum_higher) {
+ temp_min = pow(sum_higher, 2.0 / (double) t_pow) / 4.0;
+ }
+ else {
+ temp_min = pow(sum_lower, 2.0 / (double) t_pow) / 4.0;
+ }
+
+ }
+ 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)) + (higher + fabs(higher)), (double) t_pow);
+ temp_min = pow(sum, 2.0 / (double) t_pow) / 4.0;
+ }
+
+
+ if (temp_min < min)
+ min = temp_min;
+ }
+ total_min += min;
+ }
+ return total_min;
}
+
/**
* Calculates maximum bound-to-point squared distance.
*/
template<int t_pow>
double PeriodicHRectBound<t_pow>::MaxDistance(const arma::vec& point) const
{
- double sum = 0;
+ arma::vec point2 = point;
+ double total_max = 0;
+ //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++){
+ point2 = point;
+ double max = 0;
+ //Mod the point within the box
- for (size_t d = 0; d < dim_; d++)
- {
- double b = point[d];
- double v = box_[d] / 2.0;
- double ah, al;
+ 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]);
+ }
+ }
- ah = bounds_[d].Hi() - b;
- ah = ah - floor(ah / box_[d]) * box_[d];
+ 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 (ah < v)
- {
- v = ah;
- }
- else
- {
- al = bounds_[d].Lo() - b;
- al = al - floor(al / box_[d]) * box_[d];
+ double temp_max;
+ double sum = 0;
- if (al > v)
- v = (2 * v) - al;
+ double lower, higher;
+ lower = bounds_[i].Lo() - point3[i];
+ higher = point3[i] - bounds_[i].Hi();
+
+ double v = fabs(std::max(point[i] - bounds_[i].Lo(),
+ bounds_[i].Hi() - point[i]));
+ sum += pow(v, (double) t_pow);
+
+ //sum += pow((lower + fabs(lower)) + (higher + fabs(higher)),
+ // (double) t_pow);
+ temp_max = pow(sum, 2.0 / (double) t_pow) / 4.0;
+
+ if (temp_max > max)
+ max = temp_max;
}
- sum += pow(fabs(v), (double) t_pow);
+ total_max += max;
}
+ return total_max;
- return pow(sum, 2.0 / (double) t_pow);
}
/**
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -45,7 +45,7 @@
Timer::Stop("em");
////// OUTPUT RESULTS //////
- SaveRestoreUtility save;
+ mlpack::utilities::SaveRestoreUtility save;
save.SaveParameter(gmm.Gaussians(), "gaussians");
save.SaveParameter(gmm.Dimensionality(), "dimensionality");
save.SaveParameter(trans(gmm.Weights()), "weights");
Modified: mlpack/trunk/src/mlpack/tests/allkfn_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/allkfn_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/allkfn_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -20,7 +20,7 @@
* is in one dimension for simplicity -- the correct functionality of distance
* functions is not tested here.
*/
-BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
+BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest)
{
// Set up our data.
arma::mat data(1, 11);
@@ -41,17 +41,17 @@
for (int i = 0; i < 3; i++)
{
AllkFN* allkfn;
- arma::mat data_mutable = data;
+ arma::mat dataMutable = data;
switch (i)
{
case 0: // Use the dual-tree method.
- allkfn = new AllkFN(data_mutable, false, false, 1);
+ allkfn = new AllkFN(dataMutable, false, false, 1);
break;
case 1: // Use the single-tree method.
- allkfn = new AllkFN(data_mutable, false, true, 1);
+ allkfn = new AllkFN(dataMutable, false, true, 1);
break;
case 2: // Use the naive method.
- allkfn = new AllkFN(data_mutable, true);
+ allkfn = new AllkFN(dataMutable, true);
break;
}
@@ -318,36 +318,36 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(dual_tree_vs_naive_1)
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive1)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with.
- arma::mat dual_query(data_for_tree_);
- arma::mat dual_references(data_for_tree_);
- arma::mat naive_query(data_for_tree_);
- arma::mat naive_references(data_for_tree_);
+ arma::mat dualQuery(dataForTree_);
+ arma::mat dualReferences(dataForTree_);
+ arma::mat naiveQuery(dataForTree_);
+ arma::mat naiveReferences(dataForTree_);
- AllkFN allkfn_(dual_query, dual_references);
+ AllkFN allkfn_(dualQuery, dualReferences);
- AllkFN naive_(naive_query, naive_references, true);
+ AllkFN naive_(naiveQuery, naiveReferences, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allkfn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allkfn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
@@ -357,35 +357,35 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(dual_tree_vs_naive_2)
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive2)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
// Code duplication: also bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with.
- arma::mat dual_references(data_for_tree_);
- arma::mat naive_references(data_for_tree_);
+ arma::mat dualReferences(dataForTree_);
+ arma::mat naiveReferences(dataForTree_);
- AllkFN allkfn_(dual_references);
+ AllkFN allkfn_(dualReferences);
- AllkFN naive_(naive_references, true);
+ AllkFN naive_(naiveReferences, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allkfn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allkfn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
@@ -395,34 +395,34 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(single_tree_vs_naive)
+BOOST_AUTO_TEST_CASE(SingleTreeVsNaive)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
// Code duplication: also bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
- arma::mat single_query(data_for_tree_);
- arma::mat naive_query(data_for_tree_);
+ arma::mat single_query(dataForTree_);
+ arma::mat naiveQuery(dataForTree_);
AllkFN allkfn_(single_query, false, true);
- AllkFN naive_(naive_query, true);
+ AllkFN naive_(naiveQuery, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allkfn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allkfn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
Modified: mlpack/trunk/src/mlpack/tests/allknn_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/allknn_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/allknn_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -20,7 +20,7 @@
* in one dimension for simplicity -- the correct functionality of distance
* functions is not tested here.
*/
-BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
+BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest)
{
// Set up our data.
arma::mat data(1, 11);
@@ -41,17 +41,17 @@
for (int i = 0; i < 3; i++)
{
AllkNN* allknn;
- arma::mat data_mutable = data;
+ arma::mat dataMutable = data;
switch (i)
{
case 0: // Use the dual-tree method.
- allknn = new AllkNN(data_mutable, false, false, 1);
+ allknn = new AllkNN(dataMutable, false, false, 1);
break;
case 1: // Use the single-tree method.
- allknn = new AllkNN(data_mutable, false, true, 1);
+ allknn = new AllkNN(dataMutable, false, true, 1);
break;
case 2: // Use the naive method.
- allknn = new AllkNN(data_mutable, true);
+ allknn = new AllkNN(dataMutable, true);
break;
}
@@ -318,36 +318,36 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(dual_tree_vs_naive_1)
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive1)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with.
- arma::mat dual_query(data_for_tree_);
- arma::mat dual_references(data_for_tree_);
- arma::mat naive_query(data_for_tree_);
- arma::mat naive_references(data_for_tree_);
+ arma::mat dualQuery(dataForTree_);
+ arma::mat dual_references(dataForTree_);
+ arma::mat naiveQuery(dataForTree_);
+ arma::mat naive_references(dataForTree_);
- AllkNN allknn_(dual_query, dual_references);
+ AllkNN allknn_(dualQuery, dual_references);
- AllkNN naive_(naive_query, naive_references, true);
+ AllkNN naive_(naiveQuery, naive_references, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allknn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allknn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
@@ -357,36 +357,36 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(dual_tree_vs_naive_2)
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive2)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
// Code duplication: also bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
- arma::mat dual_query(data_for_tree_);
- arma::mat naive_query(data_for_tree_);
+ arma::mat dualQuery(dataForTree_);
+ arma::mat naiveQuery(dataForTree_);
- AllkNN allknn_(dual_query);
+ AllkNN allknn_(dualQuery);
// Set naive mode.
- AllkNN naive_(naive_query, true);
+ AllkNN naive_(naiveQuery, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allknn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allknn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
@@ -396,36 +396,36 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(single_tree_vs_naive)
+BOOST_AUTO_TEST_CASE(SingleTreeVsNaive)
{
- arma::mat data_for_tree_;
+ arma::mat dataForTree_;
// Hard-coded filename: bad!
// Code duplication: also bad!
- if (!data::Load("test_data_3_1000.csv", data_for_tree_))
+ if (!data::Load("test_data_3_1000.csv", dataForTree_))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
- arma::mat single_query(data_for_tree_);
- arma::mat naive_query(data_for_tree_);
+ arma::mat singleQuery(dataForTree_);
+ arma::mat naiveQuery(dataForTree_);
- AllkNN allknn_(single_query, false, true);
+ AllkNN allknn_(singleQuery, false, true);
// Set up computation for naive mode.
- AllkNN naive_(naive_query, true);
+ AllkNN naive_(naiveQuery, true);
- arma::Mat<size_t> resulting_neighbors_tree;
- arma::mat distances_tree;
- allknn_.Search(15, resulting_neighbors_tree, distances_tree);
+ arma::Mat<size_t> resultingNeighborsTree;
+ arma::mat distancesTree;
+ allknn_.Search(15, resultingNeighborsTree, distancesTree);
- arma::Mat<size_t> resulting_neighbors_naive;
- arma::mat distances_naive;
- naive_.Search(15, resulting_neighbors_naive, distances_naive);
+ arma::Mat<size_t> resultingNeighborsNaive;
+ arma::mat distancesNaive;
+ naive_.Search(15, resultingNeighborsNaive, distancesNaive);
- for (size_t i = 0; i < resulting_neighbors_tree.n_elem; i++)
+ for (size_t i = 0; i < resultingNeighborsTree.n_elem; i++)
{
- BOOST_REQUIRE(resulting_neighbors_tree[i] == resulting_neighbors_naive[i]);
- BOOST_REQUIRE_CLOSE(distances_tree[i], distances_naive[i], 1e-5);
+ BOOST_REQUIRE(resultingNeighborsTree[i] == resultingNeighborsNaive[i]);
+ BOOST_REQUIRE_CLOSE(distancesTree[i], distancesNaive[i], 1e-5);
}
}
Modified: mlpack/trunk/src/mlpack/tests/aug_lagrangian_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/aug_lagrangian_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/aug_lagrangian_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -20,7 +20,7 @@
* Tests the Augmented Lagrangian optimizer using the
* AugmentedLagrangianTestFunction class.
*/
-BOOST_AUTO_TEST_CASE(aug_lagrangian_test_function)
+BOOST_AUTO_TEST_CASE(AugLagrangianTestFunction)
{
// The choice of 10 memory slots is arbitrary.
AugLagrangianTestFunction f;
@@ -31,9 +31,9 @@
if(!aug.Optimize(0, coords))
BOOST_FAIL("Optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
- BOOST_REQUIRE_CLOSE(final_value, 70, 1e-5);
+ BOOST_REQUIRE_CLOSE(finalValue, 70, 1e-5);
BOOST_REQUIRE_CLOSE(coords[0], 1, 1e-5);
BOOST_REQUIRE_CLOSE(coords[1], 4, 1e-5);
}
@@ -41,7 +41,7 @@
/**
* Tests the Augmented Lagrangian optimizer using the Gockenbach function.
*/
-BOOST_AUTO_TEST_CASE(gockenbach_function)
+BOOST_AUTO_TEST_CASE(GockenbachFunction)
{
GockenbachFunction f;
AugLagrangian<GockenbachFunction> aug(f, 10);
@@ -51,9 +51,9 @@
if(!aug.Optimize(0, coords))
BOOST_FAIL("Optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
- BOOST_REQUIRE_CLOSE(final_value, 29.633926, 1e-5);
+ BOOST_REQUIRE_CLOSE(finalValue, 29.633926, 1e-5);
BOOST_REQUIRE_CLOSE(coords[0], 0.12288178, 1e-5);
BOOST_REQUIRE_CLOSE(coords[1], -1.10778185, 1e-5);
BOOST_REQUIRE_CLOSE(coords[2], 0.015099932, 1e-5);
@@ -62,7 +62,7 @@
/**
* Extremely simple test case for the Lovasz theta SDP.
*/
-BOOST_AUTO_TEST_CASE(extremely_simple_lovasz_theta_sdp)
+BOOST_AUTO_TEST_CASE(ExtremelySimpleLovaszThetaSdp)
{
// Manually input the single edge.
arma::mat edges = "0; 1";
@@ -75,11 +75,11 @@
if (!aug.Optimize(0, coords))
BOOST_FAIL("Optimization reported failure.");
- double final_value = ltsdp.Evaluate(coords);
+ double finalValue = ltsdp.Evaluate(coords);
arma::mat X = trans(coords) * coords;
- BOOST_CHECK_CLOSE(final_value, -1.0, 1e-5);
+ BOOST_CHECK_CLOSE(finalValue, -1.0, 1e-5);
BOOST_CHECK_CLOSE(X(0, 0) + X(1, 1), 1.0, 1e-5);
BOOST_CHECK_SMALL(X(0, 1), 1e-8);
@@ -104,9 +104,9 @@
if(!aug.Optimize(0, coords))
BOOST_FAIL("Optimization reported failure.");
- double final_value = ltsdp.Evaluate(coords);
+ double finalValue = ltsdp.Evaluate(coords);
- BOOST_REQUIRE_CLOSE(final_value, -14.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(finalValue, -14.0, 1e-5);
}
*/
Modified: mlpack/trunk/src/mlpack/tests/cli_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/cli_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/cli_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -41,13 +41,13 @@
// Check the description of our variable.
BOOST_REQUIRE_EQUAL(CLI::GetDescription("global/bool").compare(
- std::string("True or False")) , 0);
+ std::string("True or False")) , 0);
// Check that our aliasing works.
BOOST_REQUIRE_EQUAL(CLI::HasParam("global/bool"),
CLI::HasParam("alias/bool"));
BOOST_REQUIRE_EQUAL(CLI::GetDescription("global/bool").compare(
- CLI::GetDescription("alias/bool")), 0);
+ CLI::GetDescription("alias/bool")), 0);
BOOST_REQUIRE_EQUAL(CLI::GetParam<bool>("global/bool"),
CLI::GetParam<bool>("alias/bool"));
}
Modified: mlpack/trunk/src/mlpack/tests/emst_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/emst_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/emst_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -19,7 +19,7 @@
* in one dimension for simplicity -- the correct functionality of distance
* functions is not tested here.
*/
-BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
+BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest)
{
// Set up our data.
arma::mat data(1, 11);
@@ -88,39 +88,39 @@
*
* Errors are produced if the results are not identical.
*/
-BOOST_AUTO_TEST_CASE(dual_tree_vs_naive)
+BOOST_AUTO_TEST_CASE(DualTreeVsNaive)
{
- arma::mat input_data;
+ arma::mat inputData;
// Hard-coded filename: bad!
// Code duplication: also bad!
- if (!data::Load("test_data_3_1000.csv", input_data))
+ if (!data::Load("test_data_3_1000.csv", inputData))
BOOST_FAIL("Cannot load test dataset test_data_3_1000.csv!");
// Set up matrices to work with (may not be necessary with no ALIAS_MATRIX?).
- arma::mat dual_data = arma::trans(input_data);
- arma::mat naive_data = arma::trans(input_data);
+ arma::mat dualData = arma::trans(inputData);
+ arma::mat naiveData = arma::trans(inputData);
// Reset parameters from last test.
- DualTreeBoruvka<> dtb(dual_data);
+ DualTreeBoruvka<> dtb(dualData);
- arma::mat dual_results;
- dtb.ComputeMST(dual_results);
+ arma::mat dualResults;
+ dtb.ComputeMST(dualResults);
// Set naive mode.
- DualTreeBoruvka<> dtb_naive(naive_data, true);
+ DualTreeBoruvka<> dtbNaive(naiveData, true);
- arma::mat naive_results;
- dtb_naive.ComputeMST(naive_results);
+ arma::mat naiveResults;
+ dtbNaive.ComputeMST(naiveResults);
- BOOST_REQUIRE(dual_results.n_cols == naive_results.n_cols);
- BOOST_REQUIRE(dual_results.n_rows == naive_results.n_rows);
+ BOOST_REQUIRE(dualResults.n_cols == naiveResults.n_cols);
+ BOOST_REQUIRE(dualResults.n_rows == naiveResults.n_rows);
- for (size_t i = 0; i < dual_results.n_cols; i++)
+ for (size_t i = 0; i < dualResults.n_cols; i++)
{
- BOOST_REQUIRE(dual_results(0, i) == naive_results(0, i));
- BOOST_REQUIRE(dual_results(1, i) == naive_results(1, i));
- BOOST_REQUIRE_CLOSE(dual_results(2, i), naive_results(2, i), 1e-5);
+ BOOST_REQUIRE(dualResults(0, i) == naiveResults(0, i));
+ BOOST_REQUIRE(dualResults(1, i) == naiveResults(1, i));
+ BOOST_REQUIRE_CLOSE(dualResults(2, i), naiveResults(2, i), 1e-5);
}
}
Modified: mlpack/trunk/src/mlpack/tests/gmm_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/gmm_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/gmm_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -147,17 +147,17 @@
GMM gmm(1, 2);
gmm.Estimate(data);
- arma::vec actual_mean = arma::mean(data, 1);
- arma::mat actual_covar = ccov(data, 1 /* biased estimator */);
+ arma::vec actualMean = arma::mean(data, 1);
+ arma::mat actualCovar = ccov(data, 1 /* biased estimator */);
// Check the model to see that it is correct.
- BOOST_REQUIRE_CLOSE((gmm.Means()[0])[0], actual_mean(0), 1e-5);
- BOOST_REQUIRE_CLOSE((gmm.Means()[0])[1], actual_mean(1), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Means()[0])[0], actualMean(0), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Means()[0])[1], actualMean(1), 1e-5);
- BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(0, 0), actual_covar(0, 0), 1e-5);
- BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(0, 1), actual_covar(0, 1), 1e-5);
- BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(1, 0), actual_covar(1, 0), 1e-5);
- BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(1, 1), actual_covar(1, 1), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(0, 0), actualCovar(0, 0), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(0, 1), actualCovar(0, 1), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(1, 0), actualCovar(1, 0), 1e-5);
+ BOOST_REQUIRE_CLOSE((gmm.Covariances()[0])(1, 1), actualCovar(1, 1), 1e-5);
BOOST_REQUIRE_CLOSE(gmm.Weights()[0], 1.0, 1e-5);
}
Modified: mlpack/trunk/src/mlpack/tests/kernel_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/kernel_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/kernel_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -21,7 +21,7 @@
/**
* Basic test of the Manhattan distance.
*/
-BOOST_AUTO_TEST_CASE(manhattan_distance)
+BOOST_AUTO_TEST_CASE(ManhattanDistance)
{
// A couple quick tests.
arma::vec a = "1.0 3.0 4.0";
@@ -38,7 +38,7 @@
/**
* Basic test of squared Euclidean distance.
*/
-BOOST_AUTO_TEST_CASE(squared_euclidean_distance)
+BOOST_AUTO_TEST_CASE(SquaredEuclideanDistance)
{
// Sample 2-dimensional vectors.
arma::vec a = "1.0 2.0";
@@ -51,7 +51,7 @@
/**
* Basic test of Euclidean distance.
*/
-BOOST_AUTO_TEST_CASE(euclidean_distance)
+BOOST_AUTO_TEST_CASE(EuclideanDistance)
{
arma::vec a = "1.0 3.0 5.0 7.0";
arma::vec b = "4.0 0.0 2.0 0.0";
@@ -63,7 +63,7 @@
/**
* Arbitrary test case for coverage.
*/
-BOOST_AUTO_TEST_CASE(arbitrary_case)
+BOOST_AUTO_TEST_CASE(ArbitraryCase)
{
arma::vec a = "3.0 5.0 6.0 7.0";
arma::vec b = "1.0 2.0 1.0 0.0";
@@ -79,7 +79,7 @@
* Make sure two vectors of all zeros return zero distance, for a few different
* powers.
*/
-BOOST_AUTO_TEST_CASE(lmetric_zeros)
+BOOST_AUTO_TEST_CASE(LmetricZeros)
{
arma::vec a(250);
a.fill(0.0);
@@ -101,7 +101,7 @@
/**
* Simple test of Mahalanobis distance with unset covariance matrix.
*/
-BOOST_AUTO_TEST_CASE(md_unset_covariance)
+BOOST_AUTO_TEST_CASE(MdUnsetCovariance)
{
MahalanobisDistance<false> md;
arma::vec a = "1.0 2.0 2.0 3.0";
@@ -115,7 +115,7 @@
* Simple test of Mahalanobis distance with unset covariance matrix and
* t_take_root set to true.
*/
-BOOST_AUTO_TEST_CASE(md_root_unset_covariance)
+BOOST_AUTO_TEST_CASE(MdRootUnsetCovariance)
{
MahalanobisDistance<true> md;
arma::vec a = "1.0 2.0 2.5 5.0";
@@ -128,7 +128,7 @@
/**
* Simple test with diagonal covariance matrix.
*/
-BOOST_AUTO_TEST_CASE(md_diagonal_covariance)
+BOOST_AUTO_TEST_CASE(MdDiagonalCovariance)
{
arma::mat cov = arma::eye<arma::mat>(5, 5);
cov(0, 0) = 2.0;
@@ -148,12 +148,12 @@
/**
* More specific case with more difficult covariance matrix.
*/
-BOOST_AUTO_TEST_CASE(md_full_covariance)
+BOOST_AUTO_TEST_CASE(MdFullCovariance)
{
arma::mat cov = "1.0 2.0 3.0 4.0;"
- "0.5 0.6 0.7 0.1;"
- "3.4 4.3 5.0 6.1;"
- "1.0 2.0 4.0 1.0;";
+ "0.5 0.6 0.7 0.1;"
+ "3.4 4.3 5.0 6.1;"
+ "1.0 2.0 4.0 1.0;";
MahalanobisDistance<false> md(cov);
arma::vec a = "1.0 2.0 2.0 4.0";
@@ -166,7 +166,7 @@
/**
* Simple test case for the cosine distance.
*/
-BOOST_AUTO_TEST_CASE(cosine_distance_same_angle)
+BOOST_AUTO_TEST_CASE(CosineDistanceSameAngle)
{
arma::vec a = "1.0 2.0 3.0";
arma::vec b = "2.0 4.0 6.0";
@@ -178,7 +178,7 @@
/**
* Now let's have them be orthogonal.
*/
-BOOST_AUTO_TEST_CASE(cosine_distance_orthogonal)
+BOOST_AUTO_TEST_CASE(CosineDistanceOrthogonal)
{
arma::vec a = "0.0 1.0";
arma::vec b = "1.0 0.0";
@@ -190,7 +190,7 @@
/**
* Some random angle test.
*/
-BOOST_AUTO_TEST_CASE(cosine_distance_random_test)
+BOOST_AUTO_TEST_CASE(CosineDistanceRandomTest)
{
arma::vec a = "0.1 0.2 0.3 0.4 0.5";
arma::vec b = "1.2 1.0 0.8 -0.3 -0.5";
@@ -202,7 +202,7 @@
/**
* Linear Kernel test.
*/
-BOOST_AUTO_TEST_CASE(linear_kernel)
+BOOST_AUTO_TEST_CASE(LinearKernel)
{
arma::vec a = ".2 .3 .4 .1";
arma::vec b = ".56 .21 .623 .82";
@@ -215,7 +215,7 @@
/**
* Linear Kernel test, orthogonal vectors.
*/
-BOOST_AUTO_TEST_CASE(linear_kernel_orthogonal)
+BOOST_AUTO_TEST_CASE(LinearKernelOrthogonal)
{
arma::vec a = "1 0 0";
arma::vec b = "0 0 1";
@@ -225,7 +225,7 @@
BOOST_REQUIRE_SMALL(lk.Evaluate(b,a), 1e-5);
}
-BOOST_AUTO_TEST_CASE(gaussian_kernel)
+BOOST_AUTO_TEST_CASE(GaussianKernel)
{
arma::vec a = "1 0 0";
arma::vec b = "0 1 0";
Modified: mlpack/trunk/src/mlpack/tests/lars_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/lars_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/lars_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -6,6 +6,8 @@
// Note: We don't use BOOST_REQUIRE_CLOSE in the code below because we need
// to use FPC_WEAK, and it's not at all intuitive how to do that.
+
+
#include <armadillo>
#include <mlpack/methods/lars/lars.hpp>
@@ -14,16 +16,18 @@
using namespace mlpack;
using namespace mlpack::regression;
-BOOST_AUTO_TEST_SUITE(LARS_Test);
+BOOST_AUTO_TEST_SUITE(LARSTest);
-void GenerateProblem(arma::mat& X, arma::vec& y, size_t nPoints, size_t nDims) {
+void GenerateProblem(arma::mat& X, arma::vec& y, size_t nPoints, size_t nDims)
+{
X = arma::randn(nPoints, nDims);
arma::vec beta = arma::randn(nDims, 1);
y = X * beta;
}
-void VerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda) {
+void VerifyCorrectness(arma::vec beta, arma::vec errCorr, double lambda)
+{
size_t nDims = beta.n_elem;
const double tol = 1e-12;
for(size_t j = 0; j < nDims; j++) {
@@ -43,52 +47,58 @@
}
-void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky) {
+void LassoTest(size_t nPoints, size_t nDims, bool elasticNet, bool useCholesky)
+{
arma::mat X;
arma::vec y;
-
- for(size_t i = 0; i < 100; i++) {
+
+ for(size_t i = 0; i < 100; i++)
+ {
GenerateProblem(X, y, nPoints, nDims);
-
+
// Armadillo's median is broken, so...
arma::vec sortedAbsCorr = sort(abs(trans(X) * y));
- double lambda_1 = sortedAbsCorr(nDims/2);
- double lambda_2;
- if(elasticNet) {
- lambda_2 = lambda_1 / 2;
- }
- else {
- lambda_2 = 0;
- }
-
- LARS lars(useCholesky, lambda_1, lambda_2);
+ double lambda1 = sortedAbsCorr(nDims/2);
+ double lambda2;
+ if (elasticNet)
+ lambda2 = lambda1 / 2;
+ else
+ lambda2 = 0;
+
+
+ LARS lars(useCholesky, lambda1, lambda2);
lars.DoLARS(X, y);
-
+
arma::vec betaOpt;
lars.Solution(betaOpt);
- arma::vec errCorr = (arma::trans(X) * X + lambda_2 * arma::eye(nDims, nDims)) * betaOpt - arma::trans(X) * y;
-
- VerifyCorrectness(betaOpt, errCorr, lambda_1);
+ arma::vec errCorr = (arma::trans(X) * X + lambda2 *
+ arma::eye(nDims, nDims)) * betaOpt - arma::trans(X) * y;
+
+ VerifyCorrectness(betaOpt, errCorr, lambda1);
}
}
-BOOST_AUTO_TEST_CASE(LARS_Test_Lasso_Cholesky) {
+BOOST_AUTO_TEST_CASE(LARSTestLassoCholesky)
+{
LassoTest(100, 10, true, false);
}
-BOOST_AUTO_TEST_CASE(LARS_Test_Lasso_Gram) {
+BOOST_AUTO_TEST_CASE(LARSTestLassoGram)
+{
LassoTest(100, 10, false, false);
}
-BOOST_AUTO_TEST_CASE(LARS_Test_ElasticNet_Cholesky) {
+BOOST_AUTO_TEST_CASE(LARSTestElasticNetCholesky)
+{
LassoTest(100, 10, true, true);
}
-BOOST_AUTO_TEST_CASE(LARS_Test_ElasticNet_Gram) {
+BOOST_AUTO_TEST_CASE(LARSTestElasticNetGram)
+{
LassoTest(100, 10, true, false);
}
Modified: mlpack/trunk/src/mlpack/tests/lbfgs_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/lbfgs_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/lbfgs_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -19,18 +19,18 @@
/**
* Tests the L-BFGS optimizer using the Rosenbrock Function.
*/
-BOOST_AUTO_TEST_CASE(rosenbrock_function)
+BOOST_AUTO_TEST_CASE(RosenbrockFunction)
{
RosenbrockFunction f;
L_BFGS<RosenbrockFunction> lbfgs(f, 10);
arma::vec coords = f.GetInitialPoint();
- if(!lbfgs.Optimize(0, coords))
+ if (!lbfgs.Optimize(0, coords))
BOOST_FAIL("L-BFGS optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
- BOOST_REQUIRE_SMALL(final_value, 1e-5);
+ BOOST_REQUIRE_SMALL(finalValue, 1e-5);
BOOST_REQUIRE_CLOSE(coords[0], 1, 1e-5);
BOOST_REQUIRE_CLOSE(coords[1], 1, 1e-5);
}
@@ -38,18 +38,18 @@
/**
* Tests the L-BFGS optimizer using the Wood Function.
*/
-BOOST_AUTO_TEST_CASE(wood_function)
+BOOST_AUTO_TEST_CASE(WoodFunction)
{
WoodFunction f;
L_BFGS<WoodFunction> lbfgs(f, 10);
arma::vec coords = f.GetInitialPoint();
- if(!lbfgs.Optimize(0, coords))
+ if (!lbfgs.Optimize(0, coords))
BOOST_FAIL("L-BFGS optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
- BOOST_REQUIRE_SMALL(final_value, 1e-5);
+ BOOST_REQUIRE_SMALL(finalValue, 1e-5);
BOOST_REQUIRE_CLOSE(coords[0], 1, 1e-5);
BOOST_REQUIRE_CLOSE(coords[1], 1, 1e-5);
BOOST_REQUIRE_CLOSE(coords[2], 1, 1e-5);
@@ -61,7 +61,7 @@
* is actually multiple tests, increasing the dimension by powers of 2, from 4
* dimensions to 1024 dimensions.
*/
-BOOST_AUTO_TEST_CASE(generalized_rosenbrock_function)
+BOOST_AUTO_TEST_CASE(GeneralizedRosenbrockFunction)
{
for (int i = 2; i < 10; i++)
{
@@ -72,13 +72,13 @@
L_BFGS<GeneralizedRosenbrockFunction> lbfgs(f, 20);
arma::vec coords = f.GetInitialPoint();
- if(!lbfgs.Optimize(0, coords))
+ if (!lbfgs.Optimize(0, coords))
BOOST_FAIL("L-BFGS optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
// Test the output to make sure it is correct.
- BOOST_REQUIRE_SMALL(final_value, 1e-5);
+ BOOST_REQUIRE_SMALL(finalValue, 1e-5);
for (int j = 0; j < dim; j++)
BOOST_REQUIRE_CLOSE(coords[j], 1, 1e-5);
}
@@ -88,18 +88,18 @@
* Tests the L-BFGS optimizer using the Rosenbrock-Wood combined function. This
* is a test on optimizing a matrix of coordinates.
*/
-BOOST_AUTO_TEST_CASE(rosenbrock_wood_function)
+BOOST_AUTO_TEST_CASE(RosenbrockWoodFunction)
{
RosenbrockWoodFunction f;
L_BFGS<RosenbrockWoodFunction> lbfgs(f, 10);
arma::mat coords = f.GetInitialPoint();
- if(!lbfgs.Optimize(0, coords))
+ if (!lbfgs.Optimize(0, coords))
BOOST_FAIL("L-BFGS optimization reported failure.");
- double final_value = f.Evaluate(coords);
+ double finalValue = f.Evaluate(coords);
- BOOST_REQUIRE_SMALL(final_value, 1e-5);
+ BOOST_REQUIRE_SMALL(finalValue, 1e-5);
for (int row = 0; row < 4; row++)
{
BOOST_REQUIRE_CLOSE((coords(row, 0)), 1, 1e-5);
Modified: mlpack/trunk/src/mlpack/tests/load_save_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/load_save_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/load_save_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -74,9 +74,9 @@
BOOST_AUTO_TEST_CASE(SaveCSVTest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
BOOST_REQUIRE(data::Save("test_file.csv", test) == true);
@@ -99,9 +99,9 @@
BOOST_AUTO_TEST_CASE(LoadArmaASCIITest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
arma::mat testTrans = trans(test);
BOOST_REQUIRE(testTrans.save("test_file.txt", arma::arma_ascii));
@@ -124,9 +124,9 @@
BOOST_AUTO_TEST_CASE(SaveArmaASCIITest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
BOOST_REQUIRE(data::Save("test_file.txt", test) == true);
@@ -201,9 +201,9 @@
BOOST_AUTO_TEST_CASE(LoadArmaBinaryTest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
arma::mat testTrans = trans(test);
BOOST_REQUIRE(testTrans.quiet_save("test_file.bin", arma::arma_binary)
@@ -228,9 +228,9 @@
BOOST_AUTO_TEST_CASE(SaveArmaBinaryTest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
BOOST_REQUIRE(data::Save("test_file.bin", test) == true);
@@ -252,9 +252,9 @@
BOOST_AUTO_TEST_CASE(LoadRawBinaryTest)
{
arma::mat test = "1 2;"
- "3 4;"
- "5 6;"
- "7 8;";
+ "3 4;"
+ "5 6;"
+ "7 8;";
arma::mat testTrans = trans(test);
BOOST_REQUIRE(testTrans.quiet_save("test_file.bin", arma::raw_binary)
@@ -279,9 +279,9 @@
BOOST_AUTO_TEST_CASE(LoadPGMBinaryTest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
arma::mat testTrans = trans(test);
BOOST_REQUIRE(testTrans.quiet_save("test_file.pgm", arma::pgm_binary)
@@ -306,9 +306,9 @@
BOOST_AUTO_TEST_CASE(SavePGMBinaryTest)
{
arma::mat test = "1 5;"
- "2 6;"
- "3 7;"
- "4 8;";
+ "2 6;"
+ "3 7;"
+ "4 8;";
BOOST_REQUIRE(data::Save("test_file.pgm", test) == true);
Modified: mlpack/trunk/src/mlpack/tests/nca_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/nca_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/nca_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -25,7 +25,7 @@
* The Softmax error function should return the identity matrix as its initial
* point.
*/
-BOOST_AUTO_TEST_CASE(softmax_initial_point)
+BOOST_AUTO_TEST_CASE(SoftmaxInitialPoint)
{
// Cheap fake dataset.
arma::mat data;
@@ -36,15 +36,15 @@
SoftmaxErrorFunction<SquaredEuclideanDistance> sef(data, labels);
// Verify the initial point is the identity matrix.
- arma::mat initial_point = sef.GetInitialPoint();
+ arma::mat initialPoint = sef.GetInitialPoint();
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < 5; col++)
{
if (row == col)
- BOOST_REQUIRE_CLOSE(initial_point(row, col), 1.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(initialPoint(row, col), 1.0, 1e-5);
else
- BOOST_REQUIRE(initial_point(row, col) == 0.0);
+ BOOST_REQUIRE(initialPoint(row, col) == 0.0);
}
}
}
@@ -53,7 +53,7 @@
* On a simple fake dataset, ensure that the initial function evaluation is
* correct.
*/
-BOOST_AUTO_TEST_CASE(softmax_initial_evaluation)
+BOOST_AUTO_TEST_CASE(SoftmaxInitialEvaluation)
{
// Useful but simple dataset with six points and two classes.
arma::mat data = "-0.1 -0.1 -0.1 0.1 0.1 0.1;"
@@ -74,7 +74,7 @@
* On a simple fake dataset, ensure that the initial gradient evaluation is
* correct.
*/
-BOOST_AUTO_TEST_CASE(softmax_initial_gradient)
+BOOST_AUTO_TEST_CASE(SoftmaxInitialGradient)
{
// Useful but simple dataset with six points and two classes.
arma::mat data = "-0.1 -0.1 -0.1 0.1 0.1 0.1;"
@@ -99,7 +99,7 @@
* On optimally separated datasets, ensure that the objective function is
* optimal (equal to the negative number of points).
*/
-BOOST_AUTO_TEST_CASE(softmax_optimal_evaluation)
+BOOST_AUTO_TEST_CASE(SoftmaxOptimalEvaluation)
{
// Simple optimal dataset.
arma::mat data = " 500 500 -500 -500;"
@@ -118,7 +118,7 @@
/**
* On optimally separated datasets, ensure that the gradient is zero.
*/
-BOOST_AUTO_TEST_CASE(softmax_optimal_gradient)
+BOOST_AUTO_TEST_CASE(SoftmaxOptimalGradient)
{
// Simple optimal dataset.
arma::mat data = " 500 500 -500 -500;"
@@ -144,7 +144,7 @@
* On our simple dataset, ensure that the NCA algorithm fully separates the
* points.
*/
-BOOST_AUTO_TEST_CASE(nca_simple_dataset)
+BOOST_AUTO_TEST_CASE(NcaSimpleDataset)
{
// Useful but simple dataset with six points and two classes.
arma::mat data = "-0.1 -0.1 -0.1 0.1 0.1 0.1;"
@@ -153,24 +153,24 @@
NCA<SquaredEuclideanDistance> nca(data, labels);
- arma::mat output_matrix;
- nca.LearnDistance(output_matrix);
+ arma::mat outputMatrix;
+ nca.LearnDistance(outputMatrix);
// Ensure that the objective function is better now.
SoftmaxErrorFunction<SquaredEuclideanDistance> sef(data, labels);
- double init_obj = sef.Evaluate(arma::eye<arma::mat>(2, 2));
- double final_obj = sef.Evaluate(output_matrix);
- arma::mat final_gradient;
- sef.Gradient(output_matrix, final_gradient);
+ double initObj = sef.Evaluate(arma::eye<arma::mat>(2, 2));
+ double finalObj = sef.Evaluate(outputMatrix);
+ arma::mat finalGradient;
+ sef.Gradient(outputMatrix, finalGradient);
- // final_obj must be less than init_obj.
- BOOST_REQUIRE_LT(final_obj, init_obj);
+ // finalObj must be less than initObj.
+ BOOST_REQUIRE_LT(finalObj, initObj);
// Verify that final objective is optimal.
- BOOST_REQUIRE_CLOSE(final_obj, -6.0, 1e-8);
+ BOOST_REQUIRE_CLOSE(finalObj, -6.0, 1e-8);
// The solution is not unique, so the best we can do is ensure the gradient
// norm is close to 0.
- BOOST_REQUIRE_LT(arma::norm(final_gradient, 2), 1e-10);
+ BOOST_REQUIRE_LT(arma::norm(finalGradient, 2), 1e-10);
}
BOOST_AUTO_TEST_SUITE_END();
Modified: mlpack/trunk/src/mlpack/tests/radical_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/radical_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/radical_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -7,10 +7,9 @@
#include <armadillo>
#include <mlpack/core.hpp>
#include <mlpack/methods/radical/radical.hpp>
-
#include <boost/test/unit_test.hpp>
-BOOST_AUTO_TEST_SUITE(Radical_Test);
+BOOST_AUTO_TEST_SUITE(RadicalTest);
using namespace mlpack;
using namespace mlpack::radical;
@@ -22,28 +21,33 @@
data::Load("data_3d_mixed.txt", matX);
radical::Radical rad(0.175, 5, 100, matX.n_rows - 1);
+
mat matY;
- mat matW;
-
- rad.DoRadical(matX, matY, matW);
-
+ mat matW;
+ rad.DoRadical(matX, matY, matW);
+
mat matYT = trans(matY);
double valEst = 0;
- for(u32 i = 0; i < matYT.n_cols; i++) {
+
+ for(u32 i = 0; i < matYT.n_cols; i++)
+ {
vec y = vec(matYT.col(i));
valEst += rad.Vasicek(y);
- }
-
+ }
+
mat matS;
- data::Load("data_3d_ind.txt", matS);
+ data::Load("data_3d_ind.txt", matS);
rad.DoRadical(matS, matY, matW);
+
matYT = trans(matY);
double valBest = 0;
- for(u32 i = 0; i < matYT.n_cols; i++) {
+
+ for (u32 i = 0; i < matYT.n_cols; i++)
+ {
vec y = vec(matYT.col(i));
valBest += rad.Vasicek(y);
}
-
+
/*
printf("valBest = %f\n", valBest);
printf("valEst = %f\n", valEst);
@@ -51,8 +55,9 @@
printf("\n\n\t\t%f\n", fabs(valBest - valEst) / fabs(valBest));
printf("\n\n\t\t%f\n", fabs(valBest - valEst) / fabs(valEst));
*/
-
+
BOOST_REQUIRE_CLOSE(valBest, valEst, 0.2);
+
}
BOOST_AUTO_TEST_SUITE_END();
Modified: mlpack/trunk/src/mlpack/tests/range_search_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/range_search_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/range_search_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -26,9 +26,7 @@
{
output[i].resize(neighbors[i].size());
for (size_t j = 0; j < neighbors[i].size(); j++)
- {
output[i][j] = make_pair(distances[i][j], neighbors[i][j]);
- }
// Now that it's constructed, sort it.
sort(output[i].begin(), output[i].end());
@@ -43,7 +41,7 @@
* dataset is in one dimension for simplicity -- the correct functionality of
* distance functions is not tested here.
*/
-BOOST_AUTO_TEST_CASE(exhaustive_synthetic_test)
+BOOST_AUTO_TEST_CASE(ExhaustiveSyntheticTest)
{
// Set up our data.
arma::mat data(1, 11);
@@ -64,17 +62,17 @@
for (int i = 0; i < 3; i++)
{
RangeSearch<>* rs;
- arma::mat data_mutable = data;
+ arma::mat dataMutable = data;
switch (i)
{
case 0: // Use the dual-tree method.
- rs = new RangeSearch<>(data_mutable, false, false, 1);
+ rs = new RangeSearch<>(dataMutable, false, false, 1);
break;
case 1: // Use the single-tree method.
- rs = new RangeSearch<>(data_mutable, false, true, 1);
+ rs = new RangeSearch<>(dataMutable, false, true, 1);
break;
case 2: // Use the naive method.
- rs = new RangeSearch<>(data_mutable, true);
+ rs = new RangeSearch<>(dataMutable, true);
break;
}
@@ -447,16 +445,16 @@
RangeSearch<> naive(naiveQuery, naiveReferences, true);
- vector<vector<size_t> > neighborsTree;
- vector<vector<double> > distancesTree;
+ vector<vector<size_t>> neighborsTree;
+ vector<vector<double>> distancesTree;
rs.Search(Range(0.25, 1.05), neighborsTree, distancesTree);
- vector<vector<pair<double, size_t> > > sortedTree;
+ vector<vector<pair<double, size_t>>> sortedTree;
SortResults(neighborsTree, distancesTree, sortedTree);
- vector<vector<size_t> > neighborsNaive;
- vector<vector<double> > distancesNaive;
+ vector<vector<size_t>> neighborsNaive;
+ vector<vector<double>> distancesNaive;
naive.Search(Range(0.25, 1.05), neighborsNaive, distancesNaive);
- vector<vector<pair<double, size_t> > > sortedNaive;
+ vector<vector<pair<double, size_t>>> sortedNaive;
SortResults(neighborsNaive, distancesNaive, sortedNaive);
for (size_t i = 0; i < sortedTree.size(); i++)
@@ -496,16 +494,16 @@
// Set naive mode.
RangeSearch<> naive(naiveQuery, true);
- vector<vector<size_t> > neighborsTree;
- vector<vector<double> > distancesTree;
+ vector<vector<size_t>> neighborsTree;
+ vector<vector<double>> distancesTree;
rs.Search(Range(0.25, 1.05), neighborsTree, distancesTree);
- vector<vector<pair<double, size_t> > > sortedTree;
+ vector<vector<pair<double, size_t>>> sortedTree;
SortResults(neighborsTree, distancesTree, sortedTree);
- vector<vector<size_t> > neighborsNaive;
- vector<vector<double> > distancesNaive;
+ vector<vector<size_t>> neighborsNaive;
+ vector<vector<double>> distancesNaive;
naive.Search(Range(0.25, 1.05), neighborsNaive, distancesNaive);
- vector<vector<pair<double, size_t> > > sortedNaive;
+ vector<vector<pair<double, size_t>>> sortedNaive;
SortResults(neighborsNaive, distancesNaive, sortedNaive);
for (size_t i = 0; i < sortedTree.size(); i++)
@@ -545,16 +543,16 @@
// Set up computation for naive mode.
RangeSearch<> naive(naiveQuery, true);
- vector<vector<size_t> > neighborsSingle;
- vector<vector<double> > distancesSingle;
+ vector<vector<size_t>> neighborsSingle;
+ vector<vector<double>> distancesSingle;
single.Search(Range(0.25, 1.05), neighborsSingle, distancesSingle);
- vector<vector<pair<double, size_t> > > sortedTree;
+ vector<vector<pair<double, size_t>>> sortedTree;
SortResults(neighborsSingle, distancesSingle, sortedTree);
- vector<vector<size_t> > neighborsNaive;
- vector<vector<double> > distancesNaive;
+ vector<vector<size_t>> neighborsNaive;
+ vector<vector<double>> distancesNaive;
naive.Search(Range(0.25, 1.05), neighborsNaive, distancesNaive);
- vector<vector<pair<double, size_t> > > sortedNaive;
+ vector<vector<pair<double, size_t>>> sortedNaive;
SortResults(neighborsNaive, distancesNaive, sortedNaive);
for (size_t i = 0; i < sortedTree.size(); i++)
Modified: mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -5,7 +5,6 @@
* Here we have tests for the SaveRestoreModel class.
*/
#include <mlpack/core/util/save_restore_utility.hpp>
-
#include <boost/test/unit_test.hpp>
#define ARGSTR(a) a,#a
@@ -40,9 +39,8 @@
{
bool success = saveRestore.ReadFile(filename);
if (success)
- {
anInt = saveRestore.LoadParameter(anInt, "anInt");
- }
+
return success;
}
@@ -53,7 +51,7 @@
/**
* Perform a save and restore on basic types.
*/
-BOOST_AUTO_TEST_CASE(save_basic_types)
+BOOST_AUTO_TEST_CASE(SaveBasicTypes)
{
bool b = false;
char c = 67;
@@ -103,7 +101,7 @@
delete sRM;
}
-BOOST_AUTO_TEST_CASE(save_restore_std_vector)
+BOOST_AUTO_TEST_CASE(SaveRestoreStdVector)
{
size_t numbers[] = {0,3,6,2,6};
std::vector<size_t> vec (numbers,
@@ -119,15 +117,13 @@
std::vector<size_t> loadee = sRM->LoadParameter(ARGSTR(vec));
for (size_t index = 0; index < loadee.size(); ++index)
- {
BOOST_REQUIRE_EQUAL(numbers[index], loadee[index]);
- }
}
/**
* Test the arma::mat functionality.
*/
-BOOST_AUTO_TEST_CASE(save_arma_mat)
+BOOST_AUTO_TEST_CASE(SaveArmaMat)
{
arma::mat matrix;
matrix << 1.2 << 2.3 << -0.1 << arma::endr
@@ -145,12 +141,8 @@
arma::mat matrix2 = sRM->LoadParameter(ARGSTR(matrix));
for (size_t row = 0; row < matrix.n_rows; ++row)
- {
for (size_t column = 0; column < matrix.n_cols; ++column)
- {
BOOST_REQUIRE_CLOSE(matrix(row,column), matrix2(row,column), 1e-5);
- }
- }
delete sRM;
}
@@ -159,7 +151,7 @@
* Test SaveRestoreModel proper usage in child classes and loading from
* separately defined objects
*/
-BOOST_AUTO_TEST_CASE(save_restore_model_child_class_usage)
+BOOST_AUTO_TEST_CASE(SaveRestoreModelChildClassUsage)
{
SaveRestoreTest* saver = new SaveRestoreTest();
SaveRestoreTest* loader = new SaveRestoreTest();
Modified: mlpack/trunk/src/mlpack/tests/sort_policy_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/sort_policy_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/sort_policy_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -25,7 +25,7 @@
/**
* Ensure the best distance for nearest neighbors is 0.
*/
-BOOST_AUTO_TEST_CASE(nns_best_distance)
+BOOST_AUTO_TEST_CASE(NnsBestDistance)
{
BOOST_REQUIRE(NearestNeighborSort::BestDistance() == 0);
}
@@ -33,7 +33,7 @@
/**
* Ensure the worst distance for nearest neighbors is DBL_MAX.
*/
-BOOST_AUTO_TEST_CASE(nns_worst_distance)
+BOOST_AUTO_TEST_CASE(NnsWorstDistance)
{
BOOST_REQUIRE(NearestNeighborSort::WorstDistance() == DBL_MAX);
}
@@ -41,7 +41,7 @@
/**
* Make sure the comparison works for values strictly less than the reference.
*/
-BOOST_AUTO_TEST_CASE(nns_is_better_strict)
+BOOST_AUTO_TEST_CASE(NnsIsBetterStrict)
{
BOOST_REQUIRE(NearestNeighborSort::IsBetter(5.0, 6.0) == true);
}
@@ -49,7 +49,7 @@
/**
* Warn in case the comparison is not strict.
*/
-BOOST_AUTO_TEST_CASE(nns_is_better_not_strict)
+BOOST_AUTO_TEST_CASE(NnsIsBetterNotStrict)
{
BOOST_WARN(NearestNeighborSort::IsBetter(6.0, 6.0) == true);
}
@@ -58,7 +58,7 @@
* A simple test case of where to insert when all the values in the list are
* DBL_MAX.
*/
-BOOST_AUTO_TEST_CASE(nns_sort_distance_all_dbl_max)
+BOOST_AUTO_TEST_CASE(NnsSortDistanceAllDblMax)
{
arma::vec list(5);
list.fill(DBL_MAX);
@@ -71,7 +71,7 @@
* Another test case, where we are just putting the new value in the middle of
* the list.
*/
-BOOST_AUTO_TEST_CASE(nns_sort_distance_2)
+BOOST_AUTO_TEST_CASE(NnsSortDistance2)
{
arma::vec list(3);
list[0] = 0.66;
@@ -90,58 +90,58 @@
* Very simple sanity check to ensure that bounds are working alright. We will
* use a one-dimensional bound for simplicity.
*/
-BOOST_AUTO_TEST_CASE(nns_node_to_node_distance)
+BOOST_AUTO_TEST_CASE(NnsNodeToNodeDistance)
{
// Well, there's no easy way to make HRectBounds the way we want, so we have
// to make them and then expand the region to include new points.
- tree::BinarySpaceTree<HRectBound<2>, arma::mat> node_one;
+ tree::BinarySpaceTree<HRectBound<2>, arma::mat> nodeOne;
arma::vec utility(1);
utility[0] = 0;
- node_one.Bound() = HRectBound<2>(1);
- node_one.Bound() |= utility;
+ nodeOne.Bound() = HRectBound<2>(1);
+ nodeOne.Bound() |= utility;
utility[0] = 1;
- node_one.Bound() |= utility;
+ nodeOne.Bound() |= utility;
- tree::BinarySpaceTree<HRectBound<2>, arma::mat> node_two;
- node_two.Bound() = HRectBound<2>(1);
+ tree::BinarySpaceTree<HRectBound<2>, arma::mat> nodeTwo;
+ nodeTwo.Bound() = HRectBound<2>(1);
utility[0] = 5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = 6;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
// This should use the L2 squared distance.
- BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), 16.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), 16.0, 1e-5);
// And another just to be sure, from the other side.
- node_two.Bound().Clear();
+ nodeTwo.Bound().Clear();
utility[0] = -2;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = -1;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
// Again, the distance is the L2 squared distance.
- BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), 1.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), 1.0, 1e-5);
// Now, when the bounds overlap.
- node_two.Bound().Clear();
+ nodeTwo.Bound().Clear();
utility[0] = -0.5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = 0.5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
- BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), 0.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(NearestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), 0.0, 1e-5);
}
/**
* Another very simple sanity check for the point-to-node case, again in one
* dimension.
*/
-BOOST_AUTO_TEST_CASE(nns_point_to_node_distance)
+BOOST_AUTO_TEST_CASE(NnsPointToNodeDistance)
{
// Well, there's no easy way to make HRectBounds the way we want, so we have
// to make them and then expand the region to include new points.
@@ -179,7 +179,7 @@
/**
* Ensure the best distance for furthest neighbors is DBL_MAX.
*/
-BOOST_AUTO_TEST_CASE(fns_best_distance)
+BOOST_AUTO_TEST_CASE(FnsBestDistance)
{
BOOST_REQUIRE(FurthestNeighborSort::BestDistance() == DBL_MAX);
}
@@ -187,7 +187,7 @@
/**
* Ensure the worst distance for furthest neighbors is 0.
*/
-BOOST_AUTO_TEST_CASE(fns_worst_distance)
+BOOST_AUTO_TEST_CASE(FnsWorstDistance)
{
BOOST_REQUIRE(FurthestNeighborSort::WorstDistance() == 0);
}
@@ -195,7 +195,7 @@
/**
* Make sure the comparison works for values strictly less than the reference.
*/
-BOOST_AUTO_TEST_CASE(fns_is_better_strict)
+BOOST_AUTO_TEST_CASE(FnsIsBetterStrict)
{
BOOST_REQUIRE(FurthestNeighborSort::IsBetter(5.0, 4.0) == true);
}
@@ -203,7 +203,7 @@
/**
* Warn in case the comparison is not strict.
*/
-BOOST_AUTO_TEST_CASE(fns_is_better_not_strict)
+BOOST_AUTO_TEST_CASE(FnsIsBetterNotStrict)
{
BOOST_WARN(FurthestNeighborSort::IsBetter(6.0, 6.0) == true);
}
@@ -212,7 +212,7 @@
* A simple test case of where to insert when all the values in the list are
* 0.
*/
-BOOST_AUTO_TEST_CASE(fns_sort_distance_all_zero)
+BOOST_AUTO_TEST_CASE(FnsSortDistanceAllZero)
{
arma::vec list(5);
list.fill(0);
@@ -225,7 +225,7 @@
* Another test case, where we are just putting the new value in the middle of
* the list.
*/
-BOOST_AUTO_TEST_CASE(fns_sort_distance_2)
+BOOST_AUTO_TEST_CASE(FnsSortDistance2)
{
arma::vec list(3);
list[0] = 1.14;
@@ -244,57 +244,57 @@
* Very simple sanity check to ensure that bounds are working alright. We will
* use a one-dimensional bound for simplicity.
*/
-BOOST_AUTO_TEST_CASE(fns_node_to_node_distance)
+BOOST_AUTO_TEST_CASE(FnsNodeToNodeDistance)
{
// Well, there's no easy way to make HRectBounds the way we want, so we have
// to make them and then expand the region to include new points.
arma::vec utility(1);
utility[0] = 0;
- tree::BinarySpaceTree<HRectBound<2>, arma::mat> node_one;
- node_one.Bound() = HRectBound<2>(1);
- node_one.Bound() |= utility;
+ tree::BinarySpaceTree<HRectBound<2>, arma::mat> nodeOne;
+ nodeOne.Bound() = HRectBound<2>(1);
+ nodeOne.Bound() |= utility;
utility[0] = 1;
- node_one.Bound() |= utility;
+ nodeOne.Bound() |= utility;
- tree::BinarySpaceTree<HRectBound<2>, arma::mat> node_two;
- node_two.Bound() = HRectBound<2>(1);
+ tree::BinarySpaceTree<HRectBound<2>, arma::mat> nodeTwo;
+ nodeTwo.Bound() = HRectBound<2>(1);
utility[0] = 5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = 6;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
// This should use the L2 squared distance.
- BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), 36.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), 36.0, 1e-5);
// And another just to be sure, from the other side.
- node_two.Bound().Clear();
+ nodeTwo.Bound().Clear();
utility[0] = -2;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = -1;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
// Again, the distance is the L2 squared distance.
- BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), 9.0, 1e-5);
+ BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), 9.0, 1e-5);
// Now, when the bounds overlap.
- node_two.Bound().Clear();
+ nodeTwo.Bound().Clear();
utility[0] = -0.5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
utility[0] = 0.5;
- node_two.Bound() |= utility;
+ nodeTwo.Bound() |= utility;
- BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&node_one,
- &node_two), (1.5 * 1.5), 1e-5);
+ BOOST_REQUIRE_CLOSE(FurthestNeighborSort::BestNodeToNodeDistance(&nodeOne,
+ &nodeTwo), (1.5 * 1.5), 1e-5);
}
/**
* Another very simple sanity check for the point-to-node case, again in one
* dimension.
*/
-BOOST_AUTO_TEST_CASE(fns_point_to_node_distance)
+BOOST_AUTO_TEST_CASE(FnsPointToNodeDistance)
{
// Well, there's no easy way to make HRectBounds the way we want, so we have
// to make them and then expand the region to include new points.
Modified: mlpack/trunk/src/mlpack/tests/tree_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/tree_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/tree_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -360,11 +360,11 @@
// We will set the low randomly and the width randomly for each dimension of
// each bound.
- arma::vec lo_a(dim);
- arma::vec width_a(dim);
+ arma::vec loA(dim);
+ arma::vec widthA(dim);
- lo_a.randu();
- width_a.randu();
+ loA.randu();
+ widthA.randu();
arma::vec lo_b(dim);
arma::vec width_b(dim);
@@ -374,7 +374,7 @@
for (size_t j = 0; j < dim; j++)
{
- a[j] = Range(lo_a[j], lo_a[j] + width_a[j]);
+ a[j] = Range(loA[j], loA[j] + widthA[j]);
b[j] = Range(lo_b[j], lo_b[j] + width_b[j]);
}
@@ -410,14 +410,14 @@
// We will set the low randomly and the width randomly for each dimension of
// each bound.
- arma::vec lo_a(dim);
- arma::vec width_a(dim);
+ arma::vec loA(dim);
+ arma::vec widthA(dim);
- lo_a.randu();
- width_a.randu();
+ loA.randu();
+ widthA.randu();
for (size_t j = 0; j < dim; j++)
- a[j] = Range(lo_a[j], lo_a[j] + width_a[j]);
+ a[j] = Range(loA[j], loA[j] + widthA[j]);
// Now run the test on a few points.
for (int j = 0; j < 10; j++)
@@ -884,25 +884,25 @@
* BinarySpaceTree<>::count_. So, let's build a simple tree and make sure they
* are the same.
*/
-BOOST_AUTO_TEST_CASE(tree_count_mismatch)
+BOOST_AUTO_TEST_CASE(TreeCountMismatch)
{
arma::mat dataset = "2.0 5.0 9.0 4.0 8.0 7.0;"
"3.0 4.0 6.0 7.0 1.0 2.0 ";
// Leaf size of 1.
- BinarySpaceTree<HRectBound<2> > root_node(dataset, 1);
+ BinarySpaceTree<HRectBound<2>> rootNode(dataset, 1);
- BOOST_REQUIRE(root_node.Count() == 6);
- BOOST_REQUIRE(root_node.Left()->Count() == 3);
- BOOST_REQUIRE(root_node.Left()->Left()->Count() == 2);
- BOOST_REQUIRE(root_node.Left()->Left()->Left()->Count() == 1);
- BOOST_REQUIRE(root_node.Left()->Left()->Right()->Count() == 1);
- BOOST_REQUIRE(root_node.Left()->Right()->Count() == 1);
- BOOST_REQUIRE(root_node.Right()->Count() == 3);
- BOOST_REQUIRE(root_node.Right()->Left()->Count() == 2);
- BOOST_REQUIRE(root_node.Right()->Left()->Left()->Count() == 1);
- BOOST_REQUIRE(root_node.Right()->Left()->Right()->Count() == 1);
- BOOST_REQUIRE(root_node.Right()->Right()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Count() == 6);
+ BOOST_REQUIRE(rootNode.Left()->Count() == 3);
+ BOOST_REQUIRE(rootNode.Left()->Left()->Count() == 2);
+ BOOST_REQUIRE(rootNode.Left()->Left()->Left()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Left()->Left()->Right()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Left()->Right()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Right()->Count() == 3);
+ BOOST_REQUIRE(rootNode.Right()->Left()->Count() == 2);
+ BOOST_REQUIRE(rootNode.Right()->Left()->Left()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Right()->Left()->Right()->Count() == 1);
+ BOOST_REQUIRE(rootNode.Right()->Right()->Count() == 1);
}
// Forward declaration of methods we need for the next test.
@@ -933,33 +933,33 @@
*
* Then, we do that whole process a handful of times.
*/
-BOOST_AUTO_TEST_CASE(kd_tree_test)
+BOOST_AUTO_TEST_CASE(KdTreeTest)
{
typedef BinarySpaceTree<HRectBound<2> > TreeType;
- size_t max_runs = 10; // Ten total tests.
- size_t point_increments = 1000; // Range is from 2000 points to 11000.
+ size_t maxRuns = 10; // Ten total tests.
+ size_t pointIncrements = 1000; // Range is from 2000 points to 11000.
// We use the default leaf size of 20.
- for(size_t run = 0; run < max_runs; run++)
+ for(size_t run = 0; run < maxRuns; run++)
{
size_t dimensions = run + 2;
- size_t max_points = (run + 1) * point_increments;
+ size_t maxPoints = (run + 1) * pointIncrements;
- size_t size = max_points;
+ size_t size = maxPoints;
arma::mat dataset = arma::mat(dimensions, size);
arma::mat datacopy; // Used to test mappings.
// Mappings for post-sort verification of data.
- std::vector<size_t> new_to_old;
- std::vector<size_t> old_to_new;
+ std::vector<size_t> newToOld;
+ std::vector<size_t> oldToNew;
// Generate data.
dataset.randu();
datacopy = dataset; // Save a copy.
// Build the tree itself.
- TreeType root(dataset, new_to_old, old_to_new);
+ TreeType root(dataset, newToOld, oldToNew);
// Ensure the size of the tree is correct.
BOOST_REQUIRE_EQUAL(root.Count(), size);
@@ -969,8 +969,8 @@
{
for(size_t j = 0; j < dimensions; j++)
{
- BOOST_REQUIRE_EQUAL(dataset(j, i), datacopy(j, new_to_old[i]));
- BOOST_REQUIRE_EQUAL(dataset(j, old_to_new[i]), datacopy(j, i));
+ BOOST_REQUIRE_EQUAL(dataset(j, i), datacopy(j, newToOld[i]));
+ BOOST_REQUIRE_EQUAL(dataset(j, oldToNew[i]), datacopy(j, i));
}
}
@@ -1023,10 +1023,8 @@
// Check that each point which this tree claims is actually inside the tree.
for (size_t index = begin; index < begin + count; index++)
- {
if (!node->Bound().Contains(data.col(index)))
return false;
- }
return CheckPointBounds(left, data) && CheckPointBounds(right, data);
}
@@ -1090,29 +1088,29 @@
typedef BinarySpaceTree<HRectBound<2>, EmptyStatistic, arma::SpMat<double> >
TreeType;
- size_t max_runs = 2; // Two total tests.
- size_t point_increments = 200; // Range is from 200 points to 400.
+ size_t maxRuns = 2; // Two total tests.
+ size_t pointIncrements = 200; // Range is from 200 points to 400.
// We use the default leaf size of 20.
- for(size_t run = 0; run < max_runs; run++)
+ for(size_t run = 0; run < maxRuns; run++)
{
size_t dimensions = run + 2;
- size_t max_points = (run + 1) * point_increments;
+ size_t maxPoints = (run + 1) * pointIncrements;
- size_t size = max_points;
+ size_t size = maxPoints;
arma::SpMat<double> dataset = arma::SpMat<double>(dimensions, size);
arma::SpMat<double> datacopy; // Used to test mappings.
// Mappings for post-sort verification of data.
- std::vector<size_t> new_to_old;
- std::vector<size_t> old_to_new;
+ std::vector<size_t> newToOld;
+ std::vector<size_t> oldToNew;
// Generate data.
dataset.randu();
datacopy = dataset; // Save a copy.
// Build the tree itself.
- TreeType root(dataset, new_to_old, old_to_new);
+ TreeType root(dataset, newToOld, oldToNew);
// Ensure the size of the tree is correct.
BOOST_REQUIRE_EQUAL(root.Count(), size);
@@ -1122,8 +1120,8 @@
{
for(size_t j = 0; j < dimensions; j++)
{
- BOOST_REQUIRE_EQUAL(dataset(j, i), datacopy(j, new_to_old[i]));
- BOOST_REQUIRE_EQUAL(dataset(j, old_to_new[i]), datacopy(j, i));
+ BOOST_REQUIRE_EQUAL(dataset(j, i), datacopy(j, newToOld[i]));
+ BOOST_REQUIRE_EQUAL(dataset(j, oldToNew[i]), datacopy(j, i));
}
}
Modified: mlpack/trunk/src/mlpack/tests/union_find_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/union_find_test.cpp 2011-12-16 14:43:05 UTC (rev 10854)
+++ mlpack/trunk/src/mlpack/tests/union_find_test.cpp 2011-12-16 17:38:39 UTC (rev 10855)
@@ -16,33 +16,33 @@
BOOST_AUTO_TEST_CASE(TestFind)
{
- static const size_t test_size_ = 10;
- UnionFind test_union_find_(test_size_);
+ static const size_t testSize_ = 10;
+ UnionFind testUnionFind_(testSize_);
- for (size_t i = 0; i < test_size_; i++)
- BOOST_REQUIRE(test_union_find_.Find(i) == i);
+ for (size_t i = 0; i < testSize_; i++)
+ BOOST_REQUIRE(testUnionFind_.Find(i) == i);
- test_union_find_.Union(0, 1);
- test_union_find_.Union(1, 2);
+ testUnionFind_.Union(0, 1);
+ testUnionFind_.Union(1, 2);
- BOOST_REQUIRE(test_union_find_.Find(2) == test_union_find_.Find(0));
+ BOOST_REQUIRE(testUnionFind_.Find(2) == testUnionFind_.Find(0));
}
BOOST_AUTO_TEST_CASE(TestUnion)
{
- static const size_t test_size_ = 10;
- UnionFind test_union_find_(test_size_);
+ static const size_t testSize_ = 10;
+ UnionFind testUnionFind_(testSize_);
- test_union_find_.Union(0, 1);
- test_union_find_.Union(2, 3);
- test_union_find_.Union(0, 2);
- test_union_find_.Union(5, 0);
- test_union_find_.Union(0, 6);
+ testUnionFind_.Union(0, 1);
+ testUnionFind_.Union(2, 3);
+ testUnionFind_.Union(0, 2);
+ testUnionFind_.Union(5, 0);
+ testUnionFind_.Union(0, 6);
- BOOST_REQUIRE(test_union_find_.Find(0) == test_union_find_.Find(1));
- BOOST_REQUIRE(test_union_find_.Find(2) == test_union_find_.Find(3));
- BOOST_REQUIRE(test_union_find_.Find(1) == test_union_find_.Find(5));
- BOOST_REQUIRE(test_union_find_.Find(6) == test_union_find_.Find(3));
+ BOOST_REQUIRE(testUnionFind_.Find(0) == testUnionFind_.Find(1));
+ BOOST_REQUIRE(testUnionFind_.Find(2) == testUnionFind_.Find(3));
+ BOOST_REQUIRE(testUnionFind_.Find(1) == testUnionFind_.Find(5));
+ BOOST_REQUIRE(testUnionFind_.Find(6) == testUnionFind_.Find(3));
}
BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-svn
mailing list