[mlpack-svn] master: Add test for the init rules. (7c8c6cd)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Tue Jan 6 14:21:03 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/6b14d78fc09cb205ffa7a297f5e6310b2ad83e25...9147fd3ee8072669c18422de4ea6fbe8f964b423
>---------------------------------------------------------------
commit 7c8c6cd7c46297cc4177765629a8b47541ea05f5
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Mon Jan 5 11:51:36 2015 +0100
Add test for the init rules.
>---------------------------------------------------------------
7c8c6cd7c46297cc4177765629a8b47541ea05f5
src/mlpack/tests/init_rules_test.cpp | 75 ++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/src/mlpack/tests/init_rules_test.cpp b/src/mlpack/tests/init_rules_test.cpp
new file mode 100644
index 0000000..b986452
--- /dev/null
+++ b/src/mlpack/tests/init_rules_test.cpp
@@ -0,0 +1,75 @@
+/**
+ * @file init_rules_test.cpp
+ * @author Marcus Edel
+ *
+ * Tests for the various weight initialize methods.
+ */
+#include <mlpack/core.hpp>
+
+#include <mlpack/methods/ann/init_rules/random_init.hpp>
+#include <mlpack/methods/ann/init_rules/orthogonal_init.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+using namespace mlpack::ann;
+
+BOOST_AUTO_TEST_SUITE(InitRulesTest);
+
+// Be careful! When writing new tests, always get the boolean value and store
+// it in a temporary, because the Boost unit test macros do weird things and
+// will cause bizarre problems.
+
+// Test the RandomInitialization class with a constant value.
+BOOST_AUTO_TEST_CASE(ConstantInitTest)
+{
+ arma::mat weights;
+ RandomInitialization<> constantInit(1, 1);
+ constantInit.Initialize(weights, 100, 100);
+
+ bool b = arma::all(arma::vectorise(weights) == 1);
+ BOOST_REQUIRE_EQUAL(b, 1);
+}
+
+// Test the OrthogonalInitialization class.
+BOOST_AUTO_TEST_CASE(OrthogonalInitTest)
+{
+ arma::mat weights;
+ OrthogonalInitialization<> orthogonalInit;
+ orthogonalInit.Initialize(weights, 100, 200);
+
+ arma::mat orthogonalWeights = arma::eye<arma::mat>(100, 100);
+ weights *= weights.t();
+
+ for (size_t i = 0; i < weights.n_rows; i++)
+ for (size_t j = 0; j < weights.n_cols; j++)
+ BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3);
+
+ orthogonalInit.Initialize(weights, 200, 100);
+ weights = weights.t() * weights;
+
+ for (size_t i = 0; i < weights.n_rows; i++)
+ for (size_t j = 0; j < weights.n_cols; j++)
+ BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3);
+}
+
+// Test the OrthogonalInitialization class with a non default gain.
+BOOST_AUTO_TEST_CASE(OrthogonalInitGainTest)
+{
+ arma::mat weights;
+
+ const double gain = 2;
+ OrthogonalInitialization<> orthogonalInit(gain);
+ orthogonalInit.Initialize(weights, 100, 200);
+
+ arma::mat orthogonalWeights = arma::eye<arma::mat>(100, 100);
+ orthogonalWeights *= (gain * gain);
+ weights *= weights.t();
+
+ for (size_t i = 0; i < weights.n_rows; i++)
+ for (size_t j = 0; j < weights.n_cols; j++)
+ BOOST_REQUIRE_SMALL(weights.at(i, j) - orthogonalWeights.at(i, j), 1e-3);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
More information about the mlpack-git
mailing list