SuperNN  0.7.0
utils.hpp
1 /*
2  This file is part of SuperNN.
3 
4  SuperNN is free software: you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  SuperNN is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  along with SuperNN. If not, see <http://www.gnu.org/licenses/>.
16 
17  Copyright (C) 2010 - 2014 Lucas Hermann Negri
18 */
19 
20 #ifndef SUPERNN_UTILS_HPP
21 #define SUPERNN_UTILS_HPP
22 
23 #include <exception>
24 #include <algorithm>
25 
26 namespace SuperNN
27 {
29 const unsigned file_precision = 12;
30 
33 {
36 
39 
42 
45 
48 
51 
54 };
55 
59 class Exception : public std::exception
60 {
61 
62 public:
64  {
65  }
66 
67  const char* what() const throw()
68  {
69  return "SuperNN exception";
70  }
71 
73  {
74  return m_type;
75  }
76 
77 private:
78  ErrorType m_type;
79 };
80 
84 namespace Utils
85 {
92 double rand_double(double max);
93 
97 void rand_seed();
98 
107 inline double limit(double min, double max, double value)
108 {
109  return std::max(min, std::min(max, value));
110 }
111 }
112 }
113 
114 #endif
Exception(ErrorType type=ERROR_GENERIC)
Definition: utils.hpp:63
thrown when a file couldn't be opened
Definition: utils.hpp:35
ErrorType type()
Definition: utils.hpp:72
const unsigned file_precision
Precision used when writting floating point number to files.
Definition: utils.hpp:29
thrown when training with a non-diferentiable activation function
Definition: utils.hpp:47
void rand_seed()
Initializes the random number generator.
Definition: utils.cpp:41
double rand_double(double max)
Returns a pseudo-random double.
Definition: utils.cpp:36
thrown when calling a function with invalid parameters
Definition: utils.hpp:41
thrown when no other type applies
Definition: utils.hpp:53
ErrorType
Errors that the library can throw.
Definition: utils.hpp:32
The exception can be identified by the type() method.
Definition: utils.hpp:59
thrown when a matrix can't be solved/inverted
Definition: utils.hpp:44
thrown when a file has invalid contents
Definition: utils.hpp:38
thrown when the dimensions of a Row and the network does not match
Definition: utils.hpp:50
const char * what() const
Definition: utils.hpp:67
double limit(double min, double max, double value)
Returns the value limited to a range.
Definition: utils.hpp:107