SuperNN  1.0.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 - 2015 Lucas Hermann Negri
18 */
19 
20 #ifndef SUPERNN_UTILS_HPP
21 #define SUPERNN_UTILS_HPP
22 
23 #include <exception>
24 #include <algorithm>
25 
26 #if defined (WIN32)
27  #if defined (_MSC_VER)
28  #pragma warning(disable: 4251)
29  #endif
30 
31  #define SUPERNN_EXPORT __declspec(dllexport)
32 #else
33  #define SUPERNN_EXPORT
34 #endif
35 
36 namespace SuperNN
37 {
39 const unsigned file_precision = 12;
40 
43 {
46 
49 
52 
55 
58 
61 
64 };
65 
69 class SUPERNN_EXPORT Exception : public std::exception
70 {
71 
72 public:
73  Exception(ErrorType type = ERROR_GENERIC) : m_type(type)
74  {
75  }
76 
77  const char* what() const throw()
78  {
79  return "SuperNN exception";
80  }
81 
83  {
84  return m_type;
85  }
86 
87 private:
88  ErrorType m_type;
89 };
90 
94 namespace Utils
95 {
102 SUPERNN_EXPORT double rand_double(double max);
103 
107 SUPERNN_EXPORT void rand_seed();
108 
117 inline double limit(double min, double max, double value)
118 {
119  return std::max(min, std::min(max, value));
120 }
121 }
122 }
123 
124 #endif
Exception(ErrorType type=ERROR_GENERIC)
Definition: utils.hpp:73
thrown when a file couldn't be opened
Definition: utils.hpp:45
ErrorType type()
Definition: utils.hpp:82
const unsigned file_precision
Precision used when writting floating point number to files.
Definition: utils.hpp:39
thrown when training with a non-diferentiable activation function
Definition: utils.hpp:57
SUPERNN_EXPORT void rand_seed()
Initializes the random number generator.
Definition: utils.cpp:41
SUPERNN_EXPORT 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:51
thrown when no other type applies
Definition: utils.hpp:63
ErrorType
Errors that the library can throw.
Definition: utils.hpp:42
The exception can be identified by the type() method.
Definition: utils.hpp:69
thrown when a matrix can't be solved/inverted
Definition: utils.hpp:54
thrown when a file has invalid contents
Definition: utils.hpp:48
thrown when the dimensions of a Row and the network does not match
Definition: utils.hpp:60
const char * what() const
Definition: utils.hpp:77
double limit(double min, double max, double value)
Returns the value limited to a range.
Definition: utils.hpp:117