[mlpack-git] master: Use Row, not vec, for predictions. (d2bcc6b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Nov 19 16:17:37 EST 2015


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

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/319205b2f3103187c584db302b1a3683aa2fbfdf...a1dada8ba0f88f14653f09ea8c3ec8b04d982434

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

commit d2bcc6b829bc15b3e5d1fe2537cef1876397f06a
Author: Ryan Curtin <ryan at ratml.org>
Date:   Thu Nov 19 12:57:31 2015 -0800

    Use Row, not vec, for predictions.


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

d2bcc6b829bc15b3e5d1fe2537cef1876397f06a
 .../methods/softmax_regression/softmax_regression.hpp       |  2 +-
 .../methods/softmax_regression/softmax_regression_impl.hpp  | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/mlpack/methods/softmax_regression/softmax_regression.hpp b/src/mlpack/methods/softmax_regression/softmax_regression.hpp
index 25f96e8..af83b04 100644
--- a/src/mlpack/methods/softmax_regression/softmax_regression.hpp
+++ b/src/mlpack/methods/softmax_regression/softmax_regression.hpp
@@ -111,7 +111,7 @@ class SoftmaxRegression
    * @param testData Matrix of data points for which predictions are to be made.
    * @param predictions Vector to store the predictions in.
    */
-  void Predict(const arma::mat& testData, arma::vec& predictions) const;
+  void Predict(const arma::mat& testData, arma::Row<size_t>& predictions) const;
 
   /**
    * Computes accuracy of the learned model given the feature data and the
diff --git a/src/mlpack/methods/softmax_regression/softmax_regression_impl.hpp b/src/mlpack/methods/softmax_regression/softmax_regression_impl.hpp
index d21b295..d95cad4 100644
--- a/src/mlpack/methods/softmax_regression/softmax_regression_impl.hpp
+++ b/src/mlpack/methods/softmax_regression/softmax_regression_impl.hpp
@@ -58,7 +58,8 @@ SoftmaxRegression<OptimizerType>::SoftmaxRegression(
 
 template<template<typename> class OptimizerType>
 void SoftmaxRegression<OptimizerType>::Predict(const arma::mat& testData,
-                                               arma::vec& predictions) const
+                                               arma::Row<size_t>& predictions)
+    const
 {
   if (testData.n_rows != FeatureSize())
   {
@@ -95,16 +96,16 @@ void SoftmaxRegression<OptimizerType>::Predict(const arma::mat& testData,
   double maxProbability = 0;
 
   // For each test input.
-  for(size_t i = 0; i < testData.n_cols; i++)
+  for (size_t i = 0; i < testData.n_cols; i++)
   {
     // For each class.
-    for(size_t j = 0; j < numClasses; j++)
+    for (size_t j = 0; j < numClasses; j++)
     {
       // If a higher class probability is encountered, change prediction.
-      if(probabilities(j, i) > maxProbability)
+      if (probabilities(j, i) > maxProbability)
       {
         maxProbability = probabilities(j, i);
-        predictions(i) = static_cast<double>(j);
+        predictions(i) = j;
       }
     }
 
@@ -118,7 +119,7 @@ double SoftmaxRegression<OptimizerType>::ComputeAccuracy(
     const arma::mat& testData,
     const arma::Row<size_t>& labels)
 {
-  arma::vec predictions;
+  arma::Row<size_t> predictions;
 
   // Get predictions for the provided data.
   Predict(testData, predictions);



More information about the mlpack-git mailing list