[mlpack-svn] r14240 - mlpack/branches/mlpack-1.x/src/mlpack/tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Feb 8 15:38:18 EST 2013
Author: rcurtin
Date: 2013-02-08 15:38:18 -0500 (Fri, 08 Feb 2013)
New Revision: 14240
Modified:
mlpack/branches/mlpack-1.x/src/mlpack/tests/gmm_test.cpp
mlpack/branches/mlpack-1.x/src/mlpack/tests/kmeans_test.cpp
mlpack/branches/mlpack-1.x/src/mlpack/tests/nca_test.cpp
mlpack/branches/mlpack-1.x/src/mlpack/tests/radical_test.cpp
mlpack/branches/mlpack-1.x/src/mlpack/tests/sgd_test.cpp
Log:
Update tests to newest versions.
Modified: mlpack/branches/mlpack-1.x/src/mlpack/tests/gmm_test.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/tests/gmm_test.cpp 2013-02-08 20:36:10 UTC (rev 14239)
+++ mlpack/branches/mlpack-1.x/src/mlpack/tests/gmm_test.cpp 2013-02-08 20:38:18 UTC (rev 14240)
@@ -201,7 +201,7 @@
// Now, train the model.
GMM<> gmm(1, 2);
- gmm.Estimate(data, 10);
+ double likelihood = gmm.Estimate(data, 10);
arma::vec actualMean = arma::mean(data, 1);
arma::mat actualCovar = ccov(data, 1 /* biased estimator */);
@@ -291,7 +291,7 @@
// Now train the model.
GMM<> gmm(gaussians, dims);
- gmm.Estimate(data, 10);
+ double likelihood = gmm.Estimate(data, 10);
arma::uvec sortRef = sort_index(weights);
arma::uvec sortTry = sort_index(gmm.Weights());
@@ -334,7 +334,7 @@
// Now train the model.
GMM<> g(1, 2);
- g.Estimate(observations, probabilities, 10);
+ double likelihood = g.Estimate(observations, probabilities, 10);
// Check that it is trained correctly. 7% tolerance because of random error
// present in observations.
@@ -407,7 +407,7 @@
// Now train the model.
GMM<> g(4, 3); // 3 dimensions, 4 components.
- g.Estimate(points, probabilities, 8);
+ double likelihood = g.Estimate(points, probabilities, 8);
// Now check the results. We need to order by weights so that when we do the
// checking, things will be correct.
@@ -487,7 +487,7 @@
// A new one which we'll train.
GMM<> gmm2(2, 2);
- gmm2.Estimate(observations, 10);
+ double likelihood = gmm2.Estimate(observations, 10);
// Now check the results. We need to order by weights so that when we do the
// checking, things will be correct.
Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/tests/gmm_test.cpp
___________________________________________________________________
Added: svn:mergeinfo
+ /mlpack/trunk/src/mlpack/tests/gmm_test.cpp:13981-14239
Modified: mlpack/branches/mlpack-1.x/src/mlpack/tests/kmeans_test.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/tests/kmeans_test.cpp 2013-02-08 20:36:10 UTC (rev 14239)
+++ mlpack/branches/mlpack-1.x/src/mlpack/tests/kmeans_test.cpp 2013-02-08 20:38:18 UTC (rev 14240)
@@ -207,6 +207,9 @@
}
#ifdef ARMA_HAS_SPMAT
+// Can't do this test on Armadillo 3.4; var(SpBase) is not implemented.
+#if !((ARMA_VERSION_MAJOR == 3) && (ARMA_VERSION_MINOR == 4))
+
/**
* Make sure sparse k-means works okay.
*/
@@ -249,6 +252,7 @@
BOOST_REQUIRE_EQUAL(assignments[10], clusterTwo);
BOOST_REQUIRE_EQUAL(assignments[11], clusterTwo);
}
+#endif // Exclude Armadillo 3.4.
#endif // ARMA_HAS_SPMAT
BOOST_AUTO_TEST_SUITE_END();
Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/tests/kmeans_test.cpp
___________________________________________________________________
Added: svn:mergeinfo
+ /mlpack/trunk/src/mlpack/tests/kmeans_test.cpp:13981-14239
Modified: mlpack/branches/mlpack-1.x/src/mlpack/tests/nca_test.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/tests/nca_test.cpp 2013-02-08 20:36:10 UTC (rev 14239)
+++ mlpack/branches/mlpack-1.x/src/mlpack/tests/nca_test.cpp 2013-02-08 20:38:18 UTC (rev 14240)
@@ -8,6 +8,7 @@
#include <mlpack/core.hpp>
#include <mlpack/core/metrics/lmetric.hpp>
#include <mlpack/methods/nca/nca.hpp>
+#include <mlpack/core/optimizers/lbfgs/lbfgs.hpp>
#include <boost/test/unit_test.hpp>
#include "old_boost_test_definitions.hpp"
@@ -15,6 +16,7 @@
using namespace mlpack;
using namespace mlpack::metric;
using namespace mlpack::nca;
+using namespace mlpack::optimization;
//
// Tests for the SoftmaxErrorFunction
@@ -250,7 +252,7 @@
* On our simple dataset, ensure that the NCA algorithm fully separates the
* points.
*/
-BOOST_AUTO_TEST_CASE(NcaSimpleDataset)
+BOOST_AUTO_TEST_CASE(NCASGDSimpleDataset)
{
// 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;"
@@ -278,10 +280,42 @@
// finalObj must be less than initObj.
BOOST_REQUIRE_LT(finalObj, initObj);
// Verify that final objective is optimal.
+ BOOST_REQUIRE_CLOSE(finalObj, -6.0, 0.005);
+ // 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(finalGradient, 2), 1e-4);
+}
+
+BOOST_AUTO_TEST_CASE(NCALBFGSSimpleDataset)
+{
+ // 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;"
+ " 1.0 0.0 -1.0 1.0 0.0 -1.0 ";
+ arma::uvec labels = " 0 0 0 1 1 1 ";
+
+ // Huge learning rate because this is so simple.
+ NCA<SquaredEuclideanDistance, L_BFGS> nca(data, labels);
+ nca.Optimizer().NumBasis() = 5;
+
+ arma::mat outputMatrix;
+ nca.LearnDistance(outputMatrix);
+
+ // Ensure that the objective function is better now.
+ SoftmaxErrorFunction<SquaredEuclideanDistance> sef(data, labels);
+
+ double initObj = sef.Evaluate(arma::eye<arma::mat>(2, 2));
+ double finalObj = sef.Evaluate(outputMatrix);
+ arma::mat finalGradient;
+ sef.Gradient(outputMatrix, finalGradient);
+
+ // finalObj must be less than initObj.
+ BOOST_REQUIRE_LT(finalObj, initObj);
+ // Verify that final objective is optimal.
BOOST_REQUIRE_CLOSE(finalObj, -6.0, 1e-5);
// 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(finalGradient, 2), 1e-6);
+
}
BOOST_AUTO_TEST_SUITE_END();
Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/tests/nca_test.cpp
___________________________________________________________________
Added: svn:mergeinfo
+ /mlpack/trunk/src/mlpack/tests/nca_test.cpp:13981-14239
Modified: mlpack/branches/mlpack-1.x/src/mlpack/tests/radical_test.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/tests/radical_test.cpp 2013-02-08 20:36:10 UTC (rev 14239)
+++ mlpack/branches/mlpack-1.x/src/mlpack/tests/radical_test.cpp 2013-02-08 20:38:18 UTC (rev 14240)
@@ -17,48 +17,40 @@
using namespace std;
using namespace arma;
-BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D) {
+BOOST_AUTO_TEST_CASE(Radical_Test_Radical3D)
+{
mat matX;
data::Load("data_3d_mixed.txt", matX);
- radical::Radical rad(0.175, 5, 100, matX.n_rows - 1);
-
+ 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(uword i = 0; i < matYT.n_cols; i++)
+
+ for (uword 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 (uword i = 0; i < matYT.n_cols; i++)
+
+ for (uword 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);
- printf("\n\nabs(valBest - valEst) = %f\n", fabs(valBest - valEst));
- 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();
Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/tests/radical_test.cpp
___________________________________________________________________
Added: svn:mergeinfo
+ /mlpack/trunk/src/mlpack/tests/radical_test.cpp:13981-14239
Modified: mlpack/branches/mlpack-1.x/src/mlpack/tests/sgd_test.cpp
===================================================================
--- mlpack/branches/mlpack-1.x/src/mlpack/tests/sgd_test.cpp 2013-02-08 20:36:10 UTC (rev 14239)
+++ mlpack/branches/mlpack-1.x/src/mlpack/tests/sgd_test.cpp 2013-02-08 20:38:18 UTC (rev 14240)
@@ -49,7 +49,7 @@
BOOST_REQUIRE_SMALL(result, 1e-10);
for (size_t j = 0; j < i; ++j)
- BOOST_REQUIRE_CLOSE(coordinates[j], 1.0, 1e-3);
+ BOOST_REQUIRE_CLOSE(coordinates[j], (double) 1.0, 1e-3);
}
}
Property changes on: mlpack/branches/mlpack-1.x/src/mlpack/tests/sgd_test.cpp
___________________________________________________________________
Added: svn:mergeinfo
+ /mlpack/trunk/src/mlpack/tests/sgd_test.cpp:13981-14239
More information about the mlpack-svn
mailing list