[mlpack-git] master: Change API slightly to match other code. Realistically, this probably needs further thought: C++11 gives us rvalue references, so we can do something a bit smarter to validate parameters without any unnecessary copies that would result from Mutator(const T&) (or whatever). (251fb8f)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:17:54 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 251fb8f1a29b5b16d37d88a10d097549dfe3474e
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Mar 5 11:07:10 2015 -0500

    Change API slightly to match other code.
    Realistically, this probably needs further thought: C++11 gives us rvalue references, so we can do something a bit smarter to validate parameters without any unnecessary copies that would result from Mutator(const T&) (or whatever).


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

251fb8f1a29b5b16d37d88a10d097549dfe3474e
 .../softmax_regression/softmax_regression.hpp      | 42 +++++-----------------
 .../softmax_regression_function.hpp                | 39 ++++----------------
 2 files changed, 16 insertions(+), 65 deletions(-)

diff --git a/src/mlpack/methods/softmax_regression/softmax_regression.hpp b/src/mlpack/methods/softmax_regression/softmax_regression.hpp
index bf5e6c7..1f95c81 100644
--- a/src/mlpack/methods/softmax_regression/softmax_regression.hpp
+++ b/src/mlpack/methods/softmax_regression/softmax_regression.hpp
@@ -114,46 +114,22 @@ class SoftmaxRegression
   double ComputeAccuracy(const arma::mat& testData, const arma::vec& labels);
 
   //! Sets the size of the input vector.
-  void InputSize(const size_t input)
-  {
-    this->inputSize = input;
-  }
-  
+  size_t& InputSize() { return inputSize; }
   //! Gets the size of the input vector.
-  size_t InputSize() const
-  {
-    return inputSize;
-  }
+  size_t InputSize() const { return inputSize; }
 
   //! Sets the number of classes.
-  void NumClasses(const size_t classes)
-  {
-    this->numClasses = classes;
-  }
-  
+  size_t& NumClasses() { return numClasses; }
   //! Gets the number of classes.
-  size_t NumClasses() const
-  {
-    return numClasses;
-  }
+  size_t NumClasses() const { return numClasses; }
 
   //! Sets the regularization parameter.
-  void Lambda(const double l)
-  {
-    this->lambda = l;
-  }
-  
+  double& Lambda() { return lambda; }
   //! Gets the regularization parameter.
-  double Lambda() const
-  {
-    return lambda;
-  }
-
-  //! Gets the intercept term flag.
-  bool FitIntercept() const
-  {
-    return fitIntercept;
-  }
+  double Lambda() const { return lambda; }
+
+  //! Gets the intercept term flag.  We can't change this after training.
+  bool FitIntercept() const { return fitIntercept; }
 
  private:
   //! Parameters after optimization.
diff --git a/src/mlpack/methods/softmax_regression/softmax_regression_function.hpp b/src/mlpack/methods/softmax_regression/softmax_regression_function.hpp
index bd09041..3d14627 100644
--- a/src/mlpack/methods/softmax_regression/softmax_regression_function.hpp
+++ b/src/mlpack/methods/softmax_regression/softmax_regression_function.hpp
@@ -83,46 +83,22 @@ class SoftmaxRegressionFunction
   const arma::mat& GetInitialPoint() const { return initialPoint; }
 
   //! Sets the size of the input vector.
-  void InputSize(const size_t input)
-  {
-    this->inputSize = input;
-  }
-
+  size_t& InputSize() { return inputSize; }
   //! Gets the size of the input vector.
-  size_t InputSize() const
-  {
-    return inputSize;
-  }
+  size_t InputSize() const { return inputSize; }
 
   //! Sets the number of classes.
-  void NumClasses(const size_t classes)
-  {
-    this->numClasses = classes;
-  }
-
+  size_t& NumClasses() { return numClasses; }
   //! Gets the number of classes.
-  size_t NumClasses() const
-  {
-    return numClasses;
-  }
+  size_t NumClasses() const { return numClasses; }
 
   //! Sets the regularization parameter.
-  void Lambda(const double l)
-  {
-    this->lambda = l;
-  }
-
+  double& Lambda() { return lambda; }
   //! Gets the regularization parameter.
-  double Lambda() const
-  {
-    return lambda;
-  }
+  double Lambda() const { return lambda; }
 
   //! Gets the intercept flag.
-  bool FitIntercept() const
-  {
-    return fitIntercept;
-  }
+  bool FitIntercept() const { return fitIntercept; }
 
  private:
   //! Training data matrix.
@@ -139,7 +115,6 @@ class SoftmaxRegressionFunction
   double lambda;
   //! Intercept term flag.
   bool fitIntercept;
-
 };
 
 }; // namespace regression



More information about the mlpack-git mailing list