16 #include "numerical_differentiation.h"
38 set(other_numerical_differentiation);
62 if(
this != &other_numerical_differentiation)
119 case ForwardDifferences:
121 return(
"ForwardDifferences");
125 case CentralDifferences:
127 return(
"CentralDifferences");
133 std::ostringstream buffer;
135 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
136 <<
"std::string write_numerical_differentiation_method(void) const method.\n"
137 <<
"Unknown numerical differentiation method.\n";
139 throw std::logic_error(buffer.str());
190 numerical_differentiation_method = new_numerical_differentiation_method;
202 if(new_numerical_differentiation_method ==
"ForwardDifferences")
206 else if(new_numerical_differentiation_method ==
"CentralDifferences")
212 std::ostringstream buffer;
214 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
215 <<
"void set_numerical_differentiation_method(const std::string&) method.\n"
216 <<
"Unknown numerical differentiation method: " << new_numerical_differentiation_method <<
".\n";
218 throw std::logic_error(buffer.str());
273 return(sqrt(eta)*(1.0 + fabs(x)));
286 const size_t n = x.size();
290 for(
size_t i = 0; i < n; i++)
292 h[i] = sqrt(eta)*(1.0 + fabs(x[i]));
305 tinyxml2::XMLDocument* document =
new tinyxml2::XMLDocument;
359 const tinyxml2::XMLElement* root_element = document.FirstChildElement(
"NumericalDifferentiation");
363 std::ostringstream buffer;
365 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
366 <<
"void from_XML(const tinyxml2::XMLDocument&) method.\n"
367 <<
"Numerical differentiation element is NULL.\n";
369 throw std::logic_error(buffer.str());
374 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"NumericalDifferentiationMethod");
378 const std::string new_numerical_differentiation_method = element->GetText();
384 catch(
const std::logic_error& e)
386 std::cout << e.what() << std::endl;
393 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"PrecisionDigits");
397 const size_t new_precision_digits = atoi(element->GetText());
403 catch(
const std::logic_error& e)
405 std::cout << e.what() << std::endl;
413 const tinyxml2::XMLElement* element = root_element->FirstChildElement(
"Display");
417 const std::string new_display = element->GetText();
423 catch(
const std::logic_error& e)
425 std::cout << e.what() << std::endl;
size_t precision_digits
Number of precision digits.
bool operator==(const NumericalDifferentiation &) const
void set_precision_digits(const size_t &)
double calculate_h(const double &) const
void set_display(const bool &)
void set_numerical_differentiation_method(const NumericalDifferentiationMethod &)
const bool & get_display(void) const
Returns the flag used by this class for displaying or not displaying warnings.
virtual ~NumericalDifferentiation(void)
Destructor.
NumericalDifferentiationMethod numerical_differentiation_method
Numerical differentiation method variable.
void set(const NumericalDifferentiation &)
const size_t & get_precision_digits(void) const
Returns the number of precision digits required for the derivatives.
std::string write_numerical_differentiation_method(void) const
Returns a string with the name of the method to be used for numerical differentiation.
bool display
Flag for displaying warning messages from this class.
NumericalDifferentiationMethod
Enumeration of available methods for numerical differentiation.
const NumericalDifferentiationMethod & get_numerical_differentiation_method(void) const
Returns the method used for numerical differentiation (forward differences or central differences)...
tinyxml2::XMLDocument * to_XML(void) const
Serializes this numerical differentiation object into a XML document->
void from_XML(const tinyxml2::XMLDocument &)
NumericalDifferentiation(void)
NumericalDifferentiation & operator=(const NumericalDifferentiation &)