[mlpack-git] master: Revert DETTest. (e0191b7)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Tue Nov 24 13:54:00 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/0dc380de64b6b087d025c63618b8d6f00abe7545...4f97fdfb7e158025283c2652084af670bc6e2d76

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

commit e0191b7d705fa3b7721224b0bc42b2376630ec2d
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Nov 24 13:39:56 2015 -0500

    Revert DETTest.


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

e0191b7d705fa3b7721224b0bc42b2376630ec2d
 src/mlpack/tests/serialization_test.cpp | 436 ++++++++++++++++----------------
 1 file changed, 222 insertions(+), 214 deletions(-)

diff --git a/src/mlpack/tests/serialization_test.cpp b/src/mlpack/tests/serialization_test.cpp
index bdc896b..dbef1de 100644
--- a/src/mlpack/tests/serialization_test.cpp
+++ b/src/mlpack/tests/serialization_test.cpp
@@ -59,7 +59,7 @@ template<typename MatType,
 void TestArmadilloSerialization(MatType& x)
 {
   // First save it.
-  ofstream ofs("test",ios::binary);
+  ofstream ofs("test", ios::binary);
   OArchiveType o(ofs);
 
   bool success = true;
@@ -78,7 +78,7 @@ void TestArmadilloSerialization(MatType& x)
   // Now load it.
   MatType orig(x);
   success = true;
-  ifstream ifs("test",ios::binary);
+  ifstream ifs("test", ios::binary);
   IArchiveType i(ifs);
 
   try
@@ -193,40 +193,38 @@ BOOST_AUTO_TEST_CASE(EmptySparseMatrixSerializeTest)
 // The re-loaded copy is placed in 'newT'.
 template<typename T, typename IArchiveType, typename OArchiveType>
 void SerializeObject(T& t, T& newT)
-	{
-	ofstream ofs("test", ios::binary);
-	OArchiveType o(ofs);
-
-	bool success = true;
-	try
-		{
-		o << data::CreateNVP(t, "t");
-		}
-	catch (archive_exception& e)
-		{
-		success = false;
-		}
-	ofs.close();
-
-	BOOST_REQUIRE_EQUAL(success, true);
+{
+  ofstream ofs("test", ios::binary);
+  OArchiveType o(ofs);
 
-	ifstream ifs("test", ios::binary);
-	IArchiveType i(ifs);
+  bool success = true;
+  try
+  {
+    o << data::CreateNVP(t, "t");
+  }
+  catch (archive_exception& e)
+  {
+    success = false;
+  }
+  ofs.close();
 
-	try
-		{
-		i >> data::CreateNVP(newT, "t");
-		}
-	catch (archive_exception& e)
-		{
-		success = false;
-		}
-	ifs.close();
+  BOOST_REQUIRE_EQUAL(success, true);
 
-	BOOST_REQUIRE_EQUAL(success, true);
-	}
+  ifstream ifs("test", ios::binary);
+  IArchiveType i(ifs);
 
+  try
+  {
+    i >> data::CreateNVP(newT, "t");
+  }
+  catch (archive_exception& e)
+  {
+    success = false;
+  }
+  ifs.close();
 
+  BOOST_REQUIRE_EQUAL(success, true);
+}
 
 // Test mlpack serialization with all three archive types.
 template<typename T>
@@ -241,7 +239,7 @@ void SerializeObjectAll(T& t, T& xmlT, T& textT, T& binaryT)
 template<typename T, typename IArchiveType, typename OArchiveType>
 void SerializePointerObject(T* t, T*& newT)
 {
-  ofstream ofs("test",ios::binary);
+  ofstream ofs("test", ios::binary);
   OArchiveType o(ofs);
 
   bool success = true;
@@ -257,7 +255,7 @@ void SerializePointerObject(T* t, T*& newT)
 
   BOOST_REQUIRE_EQUAL(success, true);
 
-  ifstream ifs("test",ios::binary);
+  ifstream ifs("test", ios::binary);
   IArchiveType i(ifs);
 
   try
@@ -1052,208 +1050,218 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionTest)
       srBinary.Parameters());
 }
 
+BOOST_AUTO_TEST_CASE(DETTest)
+{
+  using det::DTree;
 
-template<class T, class U>
-void TestStack(T& stack, U& Stack)
-	{
-	using det::DTree;
-	while (!stack.empty())
-		{
-		// Get the top node from the stack.
-		DTree* node = stack.top();
-		DTree* Node = Stack.top();
-
-		stack.pop();
-		Stack.pop();
-
-		// Check that all the members are the same.
-		BOOST_REQUIRE_EQUAL(node->Start(), Node->Start());
-
-		BOOST_REQUIRE_EQUAL(node->End(), Node->End());
-
-		BOOST_REQUIRE_EQUAL(node->SplitDim(), Node->SplitDim());
-
-		if (std::abs(node->SplitValue()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->SplitValue(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->SplitValue(), Node->SplitValue(), 1e-5);
-			}
-
-		if (std::abs(node->LogNegError()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->LogNegError(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->LogNegError(), Node->LogNegError(), 1e-5);
-			}
-
-		if (std::abs(node->SubtreeLeavesLogNegError()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->SubtreeLeavesLogNegError(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->SubtreeLeavesLogNegError(),
-				Node->SubtreeLeavesLogNegError(), 1e-5);
-			}
-
-		BOOST_REQUIRE_EQUAL(node->SubtreeLeaves(), Node->SubtreeLeaves());
-
-		if (std::abs(node->Ratio()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->Ratio(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->Ratio(), Node->Ratio(), 1e-5);
-			}
-
-		if (std::abs(node->LogVolume()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->LogVolume(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->LogVolume(), Node->LogVolume(), 1e-5);
-			}
-
-		if (node->Left() == NULL)
-			{
-			BOOST_REQUIRE(Node->Left() == NULL);
-			}
-		else
-			{
-			BOOST_REQUIRE(Node->Left() != NULL);
-
-			// Push children onto stack.
-			stack.push(node->Left());
-			Stack.push(Node->Left());
-			}
-
-		if (node->Right() == NULL)
-			{
-			BOOST_REQUIRE(Node->Right() == NULL);
-			}
-		else
-			{
-			BOOST_REQUIRE(Node->Right() != NULL);
-
-			// Push children onto stack.
-			stack.push(node->Right());
-			Stack.push(Node->Right());
-			}
-
-		BOOST_REQUIRE_EQUAL(node->Root(), Node->Root());
-
-		if (std::abs(node->AlphaUpper()) < 1e-5)
-			{
-			BOOST_REQUIRE_SMALL(Node->AlphaUpper(), 1e-5);
-			}
-		else
-			{
-			BOOST_REQUIRE_CLOSE(node->AlphaUpper(), Node->AlphaUpper(), 1e-5);
-			}
-
-		BOOST_REQUIRE_EQUAL(node->MaxVals().n_elem, Node->MaxVals().n_elem);
-		for (size_t i = 0; i < node->MaxVals().n_elem; ++i)
-			{
-			if (std::abs(node->MaxVals()[i]) < 1e-5)
-				{
-				BOOST_REQUIRE_SMALL(Node->MaxVals()[i], 1e-5);
-				}
-			else
-				{
-				BOOST_REQUIRE_CLOSE(node->MaxVals()[i], Node->MaxVals()[i], 1e-5);
-				}
-			}
-
-		BOOST_REQUIRE_EQUAL(node->MinVals().n_elem, Node->MinVals().n_elem);
-		for (size_t i = 0; i < node->MinVals().n_elem; ++i)
-			{
-			if (std::abs(node->MinVals()[i]) < 1e-5)
-				{
-				BOOST_REQUIRE_SMALL(Node->MinVals()[i], 1e-5);
-				}
-			else
-				{
-				BOOST_REQUIRE_CLOSE(node->MinVals()[i], Node->MinVals()[i], 1e-5);
-				}
-			}
-		}
-
-	}
-BOOST_AUTO_TEST_CASE(DETXmlTest)
-	{
-	using det::DTree;
-
-	// Create a density estimation tree on a random dataset.
-	arma::mat dataset = arma::randu<arma::mat>(25, 5000);
-
-	DTree tree(dataset);
-
-	arma::mat otherDataset = arma::randu<arma::mat>(5, 100);
-	DTree Tree;
-
-	SerializeObject<DTree, xml_iarchive,xml_oarchive>(tree, Tree);
+  // Create a density estimation tree on a random dataset.
+  arma::mat dataset = arma::randu<arma::mat>(25, 5000);
 
-	std::stack<DTree*> stack, Stack;
-	stack.push(&tree);
-	Stack.push(&Tree);
-
-	TestStack(stack, Stack);
-		
-	}
+  DTree tree(dataset);
 
+  arma::mat otherDataset = arma::randu<arma::mat>(5, 100);
+  DTree xmlTree, binaryTree, textTree(otherDataset);
 
-	BOOST_AUTO_TEST_CASE(DETTextTest)
-		{
-		using det::DTree;
+  SerializeObjectAll(tree, xmlTree, binaryTree, textTree);
 
-		// Create a density estimation tree on a random dataset.
-		arma::mat dataset = arma::randu<arma::mat>(25, 5000);
+  std::stack<DTree*> stack, xmlStack, binaryStack, textStack;
+  stack.push(&tree);
+  xmlStack.push(&xmlTree);
+  binaryStack.push(&binaryTree);
+  textStack.push(&textTree);
 
-		DTree tree(dataset);
+  while (!stack.empty())
+  {
+    // Get the top node from the stack.
+    DTree* node = stack.top();
+    DTree* xmlNode = xmlStack.top();
+    DTree* binaryNode = binaryStack.top();
+    DTree* textNode = textStack.top();
 
-		arma::mat otherDataset = arma::randu<arma::mat>(5, 100);
-		DTree Tree;
+    stack.pop();
+    xmlStack.pop();
+    binaryStack.pop();
+    textStack.pop();
 
-		SerializeObject<DTree, text_iarchive, text_oarchive>(tree, Tree);
+    // Check that all the members are the same.
+    BOOST_REQUIRE_EQUAL(node->Start(), xmlNode->Start());
+    BOOST_REQUIRE_EQUAL(node->Start(), binaryNode->Start());
+    BOOST_REQUIRE_EQUAL(node->Start(), textNode->Start());
 
-		std::stack<DTree*> stack, Stack;
-		stack.push(&tree);
-		Stack.push(&Tree);
+    BOOST_REQUIRE_EQUAL(node->End(), xmlNode->End());
+    BOOST_REQUIRE_EQUAL(node->End(), binaryNode->End());
+    BOOST_REQUIRE_EQUAL(node->End(), textNode->End());
 
-		TestStack(stack, Stack);
+    BOOST_REQUIRE_EQUAL(node->SplitDim(), xmlNode->SplitDim());
+    BOOST_REQUIRE_EQUAL(node->SplitDim(), binaryNode->SplitDim());
+    BOOST_REQUIRE_EQUAL(node->SplitDim(), textNode->SplitDim());
 
-		}
-		BOOST_AUTO_TEST_CASE(DETBInaryTest)
-			{
-			using det::DTree;
+    if (std::abs(node->SplitValue()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->SplitValue(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->SplitValue(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->SplitValue(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->SplitValue(), xmlNode->SplitValue(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->SplitValue(), binaryNode->SplitValue(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->SplitValue(), textNode->SplitValue(), 1e-5);
+    }
+
+    if (std::abs(node->LogNegError()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->LogNegError(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->LogNegError(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->LogNegError(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->LogNegError(), xmlNode->LogNegError(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->LogNegError(), binaryNode->LogNegError(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->LogNegError(), textNode->LogNegError(), 1e-5);
+    }
 
-			// Create a density estimation tree on a random dataset.
-			arma::mat dataset = arma::randu<arma::mat>(25, 5000);
+    if (std::abs(node->SubtreeLeavesLogNegError()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->SubtreeLeavesLogNegError(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->SubtreeLeavesLogNegError(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->SubtreeLeavesLogNegError(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->SubtreeLeavesLogNegError(),
+          xmlNode->SubtreeLeavesLogNegError(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->SubtreeLeavesLogNegError(),
+          binaryNode->SubtreeLeavesLogNegError(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->SubtreeLeavesLogNegError(),
+          textNode->SubtreeLeavesLogNegError(), 1e-5);
+    }
 
-			DTree tree(dataset);
+    BOOST_REQUIRE_EQUAL(node->SubtreeLeaves(), xmlNode->SubtreeLeaves());
+    BOOST_REQUIRE_EQUAL(node->SubtreeLeaves(), binaryNode->SubtreeLeaves());
+    BOOST_REQUIRE_EQUAL(node->SubtreeLeaves(), textNode->SubtreeLeaves());
 
-			arma::mat otherDataset = arma::randu<arma::mat>(5, 100);
-			DTree Tree;
+    if (std::abs(node->Ratio()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->Ratio(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->Ratio(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->Ratio(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->Ratio(), xmlNode->Ratio(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->Ratio(), binaryNode->Ratio(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->Ratio(), textNode->Ratio(), 1e-5);
+    }
 
-			SerializeObject<DTree, binary_iarchive, binary_oarchive>(tree, Tree);
+    if (std::abs(node->LogVolume()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->LogVolume(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->LogVolume(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->LogVolume(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->LogVolume(), xmlNode->LogVolume(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->LogVolume(), binaryNode->LogVolume(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->LogVolume(), textNode->LogVolume(), 1e-5);
+    }
 
-			std::stack<DTree*> stack, Stack;
-			stack.push(&tree);
-			Stack.push(&Tree);
-			TestStack(stack, Stack);
+    if (node->Left() == NULL)
+    {
+      BOOST_REQUIRE(xmlNode->Left() == NULL);
+      BOOST_REQUIRE(binaryNode->Left() == NULL);
+      BOOST_REQUIRE(textNode->Left() == NULL);
+    }
+    else
+    {
+      BOOST_REQUIRE(xmlNode->Left() != NULL);
+      BOOST_REQUIRE(binaryNode->Left() != NULL);
+      BOOST_REQUIRE(textNode->Left() != NULL);
+
+      // Push children onto stack.
+      stack.push(node->Left());
+      xmlStack.push(xmlNode->Left());
+      binaryStack.push(binaryNode->Left());
+      textStack.push(textNode->Left());
+    }
 
-			}
+    if (node->Right() == NULL)
+    {
+      BOOST_REQUIRE(xmlNode->Right() == NULL);
+      BOOST_REQUIRE(binaryNode->Right() == NULL);
+      BOOST_REQUIRE(textNode->Right() == NULL);
+    }
+    else
+    {
+      BOOST_REQUIRE(xmlNode->Right() != NULL);
+      BOOST_REQUIRE(binaryNode->Right() != NULL);
+      BOOST_REQUIRE(textNode->Right() != NULL);
+
+      // Push children onto stack.
+      stack.push(node->Right());
+      xmlStack.push(xmlNode->Right());
+      binaryStack.push(binaryNode->Right());
+      textStack.push(textNode->Right());
+    }
 
+    BOOST_REQUIRE_EQUAL(node->Root(), xmlNode->Root());
+    BOOST_REQUIRE_EQUAL(node->Root(), binaryNode->Root());
+    BOOST_REQUIRE_EQUAL(node->Root(), textNode->Root());
 
+    if (std::abs(node->AlphaUpper()) < 1e-5)
+    {
+      BOOST_REQUIRE_SMALL(xmlNode->AlphaUpper(), 1e-5);
+      BOOST_REQUIRE_SMALL(binaryNode->AlphaUpper(), 1e-5);
+      BOOST_REQUIRE_SMALL(textNode->AlphaUpper(), 1e-5);
+    }
+    else
+    {
+      BOOST_REQUIRE_CLOSE(node->AlphaUpper(), xmlNode->AlphaUpper(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->AlphaUpper(), binaryNode->AlphaUpper(), 1e-5);
+      BOOST_REQUIRE_CLOSE(node->AlphaUpper(), textNode->AlphaUpper(), 1e-5);
+    }
 
+    BOOST_REQUIRE_EQUAL(node->MaxVals().n_elem, xmlNode->MaxVals().n_elem);
+    BOOST_REQUIRE_EQUAL(node->MaxVals().n_elem, binaryNode->MaxVals().n_elem);
+    BOOST_REQUIRE_EQUAL(node->MaxVals().n_elem, textNode->MaxVals().n_elem);
+    for (size_t i = 0; i < node->MaxVals().n_elem; ++i)
+    {
+      if (std::abs(node->MaxVals()[i]) < 1e-5)
+      {
+        BOOST_REQUIRE_SMALL(xmlNode->MaxVals()[i], 1e-5);
+        BOOST_REQUIRE_SMALL(binaryNode->MaxVals()[i], 1e-5);
+        BOOST_REQUIRE_SMALL(textNode->MaxVals()[i], 1e-5);
+      }
+      else
+      {
+        BOOST_REQUIRE_CLOSE(node->MaxVals()[i], xmlNode->MaxVals()[i], 1e-5);
+        BOOST_REQUIRE_CLOSE(node->MaxVals()[i], binaryNode->MaxVals()[i], 1e-5);
+        BOOST_REQUIRE_CLOSE(node->MaxVals()[i], textNode->MaxVals()[i], 1e-5);
+      }
+    }
 
+    BOOST_REQUIRE_EQUAL(node->MinVals().n_elem, xmlNode->MinVals().n_elem);
+    BOOST_REQUIRE_EQUAL(node->MinVals().n_elem, binaryNode->MinVals().n_elem);
+    BOOST_REQUIRE_EQUAL(node->MinVals().n_elem, textNode->MinVals().n_elem);
+    for (size_t i = 0; i < node->MinVals().n_elem; ++i)
+    {
+      if (std::abs(node->MinVals()[i]) < 1e-5)
+      {
+        BOOST_REQUIRE_SMALL(xmlNode->MinVals()[i], 1e-5);
+        BOOST_REQUIRE_SMALL(binaryNode->MinVals()[i], 1e-5);
+        BOOST_REQUIRE_SMALL(textNode->MinVals()[i], 1e-5);
+      }
+      else
+      {
+        BOOST_REQUIRE_CLOSE(node->MinVals()[i], xmlNode->MinVals()[i], 1e-5);
+        BOOST_REQUIRE_CLOSE(node->MinVals()[i], binaryNode->MinVals()[i], 1e-5);
+        BOOST_REQUIRE_CLOSE(node->MinVals()[i], textNode->MinVals()[i], 1e-5);
+      }
+    }
+  }
+}
 
 BOOST_AUTO_TEST_CASE(NaiveBayesSerializationTest)
 {



More information about the mlpack-git mailing list