SHOGUN  6.1.3
RmsPropUpdater.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2015 Wu Lin
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  *
30  */
31 
34 #include <shogun/base/Parameter.h>
35 using namespace shogun;
36 
39 {
40  init();
41 }
42 
43 RmsPropUpdater::RmsPropUpdater(float64_t learning_rate,float64_t epsilon,float64_t decay_factor)
45 {
46  init();
47  set_learning_rate(learning_rate);
48  set_epsilon(epsilon);
49  set_decay_factor(decay_factor);
50 }
51 
53 {
54  REQUIRE(learning_rate>0,"Learning_rate (%f) must be positive\n",
55  learning_rate);
56  m_build_in_learning_rate=learning_rate;
57 }
58 
60 {
61  REQUIRE(epsilon>=0,"Epsilon (%f) must be non-negative\n",
62  epsilon);
63  m_epsilon=epsilon;
64 }
65 
67 {
68  REQUIRE(decay_factor>=0.0 && decay_factor<1.0,
69  "decay factor (%f) must in [0,1)\n",
70  decay_factor);
71  m_decay_factor=decay_factor;
72 }
73 
75 
76 void RmsPropUpdater::init()
77 {
78  m_decay_factor=0.9;
79  m_epsilon=1e-6;
82 
83  SG_ADD(&m_decay_factor, "RmsPropUpdater__m_decay_factor",
84  "decay_factor in RmsPropUpdater", MS_NOT_AVAILABLE);
85  SG_ADD(&m_epsilon, "RmsPropUpdater__m_epsilon",
86  "epsilon in RmsPropUpdater", MS_NOT_AVAILABLE);
87  SG_ADD(&m_build_in_learning_rate, "RmsPropUpdater__m_build_in_learning_rate",
88  "build_in_learning_rate in RmsPropUpdater", MS_NOT_AVAILABLE);
89  SG_ADD(&m_gradient_accuracy, "RmsPropUpdater__m_gradient_accuracy",
90  "gradient_accuracy in RmsPropUpdater", MS_NOT_AVAILABLE);
91 }
92 
94  float64_t gradient, index_t idx, float64_t learning_rate)
95 {
96  REQUIRE(idx>=0 && idx<m_gradient_accuracy.vlen,
97  "Index (%d) is invalid\n", idx);
99  (1.0-m_decay_factor)*gradient*gradient;
102  return res;
103 }
104 
106  SGVector<float64_t> raw_negative_descend_direction, float64_t learning_rate)
107 {
108  REQUIRE(variable_reference.vlen>0,"variable_reference must set\n");
109  REQUIRE(variable_reference.vlen==raw_negative_descend_direction.vlen,
110  "The length of variable_reference (%d) and the length of gradient (%d) do not match\n",
111  variable_reference.vlen,raw_negative_descend_direction.vlen);
113  {
114  m_gradient_accuracy=SGVector<float64_t>(variable_reference.vlen);
116  }
117  DescendUpdaterWithCorrection::update_variable(variable_reference, raw_negative_descend_direction, learning_rate);
118 }
SGVector< float64_t > m_gradient_accuracy
int32_t index_t
Definition: common.h:72
static T sqrt(T x)
Definition: Math.h:428
void scale(SGVector< T > &a, SGVector< T > &result, T alpha=1)
#define REQUIRE(x,...)
Definition: SGIO.h:181
virtual void set_decay_factor(float64_t decay_factor)
virtual float64_t get_negative_descend_direction(float64_t variable, float64_t gradient, index_t idx, float64_t learning_rate)
float64_t m_build_in_learning_rate
double float64_t
Definition: common.h:60
virtual void set_learning_rate(float64_t learning_rate)
virtual void update_variable(SGVector< float64_t > variable_reference, SGVector< float64_t > raw_negative_descend_direction, float64_t learning_rate)
virtual void update_variable(SGVector< float64_t > variable_reference, SGVector< float64_t > raw_negative_descend_direction, float64_t learning_rate)
virtual void set_epsilon(float64_t epsilon)
void set_const(T const_elem)
Definition: SGVector.cpp:199
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
This is a base class for descend update with descend based correction.
#define SG_ADD(...)
Definition: SGObject.h:93
index_t vlen
Definition: SGVector.h:571

SHOGUN Machine Learning Toolbox - Documentation