[mlpack-git] master: Add tests for DatasetInfo. (59d841b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Wed Dec 23 11:41:36 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/de9cc4b05069e1fa4793d9355f2f595af5ff45d2...6070527af14296cd99739de6c62666cc5d2a2125

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

commit 59d841bab4ab8127afdc98388545d636c90ebf9e
Author: ryan <ryan at ratml.org>
Date:   Wed Sep 9 10:19:15 2015 -0400

    Add tests for DatasetInfo.


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

59d841bab4ab8127afdc98388545d636c90ebf9e
 src/mlpack/core.hpp                 |  1 +
 src/mlpack/core/data/CMakeLists.txt |  2 ++
 src/mlpack/tests/load_save_test.cpp | 51 +++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/src/mlpack/core.hpp b/src/mlpack/core.hpp
index 46dc1ec..df7657b 100644
--- a/src/mlpack/core.hpp
+++ b/src/mlpack/core.hpp
@@ -159,6 +159,7 @@
 #include <mlpack/core/data/load.hpp>
 #include <mlpack/core/data/save.hpp>
 #include <mlpack/core/data/normalize_labels.hpp>
+#include <mlpack/core/data/dataset_info.hpp>
 #include <mlpack/core/math/clamp.hpp>
 #include <mlpack/core/math/random.hpp>
 #include <mlpack/core/math/lin_alg.hpp>
diff --git a/src/mlpack/core/data/CMakeLists.txt b/src/mlpack/core/data/CMakeLists.txt
index 188736d..6fd0aef 100644
--- a/src/mlpack/core/data/CMakeLists.txt
+++ b/src/mlpack/core/data/CMakeLists.txt
@@ -1,6 +1,8 @@
 # Define the files that we need to compile.
 # Anything not in this list will not be compiled into MLPACK.
 set(SOURCES
+  dataset_info.hpp
+  dataset_info_impl.hpp
   extension.hpp
   format.hpp
   load.hpp
diff --git a/src/mlpack/tests/load_save_test.cpp b/src/mlpack/tests/load_save_test.cpp
index 646cdd1..f78b732 100644
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@ -12,6 +12,7 @@
 #include "old_boost_test_definitions.hpp"
 
 using namespace mlpack;
+using namespace mlpack::data;
 
 BOOST_AUTO_TEST_SUITE(LoadSaveTest);
 
@@ -809,5 +810,55 @@ BOOST_AUTO_TEST_CASE(LoadTextTest)
   BOOST_REQUIRE_EQUAL(y.inb.s, x.inb.s);
 }
 
+/**
+ * Test DatasetInfo by making a map for a dimension.
+ */
+BOOST_AUTO_TEST_CASE(DatasetInfoTest)
+{
+  DatasetInfo di;
+
+  // Do all types default to numeric?
+  for (size_t i = 0; i < 100; ++i)
+  {
+    BOOST_REQUIRE_EQUAL((DatasetInfo::Datatype) di.Type(i),
+        DatasetInfo::Datatype::NUMERIC);
+    BOOST_REQUIRE_EQUAL(di.NumMappings(i), 0);
+  }
+
+  // Okay.  Add some mappings for dimension 3.
+  const size_t first = di.MapString("test_mapping_1", 3);
+  const size_t second = di.MapString("test_mapping_2", 3);
+  const size_t third = di.MapString("test_mapping_3", 3);
+
+  BOOST_REQUIRE_EQUAL(first, 0);
+  BOOST_REQUIRE_EQUAL(second, 1);
+  BOOST_REQUIRE_EQUAL(third, 2);
+
+  // Now dimension 3 should be categorical.
+  for (size_t i = 0; i < 100; ++i)
+  {
+    if (i == 3)
+    {
+      BOOST_REQUIRE_EQUAL((DatasetInfo::Datatype) di.Type(i),
+          DatasetInfo::Datatype::CATEGORICAL);
+      BOOST_REQUIRE_EQUAL(di.NumMappings(i), 3);
+    }
+    else
+    {
+      BOOST_REQUIRE_EQUAL((DatasetInfo::Datatype) di.Type(i),
+          DatasetInfo::Datatype::NUMERIC);
+      BOOST_REQUIRE_EQUAL(di.NumMappings(i), 0);
+    }
+  }
+
+  // Get the mappings back.
+  const std::string& strFirst = di.UnmapString(first, 3);
+  const std::string& strSecond = di.UnmapString(second, 3);
+  const std::string& strThird = di.UnmapString(third, 3);
+
+  BOOST_REQUIRE_EQUAL(strFirst, "test_mapping_1");
+  BOOST_REQUIRE_EQUAL(strSecond, "test_mapping_2");
+  BOOST_REQUIRE_EQUAL(strThird, "test_mapping_3");
+}
 
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-git mailing list