MachineIntelligenceCore:NeuralNets
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
RMSPropTests.cpp
Go to the documentation of this file.
1 
25 #include <gtest/gtest.h>
26 #include <cmath>
27 
29 
30 // Redefine word "public" so every class field/method will be accessible for tests.
31 #define private public
32 #include <optimization/RMSProp.hpp>
33 
34 
35 
37 // RMSProp
39 
40 
45 TEST_F(Sphere1DLandscape, RMSProp_Convergence) {
46  // Optimization function - 1d RMSProp.
47  mic::neural_nets::optimization::RMSProp<double> opt(x->rows(), x->cols(), 1, 0.1);
48 
49  // Simulate a simple gradient descent.
50  size_t iteration = 0;
51  double abs_diff = 1.0;
52  while (abs_diff > eps) {
53  mic::types::MatrixPtr<double> dx = fun.calculateGradient(x);
54  // Update - learning rate not used!
55  opt.update(x, dx, 0.001);
56 
57  // Check whether value of the function is finite.
58  double value = fun.calculateValue(x);
59  ASSERT_EQ(true, std::isfinite(value)) << " at iteration i=" << iteration;
60 
61  // Calculate diff - std:abs!!
62  abs_diff = std::abs(value - fun.minValue());
63  iteration++;
64  }//: while
65  ASSERT_GE(eps, std::abs(fun.calculateValue(x) - fun.minValue()));
66  std::cout << " -> Converged after " << iteration << " iterations\n";
67 }
68 
69 
74 TEST_F(Sphere20DLandscape, RMSProp_Convergence) {
75  // Optimization function - 20d RMSProp (with default values).
76  mic::neural_nets::optimization::RMSProp<double> opt(x->rows(), x->cols());
77 
78  // Simulate a simple gradient descent.
79  size_t iteration = 0;
80  double abs_diff = 1.0;
81  while (abs_diff > eps) {
82  mic::types::MatrixPtr<double> dx = fun.calculateGradient(x);
83  // Update - learning rate not used!
84  opt.update(x, dx, 0.001);
85 
86  // Check whether value of the function is finite.
87  double value = fun.calculateValue(x);
88  ASSERT_EQ(true, std::isfinite(value)) << " at iteration i=" << iteration;
89 
90  // Calculate diff - std:abs!!
91  abs_diff = std::abs(value - fun.minValue());
92  iteration++;
93  }//: while
94  ASSERT_GE(eps, std::abs(fun.calculateValue(x) - fun.minValue()));
95  std::cout << " -> Converged after " << iteration << " iterations\n";
96 }
97 
98 
99 
Test fixture - artificial landscape - sphere function 20D (square function).
Test fixture - artificial landscape - sphere function 1D (square function).
TEST_F(Sphere1DLandscape, RMSProp_Convergence)
virtual void update(mic::types::MatrixPtr< eT > p_, mic::types::MatrixPtr< eT > dp_, eT learning_rate_, eT decay_=0.0)
Update using RMSProp - adaptive gradient descent with running average E[g^2].
Definition: RMSProp.hpp:39