OpenNN  2.2
Open Neural Networks Library
conditions_layer.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* C O N D I T I O N S L A Y E R C L A S S H E A D E R */
7 /* */
8 /* Roberto Lopez */
9 /* Artelnics - Making intelligent use of data */
11 /* */
12 /****************************************************************************************************************/
13 
14 #ifndef __CONDITIONSLAYER_H__
15 #define __CONDITIONSLAYER_H__
16 
17 // System includes
18 
19 #include <cmath>
20 #include <cstdlib>
21 #include <fstream>
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 // OpenNN includes
27 
28 #include "vector.h"
29 #include "matrix.h"
30 
31 // TinyXml includes
32 
33 #include "../tinyxml2/tinyxml2.h"
34 
35 namespace OpenNN
36 {
37 
41 
43 {
44 
45 public:
46 
47  // DEFAULT CONSTRUCTOR
48 
49  explicit ConditionsLayer(void);
50 
51  // INPUTS-CONDITIONS NUMBER CONSTRUCTOR
52 
53  explicit ConditionsLayer(const size_t&, const size_t&);
54 
55  // XML CONSTRUCTOR
56 
57  explicit ConditionsLayer(const tinyxml2::XMLDocument&);
58 
59  // COPY CONSTRUCTOR
60 
62 
63  // DESTRUCTOR
64 
65  virtual ~ConditionsLayer(void);
66 
67  // ASSIGNMENT OPERATOR
68 
70 
71  // EQUAL TO OPERATOR
72 
73  bool operator == (const ConditionsLayer&) const;
74 
75  // ENUMERATIONS
76 
78 
79  enum ConditionsMethod{NoConditions, OneCondition, TwoConditions, UserConditionsMethod};
80 
81  // GET METHODS
82 
83  const size_t& get_external_inputs_number(void) const;
84  const size_t& get_conditions_neurons_number(void) const;
85 
86  const ConditionsMethod& get_conditions_method(void) const;
87  std::string write_conditions_method(void) const;
88 
89  const Vector<double>& get_external_input_values(void) const;
90  const double& get_external_input_value(const size_t&) const;
91 
92  const Matrix<double>& get_output_values(void) const;
93  const double& get_output_value(const size_t&, const size_t&) const;
94 
95  const bool& get_display(void) const;
96 
97  // SET METHODS
98 
99  void set(void);
100  void set(const size_t&, const size_t&);
101  void set(const ConditionsLayer&);
102 
103  void set_external_inputs_number(const size_t&);
104  void set_conditions_neurons_number(const size_t&);
105 
107  void set_conditions_method(const std::string&);
108 
110  void set_external_input_value(const size_t&, const double&);
111 
112  void set_output_values(const Matrix<double>&);
113  void set_output_value(const size_t&, const size_t&, const double&);
114 
115  void set_display(const bool&);
116 
117  void set_default(void);
118 
119  // Conditions
120 
121  void initialize_random(void);
122 
123  void check(void) const;
124 
125  // Particular solution
126 
129 
132 
134 
135  // Homogeneous solution
136 
139 
142 
144 
146 
148 
150 
151  // One condition methods
152 
156 
160 
161  // Two conditions methods
162 
166 
170 
171  // Expression methods
172 
173  virtual std::string write_particular_solution_expression(const Vector<std::string>&, const Vector<std::string>&) const;
174  virtual std::string write_homogeneous_solution_expression(const Vector<std::string>&, const Vector<std::string>&) const;
175 
178 
181 
183 
184  std::string write_expression(const Vector<std::string>&, const Vector<std::string>&, const Vector<std::string>&) const;
185 
186  // Serialization methods
187 
188  std::string to_string(void) const;
189 
190  tinyxml2::XMLDocument* to_XML(void) const;
191  void from_XML(const tinyxml2::XMLDocument&);
192 
193 protected:
194 
197 
199 
202 
204 
206 
208 
210 
212 
214 
216 
218 
219  bool display;
220 
221 };
222 
223 }
224 
225 #endif
226 
227 
228 // OpenNN: Open Neural Networks Library.
229 // Copyright (c) 2005-2015 Roberto Lopez.
230 //
231 // This library is free software; you can redistribute it and/or
232 // modify it under the terms of the GNU Lesser General Public
233 // License as published by the Free Software Foundation; either
234 // version 2.1 of the License, or any later version.
235 //
236 // This library is distributed in the hope that it will be useful,
237 // but WITHOUT ANY WARRANTY; without even the implied warranty of
238 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
239 // Lesser General Public License for more details.
240 
241 // You should have received a copy of the GNU Lesser General Public
242 // License along with this library; if not, write to the Free Software
243 
244 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
245 
void set_external_input_values(const Vector< double > &)
const size_t & get_external_inputs_number(void) const
Returns the number of external inputs.
Matrix< double > calculate_Jacobian(const Vector< double > &, const Vector< double > &, const Matrix< double > &) const
std::string write_two_conditions_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
void set_default(void)
Sets the members of this conditions layer object to their default values.
const double & get_output_value(const size_t &, const size_t &) const
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &, const Vector< double > &) const
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_outputs(const Vector< double > &, const Vector< double > &) const
void set_conditions_neurons_number(const size_t &)
Vector< double > calculate_two_conditions_particular_solution(const Vector< double > &) const
const size_t & get_conditions_neurons_number(void) const
Returns the number of conditions neurons.
void set_external_inputs_number(const size_t &)
Vector< Matrix< double > > calculate_one_condition_homogeneous_solution_Hessian_form(const Vector< double > &) const
Vector< double > calculate_two_conditions_homogeneous_solution(const Vector< double > &) const
void set_output_values(const Matrix< double > &)
void set_display(const bool &)
bool operator==(const ConditionsLayer &) const
Vector< Matrix< double > > calculate_two_conditions_homogeneous_solution_Hessian_form(const Vector< double > &) const
Computes the homogeneous solution Hessian form for the two boundary conditions case.
const Vector< double > & get_external_input_values(void) const
Returns the input values for the conditions.
Vector< double > external_input_values
Independent values of the conditions.
virtual std::string write_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_one_condition_homogeneous_solution(const Vector< double > &) const
void set_conditions_method(const ConditionsMethod &)
const ConditionsMethod & get_conditions_method(void) const
const bool & get_display(void) const
virtual ~ConditionsLayer(void)
Destructor.
virtual Matrix< double > calculate_homogeneous_solution_Jacobian(const Vector< double > &) const
Returns the homogeneous solution Jacobian for applying boundary conditions.
ConditionsLayer & operator=(const ConditionsLayer &)
std::string write_two_conditions_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
tinyxml2::XMLDocument * to_XML(void) const
Serializes the conditions layer object into a document of the TinyXML library.
std::string write_one_condition_particular_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
std::string write_output_expression(const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &, const Vector< std::string > &) const
Matrix< double > calculate_one_condition_homogeneous_solution_Jacobian(const Vector< double > &) const
Computes the homogeneous solution Jacobian for the one boundary condition case.
std::string to_string(void) const
Returns a string representation of the current conditions layer object.
virtual Vector< double > calculate_homogeneous_solution(const Vector< double > &) const
Returns the homogeneous solution for applying boundary conditions.
Matrix< double > calculate_one_condition_particular_solution_Jacobian(const Vector< double > &) const
Computes the Jacobian of the particular solution function for the one boundary condition case...
void from_XML(const tinyxml2::XMLDocument &)
Matrix< double > output_values
Dependent values of the conditions.
Vector< Matrix< double > > calculate_one_condition_particular_solution_Hessian_form(const Vector< double > &) const
void set_external_input_value(const size_t &, const double &)
virtual Vector< double > calculate_particular_solution(const Vector< double > &) const
Returns the particular solution for applying boundary conditions.
virtual std::string write_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< Matrix< double > > calculate_two_conditions_particular_solution_Hessian_form(const Vector< double > &) const
ConditionsMethod conditions_method
Conditions method (one or two conditions).
Matrix< double > calculate_two_conditions_homogeneous_solution_Jacobian(const Vector< double > &) const
ConditionsMethod
Enumeration of available methods for applying conditions.
void set_output_value(const size_t &, const size_t &, const double &)
std::string write_one_condition_homogeneous_solution_expression(const Vector< std::string > &, const Vector< std::string > &) const
std::string write_conditions_method(void) const
const double & get_external_input_value(const size_t &) const
void check(void) const
Checks that all the members of the conditions layer are correct before calculating the outputs from t...
Vector< double > calculate_one_condition_particular_solution(const Vector< double > &) const
virtual Vector< Matrix< double > > calculate_particular_solution_Hessian_form(const Vector< double > &) const
virtual Matrix< double > calculate_particular_solution_Jacobian(const Vector< double > &) const
Returns the particular solution Jacobian for applying boundary conditions.
virtual Vector< Matrix< double > > calculate_homogeneous_solution_Hessian_form(const Vector< double > &) const
Matrix< double > calculate_two_conditions_particular_solution_Jacobian(const Vector< double > &) const
bool display
Display messages to screen.
const Matrix< double > & get_output_values(void) const
Returns the output values for the conditions.