OpenNN  2.2
Open Neural Networks Library
ordinary_differential_equations.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* O R D I N A R Y D I F F E R E N T I A L E Q U A T I O N S 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 __ORDINARYDIFFERENTIALEQUATIONS_H__
15 #define __ORDINARYDIFFERENTIALEQUATIONS_H__
16 
17 // System includes
18 
19 #include<fstream>
20 #include<iostream>
21 #include<string>
22 #include<sstream>
23 #include <time.h>
24 
25 // OpenNN includes
26 
27 #include "vector.h"
28 #include "matrix.h"
29 
30 #include "mathematical_model.h"
31 
32 #include "neural_network.h"
33 
34 // TinyXml includes
35 
36 #include "../tinyxml2/tinyxml2.h"
37 
38 namespace OpenNN
39 {
40 
45 
46 
48 {
49 
50 public:
51 
52  // DEFAULT CONSTRUCTOR
53 
54  explicit OrdinaryDifferentialEquations(void);
55 
56  // XML CONSTRUCTOR
57 
58  explicit OrdinaryDifferentialEquations(const tinyxml2::XMLDocument&);
59 
60  // FILE CONSTRUCTOR
61 
62  explicit OrdinaryDifferentialEquations(const std::string&);
63 
64  // COPY CONSTRUCTOR
65 
67 
68  // DESTRUCTOR
69 
70  virtual ~OrdinaryDifferentialEquations(void);
71 
72  // ASSIGNMENT OPERATOR
73 
75 
76  // EQUAL TO OPERATOR
77 
79 
80  // Enumerations
81 
83 
84  enum SolutionMethod{RungeKutta, RungeKuttaFehlberg};
85 
86 
87  // METHODS
88 
89  // Get methods
90 
91  const double& get_initial_independent_variable(void) const;
92  const double& get_final_independent_variable(void) const;
93 
95  const double& get_initial_dependent_variable(const size_t&) const;
96 
97  const SolutionMethod& get_solution_method(void) const;
98  std::string write_solution_method(void) const;
99 
100  const size_t& get_points_number(void) const;
101 
102  const double& get_tolerance(void) const;
103 
104  const size_t& get_initial_size(void) const;
105  const size_t& get_warning_size(void) const;
106  const size_t& get_error_size(void) const;
107 
108  // Set methods
109 
110  void set(const OrdinaryDifferentialEquations&);
111 
112  void set_initial_independent_variable(const double&);
113  void set_final_independent_variable(const double&);
114 
116  void set_initial_dependent_variable(const size_t&, const double&);
117 
118  void set_solution_method(const SolutionMethod&);
119  void set_solution_method(const std::string&);
120 
121  void set_points_number(const size_t&);
122 
123  void set_tolerance(const double& );
124 
125  void set_initial_size(const size_t&);
126  void set_warning_size(const size_t&);
127  void set_error_size(const size_t&);
128 
129  virtual void set_default(void);
130 
131  // Ordinary differential equations methods
132 
134 
136 
137  // Numerical solution methods
138 
141 
144 
145  virtual Matrix<double> calculate_solutions(const NeuralNetwork&) const;
147 
148  // Serialization methods
149 
150  std::string to_string(void) const;
151 
152  virtual tinyxml2::XMLDocument* to_XML(void) const;
153  virtual void from_XML(const tinyxml2::XMLDocument&);
154 
155  virtual void save_data(const NeuralNetwork&, const std::string&) const;
156 
157 protected:
158 
160 
162 
164 
166 
168 
170 
172 
174 
176 
178 
180 
181  double tolerance;
182 
184 
185  size_t initial_size;
186 
188 
189  size_t warning_size;
190 
192 
193  size_t error_size;
194 };
195 
196 }
197 
198 #endif
199 
200 
201 // OpenNN: Open Neural Networks Library.
202 // Copyright (c) 2005-2015 Roberto Lopez.
203 //
204 // This library is free software; you can redistribute it and/or
205 // modify it under the terms of the GNU Lesser General Public
206 // License as published by the Free Software Foundation; either
207 // version 2.1 of the License, or any later version.
208 //
209 // This library is distributed in the hope that it will be useful,
210 // but WITHOUT ANY WARRANTY; without even the implied warranty of
211 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
212 // Lesser General Public License for more details.
213 
214 // You should have received a copy of the GNU Lesser General Public
215 // License along with this library; if not, write to the Free Software
216 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
double final_independent_variable
Final value for the only independent variable.
const double & get_initial_independent_variable(void) const
Returns the initial value of the independent variable.
Vector< double > calculate_Runge_Kutta_final_solution(const NeuralNetwork &) const
SolutionMethod
Enumeration of available methods for numerical integration of ordinary differential equations...
virtual Vector< double > calculate_final_solutions(const NeuralNetwork &) const
const size_t & get_error_size(void) const
Returns an error size for the solutions in the Runge-Kutta-Fehlberg method.
std::string write_solution_method(void) const
Returns a string with the name of the numerical method to be used for integration of the ordinary dif...
void set_initial_dependent_variable(const size_t &, const double &)
Matrix< double > calculate_Runge_Kutta_Fehlberg_solution(const NeuralNetwork &) const
const size_t & get_initial_size(void) const
Returns the initial size to be reserved for the solutions in the Runge-Kutta-Fehlberg method...
virtual Vector< double > calculate_dependent_variables_dots(const NeuralNetwork &, const Vector< double > &) const =0
This pure virtual method calculates the derivatives of the dependent variables with respect to the in...
double initial_independent_variable
Initial value for the only independent variable.
size_t warning_size
Number of points at which the the Runge-Kutta-Fehlberg method displays a warning message.
void set_initial_dependent_variables(const Vector< double > &)
size_t error_size
Number of points at which the the Runge-Kutta-Fehlberg method throws an exception.
Matrix< double > calculate_Runge_Kutta_solution(const NeuralNetwork &) const
virtual void from_XML(const tinyxml2::XMLDocument &)
std::string to_string(void) const
Returns a string representation of the current ordinary differential equations object.
double tolerance
Tolerance in the Runge-Kutta-Fehlberg method.
virtual Matrix< double > calculate_solutions(const NeuralNetwork &) const
const SolutionMethod & get_solution_method(void) const
Returns the numerical method to be used for integration of the ordinary differential equation...
size_t points_number
Number of points in the Runge-Kutta method.
size_t initial_size
Initial number of points in the Runge-Kutta-Fehlberg method.
OrdinaryDifferentialEquations & operator=(const OrdinaryDifferentialEquations &)
const double & get_final_independent_variable(void) const
Returns the final value of the independent variable.
const double & get_tolerance(void) const
Returns the tolerance in the Runge-Kutta-Fehlberg method.
const double & get_initial_dependent_variable(const size_t &) const
Vector< double > initial_dependent_variables
Initial values for the dependent variables.
const size_t & get_points_number(void) const
Returns the number of integration points in the Runge-Kutta method.
void set(const OrdinaryDifferentialEquations &)
SolutionMethod solution_method
Numerical integration method (Runge-Kutta or Runge-Kutta-Fehlberg).
virtual void save_data(const NeuralNetwork &, const std::string &) const
const Vector< double > & get_initial_dependent_variables(void) const
Returns the initial values of the independent variables.
Vector< double > calculate_Runge_Kutta_Fehlberg_final_solution(const NeuralNetwork &) const
const size_t & get_warning_size(void) const
Returns a warning size for the solutions in the Runge-Kutta-Fehlberg method.
bool operator==(const OrdinaryDifferentialEquations &) const
virtual tinyxml2::XMLDocument * to_XML(void) const