From 3f74da5da9fd90087056aa6c3587dd26513a5b65 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 23 May 2019 14:36:32 +0200 Subject: [PATCH] lstmtrainer: Set constant kLearningRateDecay at compile time sqrt(0.5) = 1 / sqrt(2) can be replaced by the macro M_SQRT1_2. This also fixes a compiler warning: src/lstm/lstmtrainer.cpp:51:14: warning: declaration requires a global constructor [-Wglobal-constructors] Signed-off-by: Stefan Weil --- src/lstm/lstmtrainer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lstm/lstmtrainer.cpp b/src/lstm/lstmtrainer.cpp index 31a92c231c..fa4bb1cf84 100644 --- a/src/lstm/lstmtrainer.cpp +++ b/src/lstm/lstmtrainer.cpp @@ -15,6 +15,8 @@ // limitations under the License. /////////////////////////////////////////////////////////////////////// +#define _USE_MATH_DEFINES // needed to get definition of M_SQRT1_2 + // Include automatically generated configuration file if running autoconf. #ifdef HAVE_CONFIG_H #include "config_auto.h" @@ -48,7 +50,7 @@ const int kMinStallIterations = 10000; // before we declare the sub_trainer_ a success and switch to it. const double kSubTrainerMarginFraction = 3.0 / 128; // Factor to reduce learning rate on divergence. -const double kLearningRateDecay = sqrt(0.5); +const double kLearningRateDecay = M_SQRT1_2; // LR adjustment iterations. const int kNumAdjustmentIterations = 100; // How often to add data to the error_graph_.