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

This commit is contained in:
marcus
2016-03-11 16:24:02 +01:00
parent e6f7ffe266
commit f0e331889a
6 changed files with 11 additions and 5 deletions
+1 -1
View File
@@ -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
+3 -1
View File
@@ -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);
+1 -1
View File
@@ -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,
+3 -1
View File
@@ -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);
+1 -1
View File
@@ -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
+2
View File
@@ -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);