[mlpack-svn] r13461 - in mlpack/trunk/src/mlpack/core: dists util

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Aug 27 17:46:46 EDT 2012


Author: trironk3
Date: 2012-08-27 17:46:46 -0400 (Mon, 27 Aug 2012)
New Revision: 13461

Modified:
   mlpack/trunk/src/mlpack/core/dists/discrete_distribution.cpp
   mlpack/trunk/src/mlpack/core/dists/discrete_distribution.hpp
   mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.cpp
   mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.hpp
   mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp
Log:
#147
Cleaned up code.
Added some documentation.
Implemented ToString() for GaussianDistribution.



Modified: mlpack/trunk/src/mlpack/core/dists/discrete_distribution.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/dists/discrete_distribution.cpp	2012-08-27 17:54:47 UTC (rev 13460)
+++ mlpack/trunk/src/mlpack/core/dists/discrete_distribution.cpp	2012-08-27 21:46:46 UTC (rev 13461)
@@ -80,6 +80,9 @@
     probabilities.fill(1 / probabilities.n_elem); // Force normalization.
 }
 
+/*
+ * Returns a string representation of this object.
+ */
 std::string DiscreteDistribution::ToString() const
 {
   std::ostringstream convert;

Modified: mlpack/trunk/src/mlpack/core/dists/discrete_distribution.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/dists/discrete_distribution.hpp	2012-08-27 17:54:47 UTC (rev 13460)
+++ mlpack/trunk/src/mlpack/core/dists/discrete_distribution.hpp	2012-08-27 21:46:46 UTC (rev 13461)
@@ -129,6 +129,9 @@
   //! Modify the vector of probabilities.
   arma::vec& Probabilities() { return probabilities; }
   
+  /*
+   * Returns a string representation of this object.
+   */
   std::string ToString() const;
 
  private:

Modified: mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.cpp	2012-08-27 17:54:47 UTC (rev 13460)
+++ mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.cpp	2012-08-27 21:46:46 UTC (rev 13461)
@@ -95,4 +95,17 @@
 
   // This is probably biased, but I don't know how to unbias it.
   covariance /= sumProb;
+
 }
+
+/**
+ * Returns a string representation of this object.
+ */
+std::string GaussianDistribution::ToString() const
+{
+  std::ostringstream convert;
+  convert << "GaussianDistribution: " << this << std::endl;
+  convert << "mean: " << std::endl << mean << std::endl;
+  convert << "covariance: " << std::endl << covariance << std::endl;
+  return convert.str();
+}

Modified: mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.hpp	2012-08-27 17:54:47 UTC (rev 13460)
+++ mlpack/trunk/src/mlpack/core/dists/gaussian_distribution.hpp	2012-08-27 21:46:46 UTC (rev 13461)
@@ -99,6 +99,10 @@
    */
   arma::mat& Covariance() { return covariance; }
 
+  /**
+   * Returns a string representation of this object.
+   */
+  std::string ToString() const;
 };
 
 }; // namespace distribution

Modified: mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp	2012-08-27 17:54:47 UTC (rev 13460)
+++ mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp	2012-08-27 21:46:46 UTC (rev 13461)
@@ -32,15 +32,15 @@
  * @param NAME the name of the struct to construct. For example: HasToString
  * @param FUNC the name of the function to check for. For example: ToString
  */
-#define HAS_MEM_FUNC(FUNC, NAME)                                               \
-template<typename T, typename sig>                                             \
-struct NAME {                                                                  \
-    typedef char yes;                                                          \
-    typedef long no;                                                           \
-    template <typename U, U> struct type_check;                                \
-    template <typename _1> static yes &chk(type_check<sig, &_1::FUNC> *);      \
-    template <typename   > static no  &chk(...);                               \
-    static bool const value = sizeof(chk<T>(0)) == sizeof(yes);                \
+#define HAS_MEM_FUNC(FUNC, NAME)                                                   \
+template<typename T, typename sig>                                                 \
+struct NAME {                                                                      \
+  typedef char yes[1];                                                             \
+  typedef char no [2];                                                             \
+  template<typename U, U> struct type_check;                                       \
+  template<typename _1> static yes &chk(type_check<sig, &_1::FUNC> *);             \
+  template<typename   > static no  &chk(...);                                      \
+  static bool const value = sizeof(chk<T>(0)) == sizeof(yes);                      \
 };
 
 #endif




More information about the mlpack-svn mailing list