00001 /****************************************************************************************************************/ 00002 /* */ 00003 /* OpenNN: Open Neural Networks Library */ 00004 /* www.opennn.cimne.com */ 00005 /* */ 00006 /* 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 */ 00007 /* */ 00008 /* Roberto Lopez */ 00009 /* International Center for Numerical Methods in Engineering (CIMNE) */ 00010 /* Technical University of Catalonia (UPC) */ 00011 /* Barcelona, Spain */ 00012 /* E-mail: rlopez@cimne.upc.edu */ 00013 /* */ 00014 /****************************************************************************************************************/ 00015 00016 00017 #ifndef __ORDINARYDIFFERENTIALEQUATIONS_H__ 00018 #define __ORDINARYDIFFERENTIALEQUATIONS_H__ 00019 00020 // OpenNN includes 00021 00022 #include "../utilities/vector.h" 00023 #include "../utilities/matrix.h" 00024 00025 #include "mathematical_model.h" 00026 00027 #include "../neural_network/neural_network.h" 00028 00029 namespace OpenNN 00030 { 00031 00036 00037 00038 class OrdinaryDifferentialEquations : public MathematicalModel 00039 { 00040 00041 public: 00042 00043 // DEFAULT CONSTRUCTOR 00044 00045 explicit OrdinaryDifferentialEquations(void); 00046 00047 // XML CONSTRUCTOR 00048 00049 explicit OrdinaryDifferentialEquations(TiXmlElement*); 00050 00051 // FILE CONSTRUCTOR 00052 00053 explicit OrdinaryDifferentialEquations(const std::string&); 00054 00055 // COPY CONSTRUCTOR 00056 00057 OrdinaryDifferentialEquations(const OrdinaryDifferentialEquations&); 00058 00059 // DESTRUCTOR 00060 00061 virtual ~OrdinaryDifferentialEquations(void); 00062 00063 // ASSIGNMENT OPERATOR 00064 00065 OrdinaryDifferentialEquations& operator = (const OrdinaryDifferentialEquations&); 00066 00067 // EQUAL TO OPERATOR 00068 00069 bool operator == (const OrdinaryDifferentialEquations&) const; 00070 00071 // Enumerations 00072 00074 00075 enum SolutionMethod{RungeKutta, RungeKuttaFehlberg}; 00076 00077 00078 // METHODS 00079 00080 // Get methods 00081 00082 const double& get_initial_independent_variable(void) const; 00083 const double& get_final_independent_variable(void) const; 00084 00085 const Vector<double>& get_initial_dependent_variables(void) const; 00086 const double& get_initial_dependent_variable(const unsigned int&) const; 00087 00088 const SolutionMethod& get_solution_method(void) const; 00089 std::string write_solution_method(void) const; 00090 00091 const unsigned int& get_points_number(void) const; 00092 00093 const double& get_tolerance(void) const; 00094 00095 const unsigned int& get_initial_size(void) const; 00096 const unsigned int& get_warning_size(void) const; 00097 const unsigned int& get_error_size(void) const; 00098 00099 // Set methods 00100 00101 void set(const OrdinaryDifferentialEquations&); 00102 00103 void set_initial_independent_variable(const double&); 00104 void set_final_independent_variable(const double&); 00105 00106 void set_initial_dependent_variables(const Vector<double>&); 00107 void set_initial_dependent_variable(const unsigned int&, const double&); 00108 00109 void set_solution_method(const SolutionMethod&); 00110 void set_solution_method(const std::string&); 00111 00112 void set_points_number(const unsigned int&); 00113 00114 void set_tolerance(const double& ); 00115 00116 void set_initial_size(const unsigned int&); 00117 void set_warning_size(const unsigned int&); 00118 void set_error_size(const unsigned int&); 00119 00120 virtual void set_default(void); 00121 00122 // Ordinary differential equations methods 00123 00125 00126 virtual Vector<double> calculate_dependent_variables_dots(const NeuralNetwork&, const Vector<double>&) const = 0; 00127 00128 // Numerical solution methods 00129 00130 Matrix<double> calculate_Runge_Kutta_solution(const NeuralNetwork&) const; 00131 Vector<double> calculate_Runge_Kutta_final_solution(const NeuralNetwork&) const; 00132 00133 Matrix<double> calculate_Runge_Kutta_Fehlberg_solution(const NeuralNetwork&) const; 00134 Vector<double> calculate_Runge_Kutta_Fehlberg_final_solution(const NeuralNetwork&) const; 00135 00136 virtual Matrix<double> calculate_solutions(const NeuralNetwork&) const; 00137 virtual Vector<double> calculate_final_solutions(const NeuralNetwork&) const; 00138 00139 // Serialization methods 00140 00141 std::string to_string(void) const; 00142 00143 virtual TiXmlElement* to_XML(void) const; 00144 virtual void from_XML(TiXmlElement*); 00145 00146 virtual void save_data(const NeuralNetwork&, const std::string&) const; 00147 00148 protected: 00149 00151 00152 double initial_independent_variable; 00153 00155 00156 double final_independent_variable; 00157 00159 00160 Vector<double> initial_dependent_variables; 00161 00163 00164 SolutionMethod solution_method; 00165 00167 00168 unsigned int points_number; 00169 00171 00172 double tolerance; 00173 00175 00176 unsigned int initial_size; 00177 00179 00180 unsigned int warning_size; 00181 00183 00184 unsigned int error_size; 00185 }; 00186 00187 } 00188 00189 #endif 00190 00191 00192 // OpenNN: Open Neural Networks Library. 00193 // Copyright (C) 2005-2012 Roberto Lopez 00194 // 00195 // This library is free software; you can redistribute it and/or 00196 // modify it under the terms of the GNU Lesser General Public 00197 // License as published by the Free Software Foundation; either 00198 // version 2.1 of the License, or any later version. 00199 // 00200 // This library is distributed in the hope that it will be useful, 00201 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00202 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00203 // Lesser General Public License for more details. 00204 00205 // You should have received a copy of the GNU Lesser General Public 00206 // License along with this library; if not, write to the Free Software 00207 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA