[mlpack-svn] r16012 - mlpack/trunk/src/mlpack/methods/logistic_regression

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Nov 8 14:23:49 EST 2013


Author: rcurtin
Date: Fri Nov  8 14:23:49 2013
New Revision: 16012

Log:
Add some comments and fix a little bit of formatting.


Modified:
   mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression.hpp
   mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp

Modified: mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression.hpp	Fri Nov  8 14:23:49 2013
@@ -2,7 +2,8 @@
  * @file logistic_regression.hpp
  * @author Sumedh Ghaisas
  *
- * The LogisticRegression class, which implements logistic regression.
+ * The LogisticRegression class, which implements logistic regression.  This
+ * implements supports L2-regularization.
  */
 #ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
 #define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_HPP
@@ -21,10 +22,31 @@
 class LogisticRegression
 {
  public:
+  /**
+   * Construct the LogisticRegression class with the given labeled training
+   * data.  This will train the model.  Optionally, specify lambda, which is the
+   * penalty parameter for L2-regularization.  If not specified, it is set to 0,
+   * which results in standard (unregularized) logistic regression.
+   *
+   * @param predictors Input training variables.
+   * @param responses Outputs resulting from input training variables.
+   * @param lambda L2-regularization parameter.
+   */
   LogisticRegression(arma::mat& predictors,
                      arma::vec& responses,
                      const double lambda = 0);
 
+  /**
+   * Construct the LogisticRegression class with the given labeled training
+   * data.  This will train the model.  Optionally, specify lambda, which is the
+   * penalty parameter for L2-regularization.  If not specified, it is set to 0,
+   * which results in standard (unregularized) logistic regression.
+   *
+   * @param predictors Input training variables.
+   * @param responses Outputs results from input training variables.
+   * @param initialPoint Initial model to train with.
+   * @param lambda L2-regularization parameter.
+   */
   LogisticRegression(arma::mat& predictors,
                      arma::vec& responses,
                      const arma::mat& initialPoint,
@@ -35,9 +57,9 @@
   //! Modify the parameters (the b vector).
   arma::vec& Parameters() { return parameters; }
 
-  //! Return the lambda value
+  //! Return the lambda value for L2-regularization.
   const double& Lambda() const { return lambda; }
-  //! Modify the lambda value
+  //! Modify the lambda value for L2-regularization.
   double& Lambda() { return lambda; }
 
   double LearnModel();
@@ -51,7 +73,7 @@
                          const arma::vec& responses,
                          const double decisionBoundary = 0.5);
 
-  double ComputeError(arma::mat& predictors,const arma::vec& responses);
+  double ComputeError(arma::mat& predictors, const arma::vec& responses);
 
  private:
   arma::vec parameters;

Modified: mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp
==============================================================================
--- mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp	(original)
+++ mlpack/trunk/src/mlpack/methods/logistic_regression/logistic_regression_impl.hpp	Fri Nov  8 14:23:49 2013
@@ -2,7 +2,8 @@
  * @file logistic_regression_impl.hpp
  * @author Sumedh Ghaisas
  *
- * Implementation of the LogisticRegression class.
+ * Implementation of the LogisticRegression class.  This implementation supports
+ * L2-regularization.
  */
 #ifndef __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_IMPL_HPP
 #define __MLPACK_METHODS_LOGISTIC_REGRESSION_LOGISTIC_REGRESSION_IMPL_HPP
@@ -20,7 +21,7 @@
     const double lambda) :
     predictors(predictors),
     responses(responses),
-    errorFunction(LogisticRegressionFunction(predictors,responses,lambda)),
+    errorFunction(LogisticRegressionFunction(predictors, responses, lambda)),
     optimizer(OptimizerType<LogisticRegressionFunction>(errorFunction)),
     lambda(lambda)
 {
@@ -35,7 +36,7 @@
     const double lambda) :
     predictors(predictors),
     responses(responses),
-    errorFunction(LogisticRegressionFunction(predictors,responses)),
+    errorFunction(LogisticRegressionFunction(predictors, responses)),
     optimizer(OptimizerType<LogisticRegressionFunction>(errorFunction)),
     lambda(lambda)
 {
@@ -71,7 +72,7 @@
   ones.ones(predictors.n_cols);
   predictors.insert_rows(0, ones);
 
-  double out = errorFunction.Evaluate(predictors,responses,parameters);
+  double out = errorFunction.Evaluate(predictors, responses, parameters);
 
   predictors.shed_row(0);
 
@@ -84,11 +85,11 @@
     const arma::vec& responses,
     const double decisionBoundary)
 {
-  arma::vec temp_responses;
-  Predict(predictors,temp_responses,decisionBoundary);
+  arma::vec tempResponses;
+  Predict(predictors, tempResponses, decisionBoundary);
   int count = 0;
   for (size_t i = 0; i < responses.n_rows; i++)
-    if (responses(i, 0) == temp_responses(i, 0))
+    if (responses(i, 0) == tempResponses(i, 0))
       count++;
 
   return (double) (count * 100) / responses.n_rows;



More information about the mlpack-svn mailing list