[mlpack-git] master: Add test for the init rules. (1a36310)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:10:32 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 1a36310cd6bf24a33dfe5294e1275987af91d492
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Mon Jan 5 11:51:36 2015 +0100
Add test for the init rules.
>---------------------------------------------------------------
1a36310cd6bf24a33dfe5294e1275987af91d492
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