[mlpack-git] master: Distinguish between testing and training when optimizing the network model. This is useful for models that act differently when in testing or training mode. (f0e3318)

gitdub at mlpack.org gitdub at mlpack.org
Fri Mar 11 10:24:02 EST 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/e6f7ffe266faea0705ad19c7aada8ded99f92706...f0e331889a8a415fb021c2a499d31395bbcecb77

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

commit f0e331889a8a415fb021c2a499d31395bbcecb77
Author: marcus <marcus.edel at fu-berlin.de>
Date:   Fri Mar 11 16:23:40 2016 +0100

    Distinguish between testing and training when optimizing the network model. This is useful for models that act differently when in testing or training mode.


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

f0e331889a8a415fb021c2a499d31395bbcecb77
 src/mlpack/methods/ann/cnn.hpp      | 2 +-
 src/mlpack/methods/ann/cnn_impl.hpp | 4 +++-
 src/mlpack/methods/ann/ffn.hpp      | 2 +-
 src/mlpack/methods/ann/ffn_impl.hpp | 4 +++-
 src/mlpack/methods/ann/rnn.hpp      | 2 +-
 src/mlpack/methods/ann/rnn_impl.hpp | 2 ++
 6 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/mlpack/methods/ann/cnn.hpp b/src/mlpack/methods/ann/cnn.hpp
index 7e6158c..e1872e4 100644
--- a/src/mlpack/methods/ann/cnn.hpp
+++ b/src/mlpack/methods/ann/cnn.hpp
@@ -182,7 +182,7 @@ class CNN
    */
   double Evaluate(const arma::mat& parameters,
                   const size_t i,
-                  const bool deterministic = false);
+                  const bool deterministic = true);
 
   /**
    * Evaluate the gradient of the convolutional neural network with the given
diff --git a/src/mlpack/methods/ann/cnn_impl.hpp b/src/mlpack/methods/ann/cnn_impl.hpp
index 5950fda..1494f9c 100644
--- a/src/mlpack/methods/ann/cnn_impl.hpp
+++ b/src/mlpack/methods/ann/cnn_impl.hpp
@@ -245,9 +245,11 @@ template<typename LayerTypes,
 void CNN<
 LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction
 >::Gradient(const arma::mat& /* unused */,
-            const size_t /* unused */,
+            const size_t i,
             arma::mat& gradient)
 {
+  Evaluate(parameter, i, false);
+
   NetworkGradients(gradient, network);
 
   Backward<>(error, network);
diff --git a/src/mlpack/methods/ann/ffn.hpp b/src/mlpack/methods/ann/ffn.hpp
index d4cd35d..2bed68a 100644
--- a/src/mlpack/methods/ann/ffn.hpp
+++ b/src/mlpack/methods/ann/ffn.hpp
@@ -183,7 +183,7 @@ class FFN
    */
   double Evaluate(const arma::mat& parameters,
                   const size_t i,
-                  const bool deterministic = false);
+                  const bool deterministic = true);
 
   /**
    * Evaluate the gradient of the feedforward network with the given parameters,
diff --git a/src/mlpack/methods/ann/ffn_impl.hpp b/src/mlpack/methods/ann/ffn_impl.hpp
index a057f6b..ca48c30 100644
--- a/src/mlpack/methods/ann/ffn_impl.hpp
+++ b/src/mlpack/methods/ann/ffn_impl.hpp
@@ -249,9 +249,11 @@ template<typename LayerTypes,
 void FFN<
 LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction
 >::Gradient(const arma::mat& /* unused */,
-            const size_t /* unused */,
+            const size_t i,
             arma::mat& gradient)
 {
+  Evaluate(parameter, i, false);
+
   NetworkGradients(gradient, network);
 
   Backward<>(error, network);
diff --git a/src/mlpack/methods/ann/rnn.hpp b/src/mlpack/methods/ann/rnn.hpp
index 9d1d21b..1389a87 100644
--- a/src/mlpack/methods/ann/rnn.hpp
+++ b/src/mlpack/methods/ann/rnn.hpp
@@ -185,7 +185,7 @@ class RNN
    */
   double Evaluate(const arma::mat& parameters,
                   const size_t i,
-                  const bool deterministic = false);
+                  const bool deterministic = true);
 
   /**
    * Evaluate the gradient of the recurrent neural network with the given
diff --git a/src/mlpack/methods/ann/rnn_impl.hpp b/src/mlpack/methods/ann/rnn_impl.hpp
index a01a3ab..f5b519a 100644
--- a/src/mlpack/methods/ann/rnn_impl.hpp
+++ b/src/mlpack/methods/ann/rnn_impl.hpp
@@ -281,6 +281,8 @@ LayerTypes, OutputLayerType, InitializationRuleType, PerformanceFunction
             const size_t i,
             arma::mat& gradient)
 {
+  Evaluate(parameter, i, false);
+
   gradient.zeros();
   arma::mat currentGradient = arma::mat(gradient.n_rows, gradient.n_cols);
   NetworkGradients(currentGradient, network);




More information about the mlpack-git mailing list