bounding_layer.h
1// OpenNN: Open Neural Networks Library
2// www.opennn.net
3//
4// B O U N D I N G L A Y E R C L A S S H E A D E R
5//
6// Artificial Intelligence Techniques SL
7// artelnics@artelnics.com
8
9#ifndef BOUNDINGLAYER_H
10#define BOUNDINGLAYER_H
11
12// System includes
13
14#include <cmath>
15#include <cstdlib>
16#include <iostream>
17#include <fstream>
18#include <sstream>
19#include <string>
20
21// OpenNN includes
22
23#include "layer.h"
24
25#include "config.h"
26
27namespace OpenNN
28{
29
31
33
34class BoundingLayer : public Layer
35{
36
37public:
38
39 // Constructors
40
41 explicit BoundingLayer();
42
43 explicit BoundingLayer(const Index&);
44
45 // Destructor
46
47 virtual ~BoundingLayer();
48
49 // Enumerations
50
52
53 enum class BoundingMethod{NoBounding, Bounding};
54
55 // Check methods
56
57 bool is_empty() const;
58
59 // Get methods
60
61
62 Index get_inputs_number() const;
63 Index get_neurons_number() const;
64
66
67 string write_bounding_method() const;
68
69 const Tensor<type, 1>& get_lower_bounds() const;
70 type get_lower_bound(const Index&) const;
71
72 const Tensor<type, 1>& get_upper_bounds() const;
73 type get_upper_bound(const Index&) const;
74
75 // Variables bounds
76
77 void set();
78 void set(const Index&);
79 void set(const tinyxml2::XMLDocument&);
80 void set(const BoundingLayer&);
81
82 void set_inputs_number(const Index&);
83 void set_neurons_number(const Index&);
84
86 void set_bounding_method(const string&);
87
88 void set_lower_bounds(const Tensor<type, 1>&);
89 void set_lower_bound(const Index&, const type&);
90
91 void set_upper_bounds(const Tensor<type, 1>&);
92 void set_upper_bound(const Index&, const type&);
93
94 void set_display(const bool&);
95
96 void set_default();
97
98 // Lower and upper bounds
99
100 Tensor<type, 2> calculate_outputs(const Tensor<type, 2>&);
101
102 // Expression methods
103
104 string write_expression(const Tensor<string, 1>&, const Tensor<string, 1>&) const;
105
106 string write_expression_c() const;
107 string write_expression_python() const;
108
109 // Serialization methods
110
111 void from_XML(const tinyxml2::XMLDocument&);
112
113 void write_XML(tinyxml2::XMLPrinter&) const;
114
115protected:
116
117 // MEMBERS
118
120
121 BoundingMethod bounding_method = BoundingMethod::Bounding;
122
124
125 Tensor<type, 1> lower_bounds;
126
128
129 Tensor<type, 1> upper_bounds;
130
132
133 bool display = true;
134};
135
136}
137
138#endif
139
140
141// OpenNN: Open Neural Networks Library.
142// Copyright(C) 2005-2021 Artificial Intelligence Techniques, SL.
143//
144// This library is free software; you can redistribute it and/or
145// modify it under the terms of the GNU Lesser General Public
146// License as published by the Free Software Foundation; either
147// version 2.1 of the License, or any later version.
148//
149// This library is distributed in the hope that it will be useful,
150// but WITHOUT ANY WARRANTY; without even the implied warranty of
151// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152// Lesser General Public License for more details.
153
154// You should have received a copy of the GNU Lesser General Public
155// License along with this library; if not, write to the Free Software
156
157// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
158
This class represents a layer of bounding neurons.
void set_lower_bounds(const Tensor< type, 1 > &)
string write_expression_c() const
BoundingLayer::write_expression_c.
void set_upper_bound(const Index &, const type &)
type get_upper_bound(const Index &) const
void set_lower_bound(const Index &, const type &)
Index get_inputs_number() const
Get number of inputs.
string write_expression(const Tensor< string, 1 > &, const Tensor< string, 1 > &) const
Returns a string with the expression of the lower and upper bounds functions.
void from_XML(const tinyxml2::XMLDocument &)
string write_expression_python() const
BoundingLayer::write_expression_python.
bool display
Display messages to screen.
Tensor< type, 1 > lower_bounds
Lower bounds of output variables.
bool is_empty() const
Returns true if the size of the layer is zero, and false otherwise.
BoundingMethod
Enumeration of available methods for bounding the output variables.
const BoundingMethod & get_bounding_method() const
Returns the method used for bounding layer.
void set_inputs_number(const Index &)
Tensor< type, 2 > calculate_outputs(const Tensor< type, 2 > &)
Index get_neurons_number() const
Return the neurons number in the bounding layer.
void set_upper_bounds(const Tensor< type, 1 > &)
const Tensor< type, 1 > & get_upper_bounds() const
Returns the upper bounds values of all the bounding neurons in the layer.
const Tensor< type, 1 > & get_lower_bounds() const
Returns the lower bounds values of all the bounding neurons in the layer.
BoundingMethod bounding_method
Method used to bound the values.
void set_display(const bool &)
void write_XML(tinyxml2::XMLPrinter &) const
string write_bounding_method() const
Returns a string writing if use bounding layer or not.
void set_bounding_method(const BoundingMethod &)
void set_neurons_number(const Index &)
Tensor< type, 1 > upper_bounds
Upper bounds of output variables.
type get_lower_bound(const Index &) const
This abstract class represents the concept of layer of neurons in OpenNN.
Definition: layer.h:53