[mlpack-svn] r16236 - in mlpack/trunk/src/mlpack: methods/rann methods/sparse_coding tests

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Feb 7 12:30:59 EST 2014


Author: birm
Date: Fri Feb  7 12:30:58 2014
New Revision: 16236

Log:
Finished toString of the methods folder ( sparse coding and rann ); updated test.


Modified:
   mlpack/trunk/src/mlpack/methods/rann/ra_search.hpp
   mlpack/trunk/src/mlpack/methods/rann/ra_search_impl.hpp
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
   mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
   mlpack/trunk/src/mlpack/tests/to_string_test.cpp

Modified: mlpack/trunk/src/mlpack/methods/rann/ra_search.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/rann/ra_search.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/rann/ra_search.hpp	Fri Feb  7 12:30:58 2014
@@ -73,6 +73,7 @@
   size_t NumSamplesMade() const { return numSamplesMade; }
   //! Modify the number of samples made.
   size_t& NumSamplesMade() { return numSamplesMade; }
+
 };
 
 /**
@@ -286,6 +287,9 @@
    */
   void ResetQueryTree();
 
+  // Returns a string representation of this object. 
+  std::string ToString() const;
+
  private:
   //! Copy of reference dataset (if we need it, because tree building modifies
   //! it).

Modified: mlpack/trunk/src/mlpack/methods/rann/ra_search_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/rann/ra_search_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/rann/ra_search_impl.hpp	Fri Feb  7 12:30:58 2014
@@ -354,6 +354,26 @@
     ResetRAQueryStat(&treeNode->Child(i));
 }
 
+// Returns a String of the Object.
+template<typename SortPolicy, typename MetricType, typename TreeType>
+std::string RASearch<SortPolicy, MetricType, TreeType>::ToString() const
+{
+  std::ostringstream convert;
+  convert << "RA Search  [" << this << "]" << std::endl;
+  convert << "  Reference Set: " << referenceSet.n_rows << "x" ;
+  convert <<  referenceSet.n_cols << std::endl;
+  if (&referenceSet != &querySet)
+    convert << "  QuerySet: " << querySet.n_rows << "x" << querySet.n_cols 
+        << std::endl;
+  if (naive)  
+    convert << "  Naive: TRUE" << std::endl;
+  if (singleMode)
+    convert << "  Single Node: TRUE" << std::endl;
+  convert << "  Metric: " << std::endl << 
+      mlpack::util::Indent(metric.ToString(),2);
+  return convert.str();
+}
+
 }; // namespace neighbor
 }; // namespace mlpack
 

Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding.hpp	Fri Feb  7 12:30:58 2014
@@ -173,6 +173,9 @@
   //! Modify the sparse codes.
   arma::mat& Codes() { return codes; }
 
+  // Returns a string representation of this object. 
+  std::string ToString() const;
+
  private:
   //! Number of atoms.
   size_t atoms;

Modified: mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp	Fri Feb  7 12:30:58 2014
@@ -331,6 +331,19 @@
   }
 }
 
+template<typename DictionaryInitializer>
+std::string SparseCoding<DictionaryInitializer>::ToString() const
+{
+  std::ostringstream convert;
+  convert << "Sparse Coding  [" << this << "]" << std::endl;
+  convert << "  Data: " << data.n_rows << "x" ;
+  convert <<  data.n_cols << std::endl;
+  convert << "  Atoms: " << atoms << std::endl; 
+  convert << "  Lambda 1: " << lambda1 << std::endl; 
+  convert << "  Lambda 2: " << lambda2 << std::endl; 
+  return convert.str();
+}
+
 }; // namespace sparse_coding
 }; // 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	Fri Feb  7 12:30:58 2014
@@ -53,6 +53,8 @@
 #include <mlpack/methods/pca/pca.hpp>
 #include <mlpack/methods/radical/radical.hpp>
 #include <mlpack/methods/range_search/range_search.hpp>
+#include <mlpack/methods/rann/ra_search.hpp>
+#include <mlpack/methods/sparse_coding/sparse_coding.hpp>
 
 using namespace mlpack;
 using namespace mlpack::kernel;
@@ -444,4 +446,26 @@
   BOOST_REQUIRE_NE(s, "");
 }
 
+BOOST_AUTO_TEST_CASE(RannString)
+{
+  arma::mat c(40, 40);
+  c.randn();
+  mlpack::neighbor::RASearch<> d(c);
+  Log::Debug << d;
+  std::string s = d.ToString();
+  BOOST_REQUIRE_NE(s, "");
+}
+
+BOOST_AUTO_TEST_CASE(SparseCodingString)
+{
+  arma::mat c(40, 40);
+  c.randn();
+  const size_t b=3;
+  double a=0.1;
+  mlpack::sparse_coding::SparseCoding<> d(c,b,a);
+  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