[mlpack-svn] r16232 - in mlpack/trunk/src/mlpack: core/tree/binary_space_tree core/util methods/lsh tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Feb 6 18:25:37 EST 2014


Author: birm
Date: Thu Feb  6 18:25:37 2014
New Revision: 16232

Log:
Modified StringUtil to take a number on Indent, implemented LSHSearch ToString, updated Test.


Modified:
   mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
   mlpack/trunk/src/mlpack/core/util/string_util.cpp
   mlpack/trunk/src/mlpack/core/util/string_util.hpp
   mlpack/trunk/src/mlpack/methods/lsh/lsh_search.hpp
   mlpack/trunk/src/mlpack/methods/lsh/lsh_search_impl.hpp
   mlpack/trunk/src/mlpack/tests/to_string_test.cpp

Modified: mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/tree/binary_space_tree/binary_space_tree_impl.hpp	Thu Feb  6 18:25:37 2014
@@ -712,8 +712,10 @@
   convert << "BinarySpaceTree [" << this << "]" << std::endl;
   convert << "  begin: " << begin << std::endl;
   convert << "  count: " << count << std::endl;
-  convert << "  bound: " << mlpack::util::Indent(bound.ToString());
-  convert << "  statistic: " << stat.ToString();
+  convert << "  bound: " << std::endl;
+  convert << mlpack::util::Indent(bound.ToString(),2);
+  convert << "  statistic: " << std::endl;
+  convert << mlpack::util::Indent(stat.ToString(),2);
   convert << "  leaf size: " << leafSize << std::endl;
   convert << "  splitDimension: " << splitDimension << std::endl;
   if (left != NULL)

Modified: mlpack/trunk/src/mlpack/core/util/string_util.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/util/string_util.cpp	(original)
+++ mlpack/trunk/src/mlpack/core/util/string_util.cpp	Thu Feb  6 18:25:37 2014
@@ -1,6 +1,6 @@
 /**
  * @file string_util.cpp
- *
+ * @author ??? and Ryan Birmingham
  * Defines methods useful for formatting output.
  */
 #include "string_util.hpp"
@@ -11,14 +11,21 @@
 
 //! A utility function that replaces all all newlines with a number of spaces
 //! depending on the indentation level.
-string mlpack::util::Indent(string input)
+string mlpack::util::Indent(string input, size_t howManyTabs)
 {
-  // Tab the first line.
-  input.insert(0, 1, ' ');
-  input.insert(0, 1, ' ');
-
-  // Get the character sequence to replace all newline characters.
-  std::string tabbedNewline("\n  ");
+  // For each declared...
+  string standardTab = "  ";
+  string bigTab = "";
+  for (size_t ind=0; ind<howManyTabs; ind++)
+  {
+    // increase amount tabbed on later lines
+    bigTab+=standardTab;
+    //add to first line
+    input.insert(0, 1, ' ');
+    input.insert(0, 1, ' ');
+  }  
+// Get the character sequence to replace all newline characters.
+  std::string tabbedNewline("\n"+ bigTab);
 
   // Replace all newline characters with the precomputed character sequence.
   size_t startPos = 0;

Modified: mlpack/trunk/src/mlpack/core/util/string_util.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/core/util/string_util.hpp	(original)
+++ mlpack/trunk/src/mlpack/core/util/string_util.hpp	Thu Feb  6 18:25:37 2014
@@ -1,6 +1,6 @@
 /**
  * @file string_util.hpp
- *
+ * @author ??? and Ryan Birmingham
  * Declares methods that are useful for writing formatting output.
  */
 #ifndef __MLPACK_CORE_STRING_UTIL_HPP
@@ -13,7 +13,7 @@
 
 //! A utility function that replaces all all newlines with a number of spaces
 //! depending on the indentation level.
-std::string Indent(std::string input);
+std::string Indent(std::string input, size_t howManyTabs=1);
 
 }; // namespace util
 }; // namespace mlpack

Modified: mlpack/trunk/src/mlpack/methods/lsh/lsh_search.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/lsh/lsh_search.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/lsh/lsh_search.hpp	Thu Feb  6 18:25:37 2014
@@ -123,6 +123,9 @@
               arma::mat& distances,
               const size_t numTablesToSearch = 0);
 
+  // Returns a string representation of this object. 
+  std::string ToString() const;
+
  private:
   /**
    * This function builds a hash table with two levels of hashing as presented
@@ -178,7 +181,6 @@
   void InsertNeighbor(const size_t queryIndex, const size_t pos,
                       const size_t neighbor, const double distance);
 
- private:
   //! Reference dataset.
   const arma::mat& referenceSet;
 

Modified: mlpack/trunk/src/mlpack/methods/lsh/lsh_search_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/lsh/lsh_search_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/lsh/lsh_search_impl.hpp	Thu Feb  6 18:25:37 2014
@@ -390,6 +390,24 @@
   secondHashTable.resize(numRowsInTable, maxBucketSize);
 }
 
+template<typename SortPolicy>
+std::string LSHSearch<SortPolicy>::ToString() const
+{
+  std::ostringstream convert;
+  convert << "LSHSearch [" << this << "]" << std::endl;
+  convert << "  Reference Set: " << referenceSet.n_rows << "x" ;
+  convert <<  referenceSet.n_cols << std::endl;
+  if (&referenceSet != & querySet)
+    convert << "  QueryeSet: " << querySet.n_rows << "x" << querySet.n_cols 
+        << std::endl;
+  convert << "  Number of Projections: " << numProj << std::endl;
+  convert << "  Number of Tables: " << numTables << std::endl;
+  convert << "  Hash Width: " << hashWidth << std::endl;
+  convert << "  Metric: " << std::endl;
+  convert << mlpack::util::Indent(metric.ToString(),2);
+  return convert.str();
+}
+
 }; // namespace neighbor
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/tests/to_string_test.cpp
==============================================================================
--- mlpack/trunk/src/mlpack/tests/to_string_test.cpp	(original)
+++ mlpack/trunk/src/mlpack/tests/to_string_test.cpp	Thu Feb  6 18:25:37 2014
@@ -45,6 +45,7 @@
 #include <mlpack/methods/linear_regression/linear_regression.hpp>
 #include <mlpack/methods/local_coordinate_coding/lcc.hpp>
 #include <mlpack/methods/logistic_regression/logistic_regression.hpp>
+#include <mlpack/methods/lsh/lsh_search.hpp>
 
 using namespace mlpack;
 using namespace mlpack::kernel;
@@ -367,5 +368,15 @@
   std::string s = d.ToString();
   BOOST_REQUIRE_NE(s, "");
 }
+BOOST_AUTO_TEST_CASE(LSHString)
+{
+  arma::mat c(40,40);
+  const size_t b=3;
+  c.randn();
+  mlpack::neighbor::LSHSearch<NearestNeighborSort> d(c, b, b);
+  Log::Debug << d;
+  std::string s = d.ToString();
+  BOOST_REQUIRE_NE(s, "");
+}
 
 BOOST_AUTO_TEST_SUITE_END();



More information about the mlpack-svn mailing list