[mlpack-svn] r10355 - mlpack/trunk/src/mlpack/core/metrics

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Nov 23 02:06:17 EST 2011


Author: rcurtin
Date: 2011-11-23 02:06:17 -0500 (Wed, 23 Nov 2011)
New Revision: 10355

Modified:
   mlpack/trunk/src/mlpack/core/metrics/lmetric.cpp
   mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp
   mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance.hpp
   mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance_impl.hpp
Log:
Fix style as per #153 and name local class members as per #118.


Modified: mlpack/trunk/src/mlpack/core/metrics/lmetric.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/lmetric.cpp	2011-11-23 06:57:13 UTC (rev 10354)
+++ mlpack/trunk/src/mlpack/core/metrics/lmetric.cpp	2011-11-23 07:06:17 UTC (rev 10355)
@@ -1,5 +1,5 @@
 /***
- * @file lmetric.cc
+ * @file lmetric.cpp
  * @author Ryan Curtin
  *
  * Implementation of template specializations of LMetric class.
@@ -11,7 +11,8 @@
 
 // L1-metric specializations; the root doesn't matter.
 template<>
-double LMetric<1, true>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<1, true>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += fabs(a[i] - b[i]);
@@ -20,7 +21,8 @@
 }
 
 template<>
-double LMetric<1, false>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<1, false>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += fabs(a[i] - b[i]);
@@ -30,7 +32,8 @@
 
 // L2-metric specializations.
 template<>
-double LMetric<2, true>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<2, true>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += pow(a[i] - b[i], 2.0); // fabs() not necessary when squaring.
@@ -39,7 +42,8 @@
 }
 
 template<>
-double LMetric<2, false>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<2, false>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += pow(a[i] - b[i], 2.0);
@@ -49,7 +53,8 @@
 
 // L3-metric specialization (not very likely to be used, but just in case).
 template<>
-double LMetric<3, true>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<3, true>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += pow(fabs(a[i] - b[i]), 3.0);
@@ -58,7 +63,8 @@
 }
 
 template<>
-double LMetric<3, false>::Evaluate(const arma::vec& a, const arma::vec& b) {
+double LMetric<3, false>::Evaluate(const arma::vec& a, const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += pow(fabs(a[i] - b[i]), 3.0);
@@ -66,5 +72,5 @@
   return sum;
 }
 
-}; // namespace kernel
+}; // namespace metric
 }; // namespace mlpack

Modified: mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp	2011-11-23 06:57:13 UTC (rev 10354)
+++ mlpack/trunk/src/mlpack/core/metrics/lmetric.hpp	2011-11-23 07:06:17 UTC (rev 10355)
@@ -51,7 +51,8 @@
  *   t_take_root = false, because one fewer call to pow() is required.
  */
 template<int t_pow, bool t_take_root = false>
-class LMetric {
+class LMetric
+{
  public:
   /***
    * Default constructor does nothing, but is required to satisfy the Kernel
@@ -73,7 +74,8 @@
 // Unspecialized implementation.  This should almost never be used...
 template<int t_pow, bool t_take_root>
 double LMetric<t_pow, t_take_root>::Evaluate(const arma::vec& a,
-                                             const arma::vec& b) {
+                                             const arma::vec& b)
+{
   double sum = 0;
   for (size_t i = 0; i < a.n_elem; i++)
     sum += pow(fabs(a[i] - b[i]), t_pow);
@@ -103,7 +105,7 @@
  */
 typedef LMetric<2, true> EuclideanDistance;
 
-}; // namespace distance
+}; // namespace metric
 }; // namespace mlpack
 
 #endif

Modified: mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance.hpp	2011-11-23 06:57:13 UTC (rev 10354)
+++ mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance.hpp	2011-11-23 07:06:17 UTC (rev 10355)
@@ -43,14 +43,15 @@
  *   faster to leave this at the default of false.
  */
 template<bool t_take_root = false>
-class MahalanobisDistance {
+class MahalanobisDistance
+{
  public:
   /**
    * Initialize the Mahalanobis distance with the empty matrix as covariance.
    * Because we don't actually know the size of the vectors we will be using, we
    * delay creation of the covariance matrix until evaluation.
    */
-  MahalanobisDistance() : covariance_(0, 0) { }
+  MahalanobisDistance() : covariance(0, 0) { }
 
   /**
    * Initialize the Mahalanobis distance with the given covariance matrix.  The
@@ -58,7 +59,7 @@
    *
    * @param covariance The covariance matrix to use for this distance.
    */
-  MahalanobisDistance(const arma::mat& covariance) : covariance_(covariance) { }
+  MahalanobisDistance(const arma::mat& covariance) : covariance(covariance) { }
 
   /**
    * Evaluate the distance between the two given points using this Mahalanobis
@@ -74,18 +75,18 @@
    *
    * @return Constant reference to the covariance matrix.
    */
-  const arma::mat& GetCovariance() const { return covariance_; }
+  const arma::mat& Covariance() const { return covariance; }
 
   /**
    * Modify the covariance matrix.
    *
    * @return Reference to the covariance matrix.
    */
-  arma::mat& GetCovariance() { return covariance_; }
+  arma::mat& Covariance() { return covariance; }
 
  private:
   //! The covariance matrix associated with this distance.
-  arma::mat covariance_;
+  arma::mat covariance;
 };
 
 }; // namespace distance

Modified: mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance_impl.hpp	2011-11-23 06:57:13 UTC (rev 10354)
+++ mlpack/trunk/src/mlpack/core/metrics/mahalanobis_distance_impl.hpp	2011-11-23 07:06:17 UTC (rev 10355)
@@ -17,13 +17,14 @@
  */
 template<>
 double MahalanobisDistance<false>::Evaluate(const arma::vec& a,
-                                            const arma::vec& b) {
+                                            const arma::vec& b)
+{
   // Check if covariance matrix has been initialized.
-  if (covariance_.n_rows == 0)
-    covariance_ = arma::eye<arma::mat>(a.n_elem, a.n_elem);
+  if (covariance.n_rows == 0)
+    covariance = arma::eye<arma::mat>(a.n_elem, a.n_elem);
 
   arma::vec m = (a - b);
-  arma::mat out = trans(m) * covariance_ * m; // 1x1
+  arma::mat out = trans(m) * covariance * m; // 1x1
   return out[0];
 }
 
@@ -33,17 +34,18 @@
  */
 template<>
 double MahalanobisDistance<true>::Evaluate(const arma::vec& a,
-                                           const arma::vec& b) {
+                                           const arma::vec& b)
+{
   // Check if covariance matrix has been initialized.
-  if (covariance_.n_rows == 0)
-    covariance_ = arma::eye<arma::mat>(a.n_elem, a.n_elem);
+  if (covariance.n_rows == 0)
+    covariance = arma::eye<arma::mat>(a.n_elem, a.n_elem);
 
   arma::vec m = (a - b);
-  arma::mat out = trans(m) * covariance_ * m; // 1x1;
+  arma::mat out = trans(m) * covariance * m; // 1x1;
   return sqrt(out[0]);
 }
 
-}; // namespace distance
+}; // namespace metric
 }; // namespace mlpack
 
 #endif




More information about the mlpack-svn mailing list