[mlpack-git] master: Merge pull request #661 from rcurtin/keontests (a2440f1)
gitdub at mlpack.org
gitdub at mlpack.org
Fri Jun 3 12:35:12 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/ee95e2030ddd526368e377b4e1c13484d471e307...a2440f163ac76edda36a9f7ba31cfecd3a55654e
>---------------------------------------------------------------
commit a2440f163ac76edda36a9f7ba31cfecd3a55654e
Merge: ee95e20 b3fc468
Author: Ryan Curtin <ryan at ratml.org>
Date: Fri Jun 3 12:35:12 2016 -0400
Merge pull request #661 from rcurtin/keontests
More tests for DatasetInfo
>---------------------------------------------------------------
a2440f163ac76edda36a9f7ba31cfecd3a55654e
src/mlpack/tests/load_save_test.cpp | 42 +++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --cc src/mlpack/tests/load_save_test.cpp
index 1935083,ecb089c..3917aea
--- a/src/mlpack/tests/load_save_test.cpp
+++ b/src/mlpack/tests/load_save_test.cpp
@@@ -1226,142 -1093,49 +1226,184 @@@ BOOST_AUTO_TEST_CASE(CategoricalNontran
remove("test.csv");
}
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest01)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << " , 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f.close();
+
+ // Load the test CSV.
+ arma::umat matrix;
+ DatasetInfo info;
+ data::Load("test.csv", matrix, info, true, false); // No transpose.
+
+ BOOST_REQUIRE_EQUAL(matrix.n_cols, 3);
+ BOOST_REQUIRE_EQUAL(matrix.n_rows, 4);
+
+ BOOST_REQUIRE_EQUAL(matrix(0, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 0), 0);
+ BOOST_REQUIRE_EQUAL(matrix(2, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 2), 1);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(1) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(2) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("", 2), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 2), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 2), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 2), "1");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest02)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "1, 1, 1" << endl;
+ f << ", 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f.close();
+
+ // Load the test CSV.
+ arma::umat matrix;
+ DatasetInfo info;
+ data::Load("test.csv", matrix, info, true, false); // No transpose.
+
+ BOOST_REQUIRE_EQUAL(matrix.n_cols, 3);
+ BOOST_REQUIRE_EQUAL(matrix.n_rows, 4);
+
+ BOOST_REQUIRE_EQUAL(matrix(0, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 0);
+ BOOST_REQUIRE_EQUAL(matrix(1, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 2), 1);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(1) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("", 1), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 1), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 1), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 1), "1");
+
+ remove("test.csv");
+}
+
+BOOST_AUTO_TEST_CASE(CategoricalNontransposedCSVLoadTest03)
+{
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << ", 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f << "1, 1, 1" << endl;
+ f.close();
+
+ // Load the test CSV.
+ arma::umat matrix;
+ DatasetInfo info;
+ data::Load("test.csv", matrix, info, true, false); // No transpose.
+
+ BOOST_REQUIRE_EQUAL(matrix.n_cols, 3);
+ BOOST_REQUIRE_EQUAL(matrix.n_rows, 4);
+
+ BOOST_REQUIRE_EQUAL(matrix(0, 0), 0);
+ BOOST_REQUIRE_EQUAL(matrix(0, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(0, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(1, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(2, 2), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 0), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 1), 1);
+ BOOST_REQUIRE_EQUAL(matrix(3, 2), 1);
+
+ BOOST_REQUIRE(info.Type(0) == Datatype::categorical);
+ BOOST_REQUIRE(info.Type(1) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(2) == Datatype::numeric);
+ BOOST_REQUIRE(info.Type(3) == Datatype::numeric);
+
+ BOOST_REQUIRE_EQUAL(info.MapString("", 1), 0);
+ BOOST_REQUIRE_EQUAL(info.MapString("1", 1), 1);
+
+ BOOST_REQUIRE_EQUAL(info.UnmapString(0, 1), "");
+ BOOST_REQUIRE_EQUAL(info.UnmapString(1, 1), "1");
+
+ remove("test.csv");
+}
+
/**
+ * A harder test CSV based on the concerns in #658.
+ */
+ BOOST_AUTO_TEST_CASE(HarderKeonTest)
+ {
+ fstream f;
+ f.open("test.csv", fstream::out);
+ f << "a,, 13,\t, 0" << endl;
+ f << "b, 3, 14, hello,1" << endl;
+ f << "b, 4, 15, , 2" << endl;
+ f << ", 5, 16, ," << endl;
+ f.close();
+
+ // Load transposed.
+ arma::mat dataset;
+ data::DatasetInfo info;
+ data::Load("test.csv", dataset, info, true, true);
+
+ BOOST_REQUIRE_EQUAL(dataset.n_rows, 5);
+ BOOST_REQUIRE_EQUAL(dataset.n_cols, 4);
+
+ BOOST_REQUIRE_EQUAL(info.Dimensionality(), 5);
+ BOOST_REQUIRE_EQUAL(info.NumMappings(0), 3);
+ BOOST_REQUIRE_EQUAL(info.NumMappings(1), 4);
+ BOOST_REQUIRE_EQUAL(info.NumMappings(2), 0);
+ BOOST_REQUIRE_EQUAL(info.NumMappings(3), 2); // \t and "" are equivalent.
+ BOOST_REQUIRE_EQUAL(info.NumMappings(4), 4);
+
+ // Now load non-transposed.
+ data::DatasetInfo ntInfo;
+ data::Load("test.csv", dataset, ntInfo, true, false);
+
+ BOOST_REQUIRE_EQUAL(dataset.n_rows, 4);
+ BOOST_REQUIRE_EQUAL(dataset.n_cols, 5);
+
+ BOOST_REQUIRE_EQUAL(ntInfo.Dimensionality(), 4);
+ BOOST_REQUIRE_EQUAL(ntInfo.NumMappings(0), 4);
+ BOOST_REQUIRE_EQUAL(ntInfo.NumMappings(1), 5);
+ BOOST_REQUIRE_EQUAL(ntInfo.NumMappings(2), 5);
+ BOOST_REQUIRE_EQUAL(ntInfo.NumMappings(3), 3);
+ }
+
+ /**
* A simple ARFF load test. Two attributes, both numeric.
*/
BOOST_AUTO_TEST_CASE(SimpleARFFTest)
More information about the mlpack-git
mailing list