[mlpack-svn] master: Add connection and layer traits test. (de369e1)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue Jan 6 14:20:56 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/6b14d78fc09cb205ffa7a297f5e6310b2ad83e25...9147fd3ee8072669c18422de4ea6fbe8f964b423

>---------------------------------------------------------------

commit de369e12364716a133fec9ca8a056f1046e7f163
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Sun Jan 4 15:44:31 2015 +0100

    Add connection and layer traits test.


>---------------------------------------------------------------

de369e12364716a133fec9ca8a056f1046e7f163
 src/mlpack/tests/connection_traits_test.cpp | 82 +++++++++++++++++++++++++++++
 src/mlpack/tests/layer_traits_test.cpp      | 68 ++++++++++++++++++++++++
 2 files changed, 150 insertions(+)

diff --git a/src/mlpack/tests/connection_traits_test.cpp b/src/mlpack/tests/connection_traits_test.cpp
new file mode 100644
index 0000000..effa58f
--- /dev/null
+++ b/src/mlpack/tests/connection_traits_test.cpp
@@ -0,0 +1,82 @@
+/**
+ * @file connection_traits_test.cpp
+ * @author Marcus Edel
+ *
+ * Test the ConnectionTraits class. Because all of the values are known at
+ * compile time, this test is meant to ensure that uses of ConnectionTraits
+ * still compile okay and react as expected.
+ */
+#include <mlpack/core.hpp>
+
+#include <mlpack/methods/ann/connections/connection_traits.hpp>
+#include <mlpack/methods/ann/connections/self_connection.hpp>
+#include <mlpack/methods/ann/connections/fullself_connection.hpp>
+#include <mlpack/methods/ann/layer/neuron_layer.hpp>
+#include <mlpack/methods/ann/optimizer/irpropp.hpp>
+#include <mlpack/methods/ann/init_rules/random_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(ConnectionTraitsTest);
+
+// 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 defaults.
+BOOST_AUTO_TEST_CASE(DefaultsTraitsTest)
+{
+  // An irrelevant non-connection type class is used here so that the default
+  // implementation of ConnectionTraits is chosen.
+  bool b = ConnectionTraits<int>::IsSelfConnection;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b = ConnectionTraits<int>::IsFullselfConnection;
+  BOOST_REQUIRE_EQUAL(b, false);
+}
+
+// Test the SelfConnection traits.
+BOOST_AUTO_TEST_CASE(SelfConnectionTraitsTest)
+{
+  NeuronLayer<> recurrentLayer(1);
+  NeuronLayer<> hiddenLayer(1);
+  iRPROPp<> conOptimizer(1, 1);
+
+  SelfConnection<
+    decltype(recurrentLayer),
+    decltype(hiddenLayer),
+    decltype(conOptimizer)>
+    layerCon(recurrentLayer, hiddenLayer, conOptimizer);
+
+  bool b = ConnectionTraits<decltype(layerCon)>::IsSelfConnection;
+  BOOST_REQUIRE_EQUAL(b, true);
+
+  b = ConnectionTraits<decltype(layerCon)>::IsFullselfConnection;
+  BOOST_REQUIRE_EQUAL(b, false);
+}
+
+// Test the FullselfConnection traits.
+BOOST_AUTO_TEST_CASE(FullselfConnectionTraitsTest)
+{
+  NeuronLayer<> recurrentLayer(1);
+  NeuronLayer<> hiddenLayer(1);
+  iRPROPp<> conOptimizer(1, 1);
+
+  FullselfConnection<
+    decltype(recurrentLayer),
+    decltype(hiddenLayer),
+    decltype(conOptimizer)>
+    layerCon(recurrentLayer, hiddenLayer, conOptimizer);
+
+  bool b = ConnectionTraits<decltype(layerCon)>::IsSelfConnection;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b = ConnectionTraits<decltype(layerCon)>::IsFullselfConnection;
+  BOOST_REQUIRE_EQUAL(b, true);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
diff --git a/src/mlpack/tests/layer_traits_test.cpp b/src/mlpack/tests/layer_traits_test.cpp
new file mode 100644
index 0000000..8096958
--- /dev/null
+++ b/src/mlpack/tests/layer_traits_test.cpp
@@ -0,0 +1,68 @@
+/**
+ * @file layer_traits_test.cpp
+ * @author Marcus Edel
+ *
+ * Test the LayerTraits class. Because all of the values are known at compile
+ * time, this test is meant to ensure that uses of LayerTraits still compile
+ * okay and react as expected.
+ */
+#include <mlpack/core.hpp>
+
+#include <mlpack/methods/ann/layer/layer_traits.hpp>
+#include <mlpack/methods/ann/layer/bias_layer.hpp>
+#include <mlpack/methods/ann/layer/multiclass_classification_layer.hpp>
+
+#include <boost/test/unit_test.hpp>
+#include "old_boost_test_definitions.hpp"
+
+using namespace mlpack;
+using namespace mlpack::ann;
+
+BOOST_AUTO_TEST_SUITE(LayerTraitsTest);
+
+// 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 defaults.
+BOOST_AUTO_TEST_CASE(DefaultsTraitsTest)
+{
+  // An irrelevant non-connection type class is used here so that the default
+  // implementation of ConnectionTraits is chosen.
+  bool b = LayerTraits<int>::IsBinary;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b =  LayerTraits<int>::IsOutputLayer;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b =  LayerTraits<int>::IsBiasLayer;
+  BOOST_REQUIRE_EQUAL(b, false);
+}
+
+// Test the BiasLayer traits.
+BOOST_AUTO_TEST_CASE(BiasLayerTraitsTest)
+{
+  bool b = LayerTraits<BiasLayer<> >::IsBinary;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b = LayerTraits<BiasLayer<> >::IsOutputLayer;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b = LayerTraits<BiasLayer<> >::IsBiasLayer;
+  BOOST_REQUIRE_EQUAL(b, true);
+}
+
+// Test the MulticlassClassificationLayer traits.
+BOOST_AUTO_TEST_CASE(MulticlassClassificationLayerTraitsTest)
+{
+  bool b = LayerTraits<MulticlassClassificationLayer<> >::IsBinary;
+  BOOST_REQUIRE_EQUAL(b, false);
+
+  b = LayerTraits<MulticlassClassificationLayer<> >::IsOutputLayer;
+  BOOST_REQUIRE_EQUAL(b, true);
+
+  b = LayerTraits<MulticlassClassificationLayer<> >::IsBiasLayer;
+  BOOST_REQUIRE_EQUAL(b, false);
+}
+
+BOOST_AUTO_TEST_SUITE_END();




More information about the mlpack-git mailing list