14 #ifndef __NUMERICALDIFFERENTIATION_H__
15 #define __NUMERICALDIFFERENTIATION_H__
28 #include "../tinyxml2/tinyxml2.h"
92 tinyxml2::XMLDocument*
to_XML(
void)
const;
93 void from_XML(
const tinyxml2::XMLDocument&);
108 const double y = (t.*f)(x);
112 const double y_forward = (t.*f)(x + h);
114 const double d = (y_forward - y)/h;
132 const double y_forward = (t.*f)(x+h);
134 const double y_backward = (t.*f)(x-h);
136 const double d = (y_forward - y_backward)/(2.0*h);
154 case ForwardDifferences:
160 case CentralDifferences:
168 std::ostringstream buffer;
170 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
171 <<
"double calculate_derivative(const T&, double (T::*f)(const double&) const , const double&) const method.\n"
172 <<
"Unknown numerical differentiation method.\n";
174 throw std::logic_error(buffer.str());
245 case ForwardDifferences:
251 case CentralDifferences:
259 std::ostringstream buffer;
261 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
262 <<
"Vector<double> calculate_derivative(const T&, Vector<double> (T::*f)(const Vector<double>&) const, const Vector<double>&) const method.\n"
263 <<
"Unknown numerical differentiation method.\n";
265 throw std::logic_error(buffer.str());
340 case ForwardDifferences:
346 case CentralDifferences:
354 std::ostringstream buffer;
356 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
357 <<
"Vector<double> calculate_derivative(const T&, Vector<double> (T::*f)(const size_t&, const Vector<double>&) const, const size_t&, const Vector<double>&) const method.\n"
358 <<
"Unknown numerical differentiation method.\n";
360 throw std::logic_error(buffer.str());
382 const double x_forward_2 = x + 2.0*h;
384 const double y_forward_2 = (t.*f)(x_forward_2);
386 const double x_forward = x + h;
388 const double y_forward = (t.*f)(x_forward);
390 const double y = (t.*f)(x);
392 return((y_forward_2 - 2*y_forward + y)/pow(h, 2));
408 const double x_forward_2 = x + 2.0*h;
410 const double y_forward_2 = (t.*f)(x_forward_2);
412 const double x_forward = x + h;
414 const double y_forward = (t.*f)(x_forward);
416 const double y = (t.*f)(x);
418 const double x_backward = x - h;
420 const double y_backward = (t.*f)(x_backward);
422 const double x_backward_2 = x - 2.0*h;
424 const double y_backward_2 = (t.*f)(x_backward_2);
426 const double d2 = (-y_forward_2 + 16.0*y_forward -30.0*y + 16.0*y_backward - y_backward_2)/(12.0*pow(h, 2));
444 case ForwardDifferences:
450 case CentralDifferences:
458 std::ostringstream buffer;
460 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
461 <<
"double calculate_second_derivative(const T& t, double (T::*f)(const double&) const, const double&) const method.\n"
462 <<
"Unknown numerical differentiation method.\n";
464 throw std::logic_error(buffer.str());
491 return((y_forward_2 - y_forward*2.0 + y)/(h*h));
521 return((y_forward_2*-1.0 + y_forward*16.0 + y*-30.0 + y_backward*16.0 + y_backward_2*-1.0)/(h*h*12.0));
537 case ForwardDifferences:
543 case CentralDifferences:
551 std::ostringstream buffer;
553 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
554 <<
"Vector<double> calculate_second_derivative(const T& t, Vector<double> (T::*f)(const Vector<double>&) const, const Vector<double>&) const method.\n"
555 <<
"Unknown numerical differentiation method.\n";
557 throw std::logic_error(buffer.str());
586 return((y_forward_2 - y_forward*2.0 + y)/(h*h));
618 return((y_forward_2*-1.0 + y_forward*16.0 + y*-30.0 + y_backward*16.0 + y_backward_2*-1.0)/(h*h*12.0));
636 case ForwardDifferences:
642 case CentralDifferences:
650 std::ostringstream buffer;
652 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
653 <<
"Vector<double> calculate_second_derivative(const T& t, Vector<double> (T::*f)(const size_t&, const Vector<double>&) const, const size_t&, const Vector<double>&) const method.\n"
654 <<
"Unknown numerical differentiation method.\n";
656 throw std::logic_error(buffer.str());
676 const size_t n = x.size();
680 double y = (t.*f)(x);
688 for(
size_t i = 0; i < n; i++)
693 y_forward = (t.*f)(x_forward);
696 g[i] = (y_forward - y)/h;
714 const size_t n = x.size();
726 for(
size_t i = 0; i < n; i++)
731 y_forward = (t.*f)(x_forward);
735 y_backward = (t.*f)(x_backward);
738 g[i] = (y_forward - y_backward)/(2.0*h);
758 case ForwardDifferences:
764 case CentralDifferences:
772 std::ostringstream buffer;
774 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
775 <<
"Vector<double> calculate_gradient(const T& t, double (T::*f)(const Vector<double>&) const, const Vector<double>&) const method.\n"
776 <<
"Unknown numerical differentiation method.\n";
778 throw std::logic_error(buffer.str());
796 const size_t n = x.size();
800 double y = (t.*f)(x);
808 for(
size_t i = 0; i < n; i++)
813 y_forward = (t.*f)(x_forward);
816 g[i] = (y_forward - y)/h;
834 const size_t n = x.size();
846 for(
size_t i = 0; i < n; i++)
851 y_forward = (t.*f)(x_forward);
855 y_backward = (t.*f)(x_backward);
858 g[i] = (y_forward - y_backward)/(2.0*h);
878 case ForwardDifferences:
884 case CentralDifferences:
892 std::ostringstream buffer;
894 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
895 <<
"Vector<double> calculate_gradient(const T& t, double (T::*f)(const Vector<double>&), const Vector<double>&) const method.\n"
896 <<
"Unknown numerical differentiation method.\n";
898 throw std::logic_error(buffer.str());
918 const size_t n = x.size();
922 const double y = (t.*f)(dummy, x);
930 for(
size_t i = 0; i < n; i++)
935 y_forward = (t.*f)(dummy, x_forward);
938 g[i] = (y_forward - y)/h;
958 const size_t n = x.size();
970 for(
size_t i = 0; i < n; i++)
975 y_forward = (t.*f)(dummy, x_forward);
979 y_backward = (t.*f)(dummy, x_backward);
982 g[i] = (y_forward - y_backward)/(2.0*h);
1004 case ForwardDifferences:
1010 case CentralDifferences:
1018 std::ostringstream buffer;
1020 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1021 <<
"Vector<double> calculate_gradient(const T& t, double (T::*f)(const Vector<double>&, const Vector<double>&) const, const Vector<double>&, const Vector<double>&) const method.\n"
1022 <<
"Unknown numerical differentiation method.\n";
1024 throw std::logic_error(buffer.str());
1044 size_t n = x.size();
1048 double y = (t.*f)(dummy, x);
1056 for(
size_t i = 0; i < n; i++)
1061 y_forward = (t.*f)(dummy, x_forward);
1064 g[i] = (y_forward - y)/h;
1084 size_t n = x.size();
1096 for(
size_t i = 0; i < n; i++)
1101 y_forward = (t.*f)(dummy, x_forward);
1105 y_backward = (t.*f)(dummy, x_backward);
1108 g[i] = (y_forward - y_backward)/(2.0*h);
1130 case ForwardDifferences:
1136 case CentralDifferences:
1144 std::ostringstream buffer;
1146 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1147 <<
"Vector<double> calculate_gradient(const T& t, double (T::*f)(const size_t&, const Vector<double>&) const, const size_t&, const Vector<double>&) const method.\n"
1148 <<
"Unknown numerical differentiation method.\n";
1150 throw std::logic_error(buffer.str());
1171 size_t n = x.size();
1178 double y = (t.*f)(x);
1185 double y_forward_2i;
1186 double y_forward_ij;
1190 for(
size_t i = 0; i < n; i++)
1194 x_forward_i[i] += h_i;
1195 y_forward_i = (t.*f)(x_forward_i);
1196 x_forward_i[i] -= h_i;
1198 x_forward_2i[i] += 2.0*h_i;
1199 y_forward_2i = (t.*f)(x_forward_2i);
1200 x_forward_2i[i] -= 2.0*h_i;
1202 H(i,i) = (y_forward_2i - 2*y_forward_i + y)/pow(h_i, 2);
1204 for(
size_t j = i; j < n; j++)
1208 x_forward_j[j] += h_j;
1209 y_forward_j = (t.*f)(x_forward_j);
1210 x_forward_j[j] -= h_j;
1212 x_forward_ij[i] += h_i;
1213 x_forward_ij[j] += h_j;
1214 y_forward_ij = (t.*f)(x_forward_ij);
1215 x_forward_ij[i] -= h_i;
1216 x_forward_ij[j] -= h_j;
1218 H(i,j) = (y_forward_ij - y_forward_i - y_forward_j + y)/(h_i*h_j);
1222 for(
size_t i = 0; i < n; i++)
1224 for(
size_t j = 0; j < i; j++)
1245 size_t n = x.size();
1247 double y = (t.*f)(x);
1266 double y_backward_2i;
1267 double y_backward_i;
1270 double y_forward_2i;
1272 double y_backward_ij;
1273 double y_forward_ij;
1275 double y_backward_i_forward_j;
1276 double y_forward_i_backward_j;
1278 for(
size_t i = 0; i < n; i++)
1282 x_backward_2i[i] -= 2.0*h_i;
1283 y_backward_2i = (t.*f)(x_backward_2i);
1284 x_backward_2i[i] += 2.0*h_i;
1286 x_backward_i[i] -= h_i;
1287 y_backward_i = (t.*f)(x_backward_i);
1288 x_backward_i[i] += h_i;
1290 x_forward_i[i] += h_i;
1291 y_forward_i = (t.*f)(x_forward_i);
1292 x_forward_i[i] -= h_i;
1294 x_forward_2i[i] += 2.0*h_i;
1295 y_forward_2i = (t.*f)(x_forward_2i);
1296 x_forward_2i[i] -= 2.0*h_i;
1298 H(i,i) = (-y_forward_2i + 16.0*y_forward_i -30.0*y + 16.0*y_backward_i - y_backward_2i)/(12.0*pow(h_i, 2));
1300 for(
size_t j = i; j < n; j++)
1304 x_backward_ij[i] -= h_i;
1305 x_backward_ij[j] -= h_j;
1306 y_backward_ij = (t.*f)(x_backward_ij);
1307 x_backward_ij[i] += h_i;
1308 x_backward_ij[j] += h_j;
1310 x_forward_ij[i] += h_i;
1311 x_forward_ij[j] += h_j;
1312 y_forward_ij = (t.*f)(x_forward_ij);
1313 x_forward_ij[i] -= h_i;
1314 x_forward_ij[j] -= h_j;
1316 x_backward_i_forward_j[i] -= h_i;
1317 x_backward_i_forward_j[j] += h_j;
1318 y_backward_i_forward_j = (t.*f)(x_backward_i_forward_j);
1319 x_backward_i_forward_j[i] += h_i;
1320 x_backward_i_forward_j[j] -= h_j;
1322 x_forward_i_backward_j[i] += h_i;
1323 x_forward_i_backward_j[j] -= h_j;
1324 y_forward_i_backward_j = (t.*f)(x_forward_i_backward_j);
1325 x_forward_i_backward_j[i] -= h_i;
1326 x_forward_i_backward_j[j] += h_j;
1328 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(4.0*h_i*h_j);
1332 for(
size_t i = 0; i < n; i++)
1334 for(
size_t j = 0; j < i; j++)
1357 case ForwardDifferences:
1363 case CentralDifferences:
1371 std::ostringstream buffer;
1373 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1374 <<
"double calculate_Hessian(const T& t, double (T::*f)(const Vector<double>&) const, const Vector<double>&) const method.\n"
1375 <<
"Unknown numerical differentiation method.\n";
1377 throw std::logic_error(buffer.str());
1397 size_t n = x.size();
1404 double y = (t.*f)(dummy, x);
1411 double y_forward_2i;
1412 double y_forward_ij;
1416 for(
size_t i = 0; i < n; i++)
1420 x_forward_i[i] += h_i;
1421 y_forward_i = (t.*f)(dummy, x_forward_i);
1422 x_forward_i[i] -= h_i;
1424 x_forward_2i[i] += 2.0*h_i;
1425 y_forward_2i = (t.*f)(dummy, x_forward_2i);
1426 x_forward_2i[i] -= 2.0*h_i;
1428 H(i,i) = (y_forward_2i - 2*y_forward_i + y)/pow(h_i, 2);
1430 for(
size_t j = i; j < n; j++)
1434 x_forward_j[j] += h_j;
1435 y_forward_j = (t.*f)(dummy, x_forward_j);
1436 x_forward_j[j] -= h_j;
1438 x_forward_ij[i] += h_i;
1439 x_forward_ij[j] += h_j;
1440 y_forward_ij = (t.*f)(dummy, x_forward_ij);
1441 x_forward_ij[i] -= h_i;
1442 x_forward_ij[j] -= h_j;
1444 H(i,j) = (y_forward_ij - y_forward_i - y_forward_j + y)/(h_i*h_j);
1448 for(
size_t i = 0; i < n; i++)
1450 for(
size_t j = 0; j < i; j++)
1473 size_t n = x.size();
1475 double y = (t.*f)(dummy, x);
1494 double y_backward_2i;
1495 double y_backward_i;
1498 double y_forward_2i;
1500 double y_backward_ij;
1501 double y_forward_ij;
1503 double y_backward_i_forward_j;
1504 double y_forward_i_backward_j;
1506 for(
size_t i = 0; i < n; i++)
1510 x_backward_2i[i] -= 2.0*h_i;
1511 y_backward_2i = (t.*f)(dummy, x_backward_2i);
1512 x_backward_2i[i] += 2.0*h_i;
1514 x_backward_i[i] -= h_i;
1515 y_backward_i = (t.*f)(dummy, x_backward_i);
1516 x_backward_i[i] += h_i;
1518 x_forward_i[i] += h_i;
1519 y_forward_i = (t.*f)(dummy, x_forward_i);
1520 x_forward_i[i] -= h_i;
1522 x_forward_2i[i] += 2.0*h_i;
1523 y_forward_2i = (t.*f)(dummy, x_forward_2i);
1524 x_forward_2i[i] -= 2.0*h_i;
1526 H(i,i) = (-y_forward_2i + 16.0*y_forward_i -30.0*y + 16.0*y_backward_i - y_backward_2i)/(12.0*pow(h_i, 2));
1528 for(
size_t j = i; j < n; j++)
1532 x_backward_ij[i] -= h_i;
1533 x_backward_ij[j] -= h_j;
1534 y_backward_ij = (t.*f)(dummy, x_backward_ij);
1535 x_backward_ij[i] += h_i;
1536 x_backward_ij[j] += h_j;
1538 x_forward_ij[i] += h_i;
1539 x_forward_ij[j] += h_j;
1540 y_forward_ij = (t.*f)(dummy, x_forward_ij);
1541 x_forward_ij[i] -= h_i;
1542 x_forward_ij[j] -= h_j;
1544 x_backward_i_forward_j[i] -= h_i;
1545 x_backward_i_forward_j[j] += h_j;
1546 y_backward_i_forward_j = (t.*f)(dummy, x_backward_i_forward_j);
1547 x_backward_i_forward_j[i] += h_i;
1548 x_backward_i_forward_j[j] -= h_j;
1550 x_forward_i_backward_j[i] += h_i;
1551 x_forward_i_backward_j[j] -= h_j;
1552 y_forward_i_backward_j = (t.*f)(dummy, x_forward_i_backward_j);
1553 x_forward_i_backward_j[i] -= h_i;
1554 x_forward_i_backward_j[j] += h_j;
1556 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(4.0*h_i*h_j);
1560 for(
size_t i = 0; i < n; i++)
1562 for(
size_t j = 0; j < i; j++)
1587 case ForwardDifferences:
1593 case CentralDifferences:
1601 std::ostringstream buffer;
1603 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1604 <<
"double calculate_Hessian(const T& t, double (T::*f)(const Vector<double>&, const Vector<double>&) const, const Vector<double>&, const Vector<double>&) const method.\n"
1605 <<
"Unknown numerical differentiation method.\n";
1607 throw std::logic_error(buffer.str());
1627 size_t n = x.size();
1634 double y = (t.*f)(dummy, x);
1641 double y_forward_2i;
1642 double y_forward_ij;
1646 for(
size_t i = 0; i < n; i++)
1650 x_forward_i[i] += h_i;
1651 y_forward_i = (t.*f)(dummy, x_forward_i);
1652 x_forward_i[i] -= h_i;
1654 x_forward_2i[i] += 2.0*h_i;
1655 y_forward_2i = (t.*f)(dummy, x_forward_2i);
1656 x_forward_2i[i] -= 2.0*h_i;
1658 H(i,i) = (y_forward_2i - 2*y_forward_i + y)/pow(h_i, 2);
1660 for(
size_t j = i; j < n; j++)
1664 x_forward_j[j] += h_j;
1665 y_forward_j = (t.*f)(dummy, x_forward_j);
1666 x_forward_j[j] -= h_j;
1668 x_forward_ij[i] += h_i;
1669 x_forward_ij[j] += h_j;
1670 y_forward_ij = (t.*f)(dummy, x_forward_ij);
1671 x_forward_ij[i] -= h_i;
1672 x_forward_ij[j] -= h_j;
1674 H(i,j) = (y_forward_ij - y_forward_i - y_forward_j + y)/(h_i*h_j);
1678 for(
size_t i = 0; i < n; i++)
1680 for(
size_t j = 0; j < i; j++)
1703 size_t n = x.size();
1705 double y = (t.*f)(dummy, x);
1724 double y_backward_2i;
1725 double y_backward_i;
1728 double y_forward_2i;
1730 double y_backward_ij;
1731 double y_forward_ij;
1733 double y_backward_i_forward_j;
1734 double y_forward_i_backward_j;
1736 for(
size_t i = 0; i < n; i++)
1740 x_backward_2i[i] -= 2.0*h_i;
1741 y_backward_2i = (t.*f)(dummy, x_backward_2i);
1742 x_backward_2i[i] += 2.0*h_i;
1744 x_backward_i[i] -= h_i;
1745 y_backward_i = (t.*f)(dummy, x_backward_i);
1746 x_backward_i[i] += h_i;
1748 x_forward_i[i] += h_i;
1749 y_forward_i = (t.*f)(dummy, x_forward_i);
1750 x_forward_i[i] -= h_i;
1752 x_forward_2i[i] += 2.0*h_i;
1753 y_forward_2i = (t.*f)(dummy, x_forward_2i);
1754 x_forward_2i[i] -= 2.0*h_i;
1756 H(i,i) = (-y_forward_2i + 16.0*y_forward_i -30.0*y + 16.0*y_backward_i - y_backward_2i)/(12.0*pow(h_i, 2));
1758 for(
size_t j = i; j < n; j++)
1762 x_backward_ij[i] -= h_i;
1763 x_backward_ij[j] -= h_j;
1764 y_backward_ij = (t.*f)(dummy, x_backward_ij);
1765 x_backward_ij[i] += h_i;
1766 x_backward_ij[j] += h_j;
1768 x_forward_ij[i] += h_i;
1769 x_forward_ij[j] += h_j;
1770 y_forward_ij = (t.*f)(dummy, x_forward_ij);
1771 x_forward_ij[i] -= h_i;
1772 x_forward_ij[j] -= h_j;
1774 x_backward_i_forward_j[i] -= h_i;
1775 x_backward_i_forward_j[j] += h_j;
1776 y_backward_i_forward_j = (t.*f)(dummy, x_backward_i_forward_j);
1777 x_backward_i_forward_j[i] += h_i;
1778 x_backward_i_forward_j[j] -= h_j;
1780 x_forward_i_backward_j[i] += h_i;
1781 x_forward_i_backward_j[j] -= h_j;
1782 y_forward_i_backward_j = (t.*f)(dummy, x_forward_i_backward_j);
1783 x_forward_i_backward_j[i] -= h_i;
1784 x_forward_i_backward_j[j] += h_j;
1786 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(4.0*h_i*h_j);
1790 for(
size_t i = 0; i < n; i++)
1792 for(
size_t j = 0; j < i; j++)
1817 case ForwardDifferences:
1823 case CentralDifferences:
1831 std::ostringstream buffer;
1833 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1834 <<
"double calculate_Hessian(const T& t, double (T::*f)(const size_t&, const Vector<double>&) const, const size_t&, const Vector<double>&) const method.\n"
1835 <<
"Unknown numerical differentiation method.\n";
1837 throw std::logic_error(buffer.str());
1861 size_t n = x.size();
1862 size_t m = y.size();
1869 for(
size_t j = 0; j < n; j++)
1874 y_forward = (t.*f)(x_forward);
1877 for(
size_t i = 0; i < m; i++)
1879 J(i,j) = (y_forward[i] - y[i])/h;
1902 size_t n = x.size();
1903 size_t m = y.size();
1913 for(
size_t j = 0; j < n; j++)
1918 y_backward = (t.*f)(x_backward);
1922 y_forward = (t.*f)(x_forward);
1925 for(
size_t i = 0; i < m; i++)
1927 J(i,j) = (y_forward[i] - y_backward[i])/(2.0*h);
1948 case ForwardDifferences:
1954 case CentralDifferences:
1962 std::ostringstream buffer;
1964 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
1965 <<
"Matrix<double> calculate_Jacobian(const T&, Vector<double> (T::*f)(const Vector<double>&) const, const Vector<double>&) const method.\n"
1966 <<
"Unknown numerical differentiation method.\n";
1968 throw std::logic_error(buffer.str());
1991 size_t n = x.size();
1992 size_t m = y.size();
1999 for(
size_t j = 0; j < n; j++)
2004 y_forward = (t.*f)(dummy, x_forward);
2007 for(
size_t i = 0; i < m; i++)
2009 J(i,j) = (y_forward[i] - y[i])/h;
2033 size_t n = x.size();
2034 size_t m = y.size();
2044 for(
size_t j = 0; j < n; j++)
2049 y_backward = (t.*f)(dummy, x_backward);
2053 y_forward = (t.*f)(dummy, x_forward);
2056 for(
size_t i = 0; i < m; i++)
2058 J(i,j) = (y_forward[i] - y_backward[i])/(2.0*h);
2080 case ForwardDifferences:
2086 case CentralDifferences:
2094 std::ostringstream buffer;
2096 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
2097 <<
"Matrix<double> calculate_Jacobian(const T&, Vector<double> (T::*f)(const Vector<double>&, const Vector<double>&) const, const Vector<double>&, const Vector<double>&) const method.\n"
2098 <<
"Unknown numerical differentiation method.\n";
2100 throw std::logic_error(buffer.str());
2125 size_t n = x.size();
2126 size_t m = y.size();
2133 for(
size_t j = 0; j < n; j++)
2138 y_forward = (t.*f)(dummy, x_forward);
2141 for(
size_t i = 0; i < m; i++)
2143 J(i,j) = (y_forward[i] - y[i])/h;
2168 size_t n = x.size();
2169 size_t m = y.size();
2179 for(
size_t j = 0; j < n; j++)
2184 y_backward = (t.*f)(dummy, x_backward);
2188 y_forward = (t.*f)(dummy, x_forward);
2191 for(
size_t i = 0; i < m; i++)
2193 J(i,j) = (y_forward[i] - y_backward[i])/(2.0*h);
2216 case ForwardDifferences:
2222 case CentralDifferences:
2230 std::ostringstream buffer;
2232 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
2233 <<
"Matrix<double> calculate_Jacobian(const T&, Vector<double> (T::*f)(const size_t&, const Vector<double>&) const, const size_t&, const Vector<double>&) const method.\n"
2234 <<
"Unknown numerical differentiation method.\n";
2236 throw std::logic_error(buffer.str());
2262 size_t n = x.size();
2263 size_t m = y.size();
2270 for(
size_t j = 0; j < n; j++)
2275 y_forward = (t.*f)(dummy_int, dummy_vector, x_forward);
2278 for(
size_t i = 0; i < m; i++)
2280 J(i,j) = (y_forward[i] - y[i])/h;
2303 const size_t n = x.size();
2306 const size_t m = y.size();
2318 for(
size_t j = 0; j < n; j++)
2323 y_backward = (t.*f)(dummy_int, dummy_vector, x_backward);
2327 y_forward = (t.*f)(dummy_int, dummy_vector, x_forward);
2330 for(
size_t i = 0; i < m; i++)
2332 J(i,j) = (y_forward[i] - y_backward[i])/(2.0*h);
2357 case ForwardDifferences:
2363 case CentralDifferences:
2371 std::ostringstream buffer;
2373 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
2374 <<
"Matrix<double> calculate_Jacobian\n"
2375 <<
"(const T&, Vector<double> (T::*f)(const size_t&, const Vector<double>&, const Vector<double>&) const, const size_t&, const Vector<double>&, const Vector<double>&) const method.\n"
2376 <<
"Unknown numerical differentiation method.\n";
2378 throw std::logic_error(buffer.str());
2402 const size_t n = x.size();
2403 const size_t m = y.size();
2412 for(
size_t j = 0; j < n; j++)
2417 y_forward = (t.*f)(dummy_int_1, dummy_int_2, x_forward);
2420 for(
size_t i = 0; i < m; i++)
2422 J(i,j) = (y_forward[i] - y[i])/h;
2447 const size_t n = x.size();
2448 const size_t m = y.size();
2460 for(
size_t j = 0; j < n; j++)
2465 y_backward = (t.*f)(dummy_int_1, dummy_int_2, x_backward);
2469 y_forward = (t.*f)(dummy_int_1, dummy_int_2, x_forward);
2472 for(
size_t i = 0; i < m; i++)
2474 J(i,j) = (y_forward[i] - y_backward[i])/(2.0*h);
2499 case ForwardDifferences:
2505 case CentralDifferences:
2513 std::ostringstream buffer;
2515 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
2516 <<
"Matrix<double> calculate_Jacobian\n"
2517 <<
"(const T&, Vector<double> (T::*f)(const size_t&, const size_t&, const Vector<double>&) const, const size_t&, const size_t&, const Vector<double>&) const method.\n"
2518 <<
"Unknown numerical differentiation method.\n";
2520 throw std::logic_error(buffer.str());
2543 size_t s = y.size();
2544 size_t n = x.size();
2563 for(
size_t i = 0; i < s; i++)
2567 for(
size_t j = 0; j < n; j++)
2571 x_forward_j[j] += h_j;
2572 y_forward_j = (t.*f)(x_forward_j);
2573 x_forward_j[j] -= h_j;
2575 x_forward_2j[j] += 2.0*h_j;
2576 y_forward_2j = (t.*f)(x_forward_2j);
2577 x_forward_2j[j] -= 2.0*h_j;
2579 H[i](j,j) = (y_forward_2j[i] - 2.0*y_forward_j[i] + y[i])/pow(h_j, 2);
2581 for(
size_t k = j; k < n; k++)
2585 x_forward_k[k] += h_k;
2586 y_forward_k = (t.*f)(x_forward_k);
2587 x_forward_k[k] -= h_k;
2589 x_forward_jk[j] += h_j;
2590 x_forward_jk[k] += h_k;
2591 y_forward_jk = (t.*f)(x_forward_jk);
2592 x_forward_jk[j] -= h_j;
2593 x_forward_jk[k] -= h_k;
2595 H[i](j,k) = (y_forward_jk[i] - y_forward_j[i] - y_forward_k[i] + y[i])/(h_j*h_k);
2599 for(
size_t j = 0; j < n; j++)
2601 for(
size_t k = 0; k < j; k++)
2603 H[i](j,k) = H[i](k,j);
2625 size_t s = y.size();
2626 size_t n = x.size();
2657 for(
size_t i = 0; i < s; i++)
2661 for(
size_t j = 0; j < n; j++)
2665 x_backward_2j[j] -= 2.0*h_j;
2666 y_backward_2j = (t.*f)(x_backward_2j);
2667 x_backward_2j[j] += 2.0*h_j;
2669 x_backward_j[j] -= h_j;
2670 y_backward_j = (t.*f)(x_backward_j);
2671 x_backward_j[j] += h_j;
2673 x_forward_j[j] += h_j;
2674 y_forward_j = (t.*f)(x_forward_j);
2675 x_forward_j[j] -= h_j;
2677 x_forward_2j[j] += 2.0*h_j;
2678 y_forward_2j = (t.*f)(x_forward_2j);
2679 x_forward_2j[j] -= 2.0*h_j;
2681 H[i](j,j) = (-y_forward_2j[i] + 16.0*y_forward_j[i] -30.0*y[i] + 16.0*y_backward_j[i] - y_backward_2j[i])/(12.0*pow(h_j, 2));
2683 for(
size_t k = j; k < n; k++)
2687 x_backward_jk[j] -= h_j;
2688 x_backward_jk[k] -= h_k;
2689 y_backward_jk = (t.*f)(x_backward_jk);
2690 x_backward_jk[j] += h_j;
2691 x_backward_jk[k] += h_k;
2693 x_forward_jk[j] += h_j;
2694 x_forward_jk[k] += h_k;
2695 y_forward_jk = (t.*f)(x_forward_jk);
2696 x_forward_jk[j] -= h_j;
2697 x_forward_jk[k] -= h_k;
2699 x_backward_j_forward_k[j] -= h_j;
2700 x_backward_j_forward_k[k] += h_k;
2701 y_backward_j_forward_k = (t.*f)(x_backward_j_forward_k);
2702 x_backward_j_forward_k[j] += h_j;
2703 x_backward_j_forward_k[k] -= h_k;
2705 x_forward_j_backward_k[j] += h_j;
2706 x_forward_j_backward_k[k] -= h_k;
2707 y_forward_j_backward_k = (t.*f)(x_forward_j_backward_k);
2708 x_forward_j_backward_k[j] -= h_j;
2709 x_forward_j_backward_k[k] += h_k;
2711 H[i](j,k) = (y_forward_jk[i] - y_forward_j_backward_k[i] - y_backward_j_forward_k[i] + y_backward_jk[i])/(4.0*h_j*h_k);
2715 for(
size_t j = 0; j < n; j++)
2717 for(
size_t k = 0; k < j; k++)
2719 H[i](j,k) = H[i](k,j);
2741 case ForwardDifferences:
2747 case CentralDifferences:
2755 std::ostringstream buffer;
2757 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
2758 <<
"double calculate_Hessian_form(const T& t, Vector<double> (T::*f)(const Vector<double>&), const Vector<double>&) const method.\n"
2759 <<
"Unknown numerical differentiation method.\n";
2761 throw std::logic_error(buffer.str());
2785 size_t s = y.size();
2786 size_t n = x.size();
2805 for(
size_t i = 0; i < s; i++)
2809 for(
size_t j = 0; j < n; j++)
2813 x_forward_j[j] += h_j;
2814 y_forward_j = (t.*f)(dummy_vector, x_forward_j);
2815 x_forward_j[j] -= h_j;
2817 x_forward_2j[j] += 2.0*h_j;
2818 y_forward_2j = (t.*f)(dummy_vector, x_forward_2j);
2819 x_forward_2j[j] -= 2.0*h_j;
2821 H[i](j,j) = (y_forward_2j[i] - 2.0*y_forward_j[i] + y[i])/pow(h_j, 2);
2823 for(
size_t k = j; k < n; k++)
2827 x_forward_k[k] += h_k;
2828 y_forward_k = (t.*f)(dummy_vector, x_forward_k);
2829 x_forward_k[k] -= h_k;
2831 x_forward_jk[j] += h_j;
2832 x_forward_jk[k] += h_k;
2833 y_forward_jk = (t.*f)(dummy_vector, x_forward_jk);
2834 x_forward_jk[j] -= h_j;
2835 x_forward_jk[k] -= h_k;
2837 H[i](j,k) = (y_forward_jk[i] - y_forward_j[i] - y_forward_k[i] + y[i])/(h_j*h_k);
2841 for(
size_t j = 0; j < n; j++)
2843 for(
size_t k = 0; k < j; k++)
2845 H[i](j,k) = H[i](k,j);
2871 size_t s = y.size();
2872 size_t n = x.size();
2903 for(
size_t i = 0; i < s; i++)
2907 for(
size_t j = 0; j < n; j++)
2911 x_backward_2j[j] -= 2.0*h_j;
2912 y_backward_2j = (t.*f)(dummy_vector, x_backward_2j);
2913 x_backward_2j[j] += 2.0*h_j;
2915 x_backward_j[j] -= h_j;
2916 y_backward_j = (t.*f)(dummy_vector, x_backward_j);
2917 x_backward_j[j] += h_j;
2919 x_forward_j[j] += h_j;
2920 y_forward_j = (t.*f)(dummy_vector, x_forward_j);
2921 x_forward_j[j] -= h_j;
2923 x_forward_2j[j] += 2.0*h_j;
2924 y_forward_2j = (t.*f)(dummy_vector, x_forward_2j);
2925 x_forward_2j[j] -= 2.0*h_j;
2927 H[i](j,j) = (-y_forward_2j[i] + 16.0*y_forward_j[i] -30.0*y[i] + 16.0*y_backward_j[i] - y_backward_2j[i])/(12.0*pow(h_j, 2));
2929 for(
size_t k = j; k < n; k++)
2933 x_backward_jk[j] -= h_j;
2934 x_backward_jk[k] -= h_k;
2935 y_backward_jk = (t.*f)(dummy_vector, x_backward_jk);
2936 x_backward_jk[j] += h_j;
2937 x_backward_jk[k] += h_k;
2939 x_forward_jk[j] += h_j;
2940 x_forward_jk[k] += h_k;
2941 y_forward_jk = (t.*f)(dummy_vector, x_forward_jk);
2942 x_forward_jk[j] -= h_j;
2943 x_forward_jk[k] -= h_k;
2945 x_backward_j_forward_k[j] -= h_j;
2946 x_backward_j_forward_k[k] += h_k;
2947 y_backward_j_forward_k = (t.*f)(dummy_vector, x_backward_j_forward_k);
2948 x_backward_j_forward_k[j] += h_j;
2949 x_backward_j_forward_k[k] -= h_k;
2951 x_forward_j_backward_k[j] += h_j;
2952 x_forward_j_backward_k[k] -= h_k;
2953 y_forward_j_backward_k = (t.*f)(dummy_vector, x_forward_j_backward_k);
2954 x_forward_j_backward_k[j] -= h_j;
2955 x_forward_j_backward_k[k] += h_k;
2957 H[i](j,k) = (y_forward_jk[i] - y_forward_j_backward_k[i] - y_backward_j_forward_k[i] + y_backward_jk[i])/(4.0*h_j*h_k);
2961 for(
size_t j = 0; j < n; j++)
2963 for(
size_t k = 0; k < j; k++)
2965 H[i](j,k) = H[i](k,j);
2991 case ForwardDifferences:
2997 case CentralDifferences:
3005 std::ostringstream buffer;
3007 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
3008 <<
"Vector< Matrix<double> > calculate_Hessian_form\n"
3009 <<
"(const T& t, Vector<double> (T::*f)(const Vector<double>&, const Vector<double>&) const, const Vector<double>&, const Vector<double>&) const method.\n"
3010 <<
"Unknown numerical differentiation method.\n";
3012 throw std::logic_error(buffer.str());
3034 size_t s = y.size();
3035 size_t n = x.size();
3054 for(
size_t i = 0; i < s; i++)
3058 for(
size_t j = 0; j < n; j++)
3062 x_forward_j[j] += h_j;
3063 y_forward_j = (t.*f)(dummy, x_forward_j);
3064 x_forward_j[j] -= h_j;
3066 x_forward_2j[j] += 2.0*h_j;
3067 y_forward_2j = (t.*f)(dummy, x_forward_2j);
3068 x_forward_2j[j] -= 2.0*h_j;
3070 H[i](j,j) = (y_forward_2j[i] - 2.0*y_forward_j[i] + y[i])/pow(h_j, 2);
3072 for(
size_t k = j; k < n; k++)
3076 x_forward_k[k] += h_k;
3077 y_forward_k = (t.*f)(dummy, x_forward_k);
3078 x_forward_k[k] -= h_k;
3080 x_forward_jk[j] += h_j;
3081 x_forward_jk[k] += h_k;
3082 y_forward_jk = (t.*f)(dummy, x_forward_jk);
3083 x_forward_jk[j] -= h_j;
3084 x_forward_jk[k] -= h_k;
3086 H[i](j,k) = (y_forward_jk[i] - y_forward_j[i] - y_forward_k[i] + y[i])/(h_j*h_k);
3090 for(
size_t j = 0; j < n; j++)
3092 for(
size_t k = 0; k < j; k++)
3094 H[i](j,k) = H[i](k,j);
3118 size_t s = y.size();
3119 size_t n = x.size();
3150 for(
size_t i = 0; i < s; i++)
3154 for(
size_t j = 0; j < n; j++)
3158 x_backward_2j[j] -= 2.0*h_j;
3159 y_backward_2j = (t.*f)(dummy, x_backward_2j);
3160 x_backward_2j[j] += 2.0*h_j;
3162 x_backward_j[j] -= h_j;
3163 y_backward_j = (t.*f)(dummy, x_backward_j);
3164 x_backward_j[j] += h_j;
3166 x_forward_j[j] += h_j;
3167 y_forward_j = (t.*f)(dummy, x_forward_j);
3168 x_forward_j[j] -= h_j;
3170 x_forward_2j[j] += 2.0*h_j;
3171 y_forward_2j = (t.*f)(dummy, x_forward_2j);
3172 x_forward_2j[j] -= 2.0*h_j;
3174 H[i](j,j) = (-y_forward_2j[i] + 16.0*y_forward_j[i] -30.0*y[i] + 16.0*y_backward_j[i] - y_backward_2j[i])/(12.0*pow(h_j, 2));
3176 for(
size_t k = j; k < n; k++)
3180 x_backward_jk[j] -= h_j;
3181 x_backward_jk[k] -= h_k;
3182 y_backward_jk = (t.*f)(dummy, x_backward_jk);
3183 x_backward_jk[j] += h_j;
3184 x_backward_jk[k] += h_k;
3186 x_forward_jk[j] += h_j;
3187 x_forward_jk[k] += h_k;
3188 y_forward_jk = (t.*f)(dummy, x_forward_jk);
3189 x_forward_jk[j] -= h_j;
3190 x_forward_jk[k] -= h_k;
3192 x_backward_j_forward_k[j] -= h_j;
3193 x_backward_j_forward_k[k] += h_k;
3194 y_backward_j_forward_k = (t.*f)(dummy, x_backward_j_forward_k);
3195 x_backward_j_forward_k[j] += h_j;
3196 x_backward_j_forward_k[k] -= h_k;
3198 x_forward_j_backward_k[j] += h_j;
3199 x_forward_j_backward_k[k] -= h_k;
3200 y_forward_j_backward_k = (t.*f)(dummy, x_forward_j_backward_k);
3201 x_forward_j_backward_k[j] -= h_j;
3202 x_forward_j_backward_k[k] += h_k;
3204 H[i](j,k) = (y_forward_jk[i] - y_forward_j_backward_k[i] - y_backward_j_forward_k[i] + y_backward_jk[i])/(4.0*h_j*h_k);
3208 for(
size_t j = 0; j < n; j++)
3210 for(
size_t k = 0; k < j; k++)
3212 H[i](j,k) = H[i](k,j);
3236 case ForwardDifferences:
3242 case CentralDifferences:
3250 std::ostringstream buffer;
3252 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
3253 <<
"double calculate_Hessian_form(const T& t, Vector<double> (T::*f)(const size_t&, const Vector<double>&), const size_t&, const Vector<double>&) const method.\n"
3254 <<
"Unknown numerical differentiation method.\n";
3256 throw std::logic_error(buffer.str());
3281 size_t s = y.size();
3282 size_t n = x.size();
3301 for(
size_t i = 0; i < s; i++)
3305 for(
size_t j = 0; j < n; j++)
3309 x_forward_j[j] += h_j;
3310 y_forward_j = (t.*f)(dummy_int, dummy_vector, x_forward_j);
3311 x_forward_j[j] -= h_j;
3313 x_forward_2j[j] += 2.0*h_j;
3314 y_forward_2j = (t.*f)(dummy_int, dummy_vector, x_forward_2j);
3315 x_forward_2j[j] -= 2.0*h_j;
3317 H[i](j,j) = (y_forward_2j[i] - 2.0*y_forward_j[i] + y[i])/pow(h_j, 2);
3319 for(
size_t k = j; k < n; k++)
3323 x_forward_k[k] += h_k;
3324 y_forward_k = (t.*f)(dummy_int, dummy_vector, x_forward_k);
3325 x_forward_k[k] -= h_k;
3327 x_forward_jk[j] += h_j;
3328 x_forward_jk[k] += h_k;
3329 y_forward_jk = (t.*f)(dummy_int, dummy_vector, x_forward_jk);
3330 x_forward_jk[j] -= h_j;
3331 x_forward_jk[k] -= h_k;
3333 H[i](j,k) = (y_forward_jk[i] - y_forward_j[i] - y_forward_k[i] + y[i])/(h_j*h_k);
3337 for(
size_t j = 0; j < n; j++)
3339 for(
size_t k = 0; k < j; k++)
3341 H[i](j,k) = H[i](k,j);
3368 size_t s = y.size();
3369 size_t n = x.size();
3400 for(
size_t i = 0; i < s; i++)
3404 for(
size_t j = 0; j < n; j++)
3408 x_backward_2j[j] -= 2.0*h_j;
3409 y_backward_2j = (t.*f)(dummy_int, dummy_vector, x_backward_2j);
3410 x_backward_2j[j] += 2.0*h_j;
3412 x_backward_j[j] -= h_j;
3413 y_backward_j = (t.*f)(dummy_int, dummy_vector, x_backward_j);
3414 x_backward_j[j] += h_j;
3416 x_forward_j[j] += h_j;
3417 y_forward_j = (t.*f)(dummy_int, dummy_vector, x_forward_j);
3418 x_forward_j[j] -= h_j;
3420 x_forward_2j[j] += 2.0*h_j;
3421 y_forward_2j = (t.*f)(dummy_int, dummy_vector, x_forward_2j);
3422 x_forward_2j[j] -= 2.0*h_j;
3424 H[i](j,j) = (-y_forward_2j[i] + 16.0*y_forward_j[i] -30.0*y[i] + 16.0*y_backward_j[i] - y_backward_2j[i])/(12.0*pow(h_j, 2));
3426 for(
size_t k = j; k < n; k++)
3430 x_backward_jk[j] -= h_j;
3431 x_backward_jk[k] -= h_k;
3432 y_backward_jk = (t.*f)(dummy_int, dummy_vector, x_backward_jk);
3433 x_backward_jk[j] += h_j;
3434 x_backward_jk[k] += h_k;
3436 x_forward_jk[j] += h_j;
3437 x_forward_jk[k] += h_k;
3438 y_forward_jk = (t.*f)(dummy_int, dummy_vector, x_forward_jk);
3439 x_forward_jk[j] -= h_j;
3440 x_forward_jk[k] -= h_k;
3442 x_backward_j_forward_k[j] -= h_j;
3443 x_backward_j_forward_k[k] += h_k;
3444 y_backward_j_forward_k = (t.*f)(dummy_int, dummy_vector, x_backward_j_forward_k);
3445 x_backward_j_forward_k[j] += h_j;
3446 x_backward_j_forward_k[k] -= h_k;
3448 x_forward_j_backward_k[j] += h_j;
3449 x_forward_j_backward_k[k] -= h_k;
3450 y_forward_j_backward_k = (t.*f)(dummy_int, dummy_vector, x_forward_j_backward_k);
3451 x_forward_j_backward_k[j] -= h_j;
3452 x_forward_j_backward_k[k] += h_k;
3454 H[i](j,k) = (y_forward_jk[i] - y_forward_j_backward_k[i] - y_backward_j_forward_k[i] + y_backward_jk[i])/(4.0*h_j*h_k);
3458 for(
size_t j = 0; j < n; j++)
3460 for(
size_t k = 0; k < j; k++)
3462 H[i](j,k) = H[i](k,j);
3489 case ForwardDifferences:
3495 case CentralDifferences:
3503 std::ostringstream buffer;
3505 buffer <<
"OpenNN Exception: NumericalDifferentiation class.\n"
3506 <<
"Vector< Matrix<double> > calculate_Hessian_form\n"
3507 <<
"(const T& t, Vector<double> (T::*f)(const size_t&, const Vector<double>&, const Vector<double>&) const, const size_t&, const Vector<double>&, const Vector<double>&) const method.\n"
3508 <<
"Unknown numerical differentiation method.\n";
3510 throw std::logic_error(buffer.str());
Matrix< double > calculate_forward_differences_Hessian(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Matrix< double > calculate_Hessian(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_forward_differences_gradient(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
Matrix< double > calculate_central_differences_Jacobian(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< double > calculate_central_differences_gradient(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
size_t precision_digits
Number of precision digits.
bool operator==(const NumericalDifferentiation &) const
Vector< double > calculate_central_differences_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
void set_precision_digits(const size_t &)
Vector< Matrix< double > > calculate_Hessian_form(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_central_differences_second_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_central_differences_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Matrix< double > calculate_Jacobian(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
double calculate_second_derivative(const T &t, double(T::*f)(const double &) const , const double &x) const
Vector< Matrix< double > > calculate_central_differences_Hessian_form(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
double calculate_h(const double &) const
Vector< double > calculate_gradient(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< Matrix< double > > calculate_forward_differences_Hessian_form(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< Matrix< double > > calculate_forward_differences_Hessian_form(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
double calculate_forward_differences_second_derivative(const T &t, double(T::*f)(const double &) const, const double &x) const
void set_display(const bool &)
Matrix< double > calculate_forward_differences_Jacobian(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< double > calculate_forward_differences_second_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
void set(void)
Sets the size of a vector to zero.
void set_numerical_differentiation_method(const NumericalDifferentiationMethod &)
Matrix< double > calculate_forward_differences_Hessian(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_forward_differences_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Matrix< double > calculate_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_central_differences_second_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
double calculate_forward_differences_derivative(const T &t, double(T::*f)(const double &) const, const double &x) const
Vector< Matrix< double > > calculate_Hessian_form(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_Hessian(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
const bool & get_display(void) const
Returns the flag used by this class for displaying or not displaying warnings.
virtual ~NumericalDifferentiation(void)
Destructor.
Matrix< double > calculate_forward_differences_Hessian(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
NumericalDifferentiationMethod numerical_differentiation_method
Numerical differentiation method variable.
Vector< double > calculate_gradient(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< double > calculate_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_central_differences_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
Vector< double > calculate_gradient(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
Vector< double > calculate_second_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_forward_differences_second_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_forward_differences_gradient(const T &t, double(T::*f)(const Vector< double > &), const Vector< double > &x) const
Matrix< double > calculate_central_differences_Hessian(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
void set(const NumericalDifferentiation &)
Matrix< double > calculate_Hessian(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< double > calculate_central_differences_gradient(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Vector< Matrix< double > > calculate_central_differences_Hessian_form(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_central_differences_Hessian(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
const size_t & get_precision_digits(void) const
Returns the number of precision digits required for the derivatives.
Vector< double > calculate_central_differences_gradient(const T &t, double(T::*f)(const Vector< double > &), const Vector< double > &x) const
Vector< double > calculate_forward_differences_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_central_differences_gradient(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
Vector< double > calculate_gradient(const T &t, double(T::*f)(const Vector< double > &), const Vector< double > &x) const
double calculate_central_differences_derivative(const T &t, double(T::*f)(const double &) const , const double &x) const
double calculate_derivative(const T &t, double(T::*f)(const double &) const , const double &x) const
Matrix< double > calculate_central_differences_Hessian(const T &t, double(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
std::string write_numerical_differentiation_method(void) const
Returns a string with the name of the method to be used for numerical differentiation.
Vector< double > calculate_forward_differences_gradient(const T &t, double(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
Matrix< double > calculate_forward_differences_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
bool display
Flag for displaying warning messages from this class.
Vector< double > calculate_forward_differences_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
NumericalDifferentiationMethod
Enumeration of available methods for numerical differentiation.
Vector< double > calculate_forward_differences_gradient(const T &t, double(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
Vector< double > calculate_second_derivative(const T &t, Vector< double >(T::*f)(const size_t &, const Vector< double > &) const, const size_t &dummy, const Vector< double > &x) const
const NumericalDifferentiationMethod & get_numerical_differentiation_method(void) const
Returns the method used for numerical differentiation (forward differences or central differences)...
Matrix< double > calculate_Jacobian(const T &t, Vector< double >(T::*f)(const Vector< double > &, const Vector< double > &) const, const Vector< double > &dummy, const Vector< double > &x) const
tinyxml2::XMLDocument * to_XML(void) const
Serializes this numerical differentiation object into a XML document->
double calculate_central_differences_second_derivative(const T &t, double(T::*f)(const double &) const , const double &x) const
void from_XML(const tinyxml2::XMLDocument &)
NumericalDifferentiation(void)
Vector< double > calculate_central_differences_derivative(const T &t, Vector< double >(T::*f)(const Vector< double > &) const, const Vector< double > &x) const
NumericalDifferentiation & operator=(const NumericalDifferentiation &)