Machine Learning Library
CLearnRate.h
Go to the documentation of this file.
1 /*
2  COPYRIGHT (C) 2003 APPLIED NEUROINFORMATIC GROUP - UNIVERSITY OF BIELEFELD.
3 
4  ALL RIGHTS RESERVED.
5 
6  REDISTRIBUTION AND USE IN SOURCE AND BINARY FORM, WITH OR WITHOUT
7  MODIFICATION, REQUIRE THE PERMISSION OF THE COPYRIGHT HOLDERS.
8 
9  COMMERCIAL USE WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT HOLDERS
10  IS FORBIDDEN
11 
12  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
13  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 
25 
26 #ifndef CLEARNRATE_H
27 #define CLEARNRATE_H
28 
29 #include <cmath>
30 #include <cstdio>
31 #include <cassert>
32 #include "CObject.h"
33 /******************************************************************************/
38 template<class Type>
39 class CLearnRate : public CObject<Type> {
40 
41 protected:
42 
43  Type tInitial;
44  Type tFinal;
45  Type tRate;
46  Type tDecay;
49 
50 public:
51 
52 /*----------------------------------------------------------------------------*/
57  virtual Type iterate(void) { return 0; }
58  virtual ~CLearnRate(){};
59 /*----------------------------------------------------------------------------*/
63  virtual Type rate(int iIterationNumber) { return 0; }
64 
65  void setInitial(Type tVal) { tInitial = tVal; }
66  void setFinal(Type tVal) { tFinal = tVal; }
67  void setIterations(int iVal) { iMaxIteration = iVal; }
68  void reset() { iIteration = 0; tRate = tInitial;}
69  void setIteration(int iVal) { iIteration = iVal; }
70 
71  Type getInitial() { return tInitial; }
72  Type getFinal() { return tFinal; }
73  Type getRate() { return tRate; }
74  int getIterations() { return iMaxIteration; }
75  int getIteration() { return iIteration; }
76  virtual string className() const { return string("CLearnRate"); };
77  virtual bool isA(const char* acClass) const {
78  if(string(acClass) == this->className())
79  return true;
80  else
81  return CObject<Type>::isA(acClass);
82  };
83  virtual bool serialize (fstream &stream, IO_MODE mode=READ);
84 };
85 
86 /******************************************************************************/
91 template<class Type>
92 class CConstantRate : public CLearnRate<Type>{
93 
94 public:
95 
96 /*----------------------------------------------------------------------------*/
101  CConstantRate(Type tLearnRate=1.0);
102 
103 /*----------------------------------------------------------------------------*/
109  Type iterate(void);
110 
111 /*----------------------------------------------------------------------------*/
118  Type rate(int iIterationNumber);
119 
120 
121  virtual string className() const { return "CConstantRate"; };
122  virtual bool isA(const char* acClass) const {
123  if(string(acClass) == this->className())
124  return true;
125  else
126  return CLearnRate<Type>::isA(acClass);
127  };
128 };
129 
130 /******************************************************************************/
135 template<class Type>
136 class CHarmonicRate : public CLearnRate<Type>{
137 
138 public:
139 
140 /*----------------------------------------------------------------------------*/
145  CHarmonicRate(Type tInitialRate=1.0);
146 
147 /*----------------------------------------------------------------------------*/
153  Type iterate(void);
154 
155 /*----------------------------------------------------------------------------*/
162  Type rate(int iIterationNumber);
163 
164  virtual string className() const { return "CHarmonicRate"; };
165  virtual bool isA(const char* acClass) const {
166  if(string(acClass) == this->className())
167  return true;
168  else
169  return CLearnRate<Type>::isA(acClass);
170  };
171 };
172 
173 
174 /******************************************************************************/
179 template<class Type>
180 class CLinearRate : public CLearnRate<Type>{
181 
182 public:
183 
184 /*----------------------------------------------------------------------------*/
191  CLinearRate(Type tInitialRate=0.5, Type tFinalRate=0.01, int iMaxIterationNumber=100);
192 
193 /*----------------------------------------------------------------------------*/
199  Type iterate(void);
200 
201 /*----------------------------------------------------------------------------*/
208  Type rate(int iIterationNumber);
209 
210  virtual string className() const { return "CLinearRate"; };
211  virtual bool isA(const char* acClass) const {
212  if(string(acClass) == this->className())
213  return true;
214  else
215  return CLearnRate<Type>::isA(acClass);
216  };
217 };
218 
219 
220 /******************************************************************************/
226 template<class Type>
227 class CExponentialRate : public CLearnRate<Type>{
228 
229 public:
230 
231 /*----------------------------------------------------------------------------*/
238  CExponentialRate(Type tInitialRate=0.5, Type tFinalRate=0.01, int iMaxIterationNumber=100);
239 
240 /*----------------------------------------------------------------------------*/
246  Type iterate(void);
247 
248 /*----------------------------------------------------------------------------*/
255  Type rate(int iIterationNumber);
256 
257  virtual string className() const { return "CExponentialRate"; };
258  virtual bool isA(const char* acClass) const {
259  if(string(acClass) == this->className())
260  return true;
261  else
262  return CLearnRate<Type>::isA(acClass);
263  };
264 };
265 
266 #endif
void setInitial(Type tVal)
Definition: CLearnRate.h:65
CConstantRate(Type tLearnRate=1.0)
Base class for all learning rate functions Template base class for all learning rates (virtual)...
Definition: CLearnRate.h:39
Type tDecay
Definition: CLearnRate.h:46
Exponential decreasing learn rate Template class for exponential decreasing learning rates...
Definition: CLearnRate.h:227
Type iterate(void)
int iIteration
Definition: CLearnRate.h:48
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CLearnRate.h:211
void reset()
Definition: CLearnRate.h:68
IO_MODE
Definition: CObject.h:38
Constante learn rate Template class for constant learn rates.
Definition: CLearnRate.h:92
virtual Type iterate(void)
Definition: CLearnRate.h:57
Type tFinal
Definition: CLearnRate.h:44
virtual string className() const
Returns the class name.
Definition: CLearnRate.h:121
Type rate(int iIterationNumber)
virtual string className() const
Returns the class name.
Definition: CLearnRate.h:257
Type getRate()
Definition: CLearnRate.h:73
CHarmonicRate(Type tInitialRate=1.0)
Type rate(int iIterationNumber)
CExponentialRate(Type tInitialRate=0.5, Type tFinalRate=0.01, int iMaxIterationNumber=100)
CLinearRate(Type tInitialRate=0.5, Type tFinalRate=0.01, int iMaxIterationNumber=100)
Type iterate(void)
virtual Type rate(int iIterationNumber)
Definition: CLearnRate.h:63
Type iterate(void)
Definition: CObject.h:38
virtual ~CLearnRate()
Definition: CLearnRate.h:58
Linear decreasing learn rate Template class for linear decreasing learning rates. ...
Definition: CLearnRate.h:180
Definition: CLearnRate.h:136
virtual string className() const
Returns the class name.
Definition: CLearnRate.h:210
Type rate(int iIterationNumber)
int iMaxIteration
Definition: CLearnRate.h:47
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CLearnRate.h:258
void setIteration(int iVal)
Definition: CLearnRate.h:69
Base class for all object.
Definition: CObject.h:51
Type getInitial()
Definition: CLearnRate.h:71
Type tInitial
Definition: CLearnRate.h:43
virtual string className() const
Returns the class name.
Definition: CLearnRate.h:164
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CLearnRate.h:165
void setIterations(int iVal)
Definition: CLearnRate.h:67
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CObject.h:93
Type tRate
Definition: CLearnRate.h:45
virtual string className() const
Returns the class name.
Definition: CLearnRate.h:76
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CLearnRate.h:77
int getIteration()
Definition: CLearnRate.h:75
int getIterations()
Definition: CLearnRate.h:74
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CLearnRate.h:122
virtual bool serialize(fstream &stream, IO_MODE mode=READ)
Read/write from binary stream.
Type getFinal()
Definition: CLearnRate.h:72
Type iterate(void)
void setFinal(Type tVal)
Definition: CLearnRate.h:66
Type rate(int iIterationNumber)