9#ifndef NUMERICALDIFFERENTIATION_H
10#define NUMERICALDIFFERENTIATION_H
60 type calculate_eta()
const;
63 Tensor<type, 1>
calculate_h(
const Tensor<type, 1>&)
const;
64 Tensor<type, 2>
calculate_h(
const Tensor<type, 2>&)
const;
65 Tensor<type, 4>
calculate_h(
const Tensor<type, 4>&)
const;
68 type calculate_derivatives(
const T& t, type(T::*f)(
const type&)
const ,
const type& x)
const
72 const type y_forward = (t.*f)(x+h);
74 const type y_backward = (t.*f)(x-h);
76 const type d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
88 Tensor<type, 1>
calculate_derivatives(
const T& t, Tensor<type, 1>(T::*f)(
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& x)
const
93 const Tensor<type, 1> x_forward = x + h;
94 const Tensor<type, 1> x_backward = x - h;
96 const Tensor<type, 1> y_forward = (t.*f)(x_forward);
97 const Tensor<type, 1> y_backward = (t.*f)(x_backward);
99 const Tensor<type, 1> y = (t.*f)(x);
101 const Tensor<type, 1> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
108 Tensor<type, 2> calculate_derivatives(
const T& t, Tensor<type, 2>(T::*f)(
const Tensor<type, 2>&)
const,
const Tensor<type, 2>& x)
const
112 const Tensor<type, 2> x_forward = x + h;
113 const Tensor<type, 2> x_backward = x - h;
115 const Tensor<type, 2> y_forward = (t.*f)(x_forward);
116 const Tensor<type, 2> y_backward = (t.*f)(x_backward);
118 const Tensor<type, 2> y = (t.*f)(x);
120 const Tensor<type, 2> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
127 Tensor<type, 4> calculate_derivatives(
const T& t, Tensor<type, 4>(T::*f)(
const Tensor<type, 4>&)
const,
const Tensor<type, 4>& x)
const
131 const Tensor<type, 4> x_forward = x + h;
132 const Tensor<type, 4> x_backward = x - h;
134 const Tensor<type, 4> y_forward = (t.*f)(x_forward);
135 const Tensor<type, 4> y_backward = (t.*f)(x_backward);
137 const Tensor<type, 4> y = (t.*f)(x);
139 const Tensor<type, 4> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
153 Tensor<type, 1>
calculate_derivatives(
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy,
const Tensor<type, 1>& x)
const
157 const Tensor<type, 1> x_forward = x + h;
158 const Tensor<type, 1> x_backward = x - h;
160 const Tensor<type, 1> y_forward = (t.*f)(dummy, x_forward);
161 const Tensor<type, 1> y_backward = (t.*f)(dummy, x_backward);
163 const Tensor<type, 1> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
170 Tensor<type, 2> calculate_derivatives(
const T& t,
void(T::*f)(
const Tensor<type, 2>&, Tensor<type, 2>&)
const,
const Index& dummy,
const Tensor<type, 2>& x)
const
172 const Index rn = x.dimension(0);
173 const Index cn = x.dimension(1);
177 const Tensor<type, 2> x_forward = x + h;
178 const Tensor<type, 2> x_backward = x - h;
180 Tensor<type, 2> y_forward(rn,cn);
181 (t.*f)(x_forward, y_forward);
182 Tensor<type, 2> y_backward(rn,cn);
183 (t.*f)(x_backward, y_backward);
185 const Tensor<type, 2> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
192 Tensor<type, 4> calculate_derivatives(
const T& t,
void(T::*f)(
const Tensor<type, 4>&, Tensor<type, 4>&)
const,
const Index& dummy,
const Tensor<type, 4>& x)
const
194 const Index rn = x.dimension(0);
195 const Index cn = x.dimension(1);
196 const Index kn = x.dimension(2);
197 const Index in = x.dimension(3);
201 const Tensor<type, 4> x_forward = x + h;
202 const Tensor<type, 4> x_backward = x - h;
204 Tensor<type, 4> y_forward(rn,cn, kn, in);
205 (t.*f)(x_forward, y_forward);
206 Tensor<type, 4> y_backward(rn,cn, kn, in);
207 (t.*f)(x_backward, y_backward);
209 const Tensor<type, 4> d = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
225 const type x_forward_2 = x +
static_cast<type
>(2.0)*h;
227 const type y_forward_2 = (t.*f)(x_forward_2);
229 const type x_forward = x + h;
231 const type y_forward = (t.*f)(x_forward);
233 const type y = (t.*f)(x);
235 const type x_backward = x - h;
237 const type y_backward = (t.*f)(x_backward);
239 const type x_backward_2 = x -
static_cast<type
>(2.0)*h;
241 const type y_backward_2 = (t.*f)(x_backward_2);
243 const type d2 = (-y_forward_2 + type(16.0)*y_forward - type(30.0)*y + type(16.0)*y_backward - y_backward_2)/(type(12.0)*
pow(h, type(2)));
259 const Tensor<type, 1> x_forward = x + h;
260 const Tensor<type, 1> x_forward_2 = x + h*
static_cast<type
>(2.0);
262 const Tensor<type, 1> x_backward = x - h;
263 const Tensor<type, 1> x_backward_2 = x - h*
static_cast<type
>(2.0);
265 const Tensor<type, 1> y = (t.*f)(x);
267 const Tensor<type, 1> y_forward = (t.*f)(x_forward);
268 const Tensor<type, 1> y_forward_2 = (t.*f)(x_forward_2);
270 const Tensor<type, 1> y_backward = (t.*f)(x_backward);
271 const Tensor<type, 1> y_backward_2 = (t.*f)(x_backward_2);
273 return ((y_forward_2*type(-1) + y_forward*type(16) + y*type(-30) + y_backward*type(16) + y_backward_2*type(-1))/(h*h*type(12)));
286 Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
287 const Index& dummy,
const Tensor<type, 1>& x)
const
291 const Tensor<type, 1> x_forward = x + h;
292 const Tensor<type, 1> x_forward_2 = x + h*
static_cast<type
>(2.0);
294 const Tensor<type, 1> x_backward = x - h;
295 const Tensor<type, 1> x_backward_2 = x - h*
static_cast<type
>(2.0);
297 const Tensor<type, 1> y = (t.*f)(dummy, x);
299 const Tensor<type, 1> y_forward = (t.*f)(dummy, x_forward);
300 const Tensor<type, 1> y_forward_2 = (t.*f)(dummy, x_forward_2);
302 const Tensor<type, 1> y_backward = (t.*f)(dummy, x_backward);
303 const Tensor<type, 1> y_backward_2 = (t.*f)(dummy, x_backward_2);
305 return (y_forward_2*type(-1) + y_forward*type(16) + y*type(-30) + y_backward*type(16) + y_backward_2*type(-1))/(h*h*type(12));
316 Tensor<type, 1>
calculate_gradient(
const T& t, type (T::*f)(
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& x)
const
319 const Index n = x.size();
323 Tensor<type, 1> x_forward(x);
324 Tensor<type, 1> x_backward(x);
329 Tensor<type, 1> g(n);
331 for(Index i = 0; i < n; i++)
337 y_forward = (t.*f)(x_forward);
342 y_backward = (t.*f)(x_backward);
345 g(i) = (y_forward - y_backward)/(type(2.0)*h);
359 Tensor<type, 1>
calculate_gradient(
const T& t, type(T::*f)(
const Tensor<type, 1>&),
const Tensor<type, 1>& x)
const
361 const Index n = x.size();
365 Tensor<type, 1> x_forward(x);
366 Tensor<type, 1> x_backward(x);
371 Tensor<type, 1> g(n);
373 for(Index i = 0; i < n; i++)
378 y_forward = (t.*f)(x_forward);
382 y_backward = (t.*f)(x_backward);
385 g(i) = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
400 Tensor<type, 1>
calculate_gradient(
const T& t, type(T::*f)(
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& dummy,
const Tensor<type, 1>& x)
const
402 const Index n = x.size();
406 Tensor<type, 1> x_forward(x);
407 Tensor<type, 1> x_backward(x);
412 Tensor<type, 1> g(n);
414 for(Index i = 0; i < n; i++)
419 y_forward = (t.*f)(dummy, x_forward);
423 y_backward = (t.*f)(dummy, x_backward);
426 g(i) = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
441 Tensor<type, 1>
calculate_gradient(
const T& t, type(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy,
const Tensor<type, 1>& x)
const
443 const Index n = x.size();
447 Tensor<type, 1> x_forward(x);
448 Tensor<type, 1> x_backward(x);
453 Tensor<type, 1> g(n);
455 for(Index i = 0; i < n; i++)
460 y_forward = (t.*f)(dummy, x_forward);
464 y_backward = (t.*f)(dummy, x_backward);
467 g(i) = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
483 Tensor<type, 1>
calculate_gradient(
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 2>&)
const,
const Index& dummy,
const Tensor<type, 2>& x)
const
485 const Index n = x.size();
489 Tensor<type, 1> x_forward(x);
490 Tensor<type, 1> x_backward(x);
495 Tensor<type, 1> g(n);
497 for(Index i = 0; i < n; i++)
502 y_forward = (t.*f)(dummy, x_forward);
506 y_backward = (t.*f)(dummy, x_backward);
509 g(i) = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
525 Tensor<type, 1>
calculate_gradient(
const T& t, type(T::*f)(
const Tensor<Index, 1>&,
const Tensor<type, 1>&)
const,
const Tensor<Index, 1>& dummy,
const Tensor<type, 1>& x)
const
527 const Index n = x.size();
530 Tensor<type, 1> x_forward(x);
531 Tensor<type, 1> x_backward(x);
536 Tensor<type, 1> g(n);
538 for(Index i = 0; i < n; i++)
543 y_forward = (t.*f)(dummy, x_forward);
547 y_backward = (t.*f)(dummy, x_backward);
550 g(i) = (y_forward - y_backward)/(h*type(2));
558 Tensor<type, 2> calculate_gradient_matrix(
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 2>&)
const,
const Index& integer,
const Tensor<type, 2>& x)
const
560 const Index rows_number = x.dimension(0);
561 const Index columns_number = x.dimension(1);
563 Tensor<type, 2> gradient(rows_number, columns_number);
566 Tensor<type, 2> x_forward(x);
567 Tensor<type, 2> x_backward(x);
572 for(Index i = 0; i < rows_number; i++)
574 for(Index j = 0; j < columns_number; j++)
579 y_forward = (t.*f)(integer, x_forward)(i);
582 x_backward(i,j) -= h;
583 y_backward = (t.*f)(integer, x_backward)(i);
584 x_backward(i,j) += h;
586 gradient(i,j) = (y_forward - y_backward)/(
static_cast<type
>(2.0)*h);
601 Tensor<type, 2>
calculate_hessian(
const T& t, type(T::*f)(
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& x)
const
603 const Index n = x.size();
607 Tensor<type, 2> H(n, n);
612 Tensor<type, 1> x_backward_2i(x);
613 Tensor<type, 1> x_backward_i(x);
615 Tensor<type, 1> x_forward_i(x);
616 Tensor<type, 1> x_forward_2i(x);
618 Tensor<type, 1> x_backward_ij(x);
619 Tensor<type, 1> x_forward_ij(x);
621 Tensor<type, 1> x_backward_i_forward_j(x);
622 Tensor<type, 1> x_forward_i_backward_j(x);
633 type y_backward_i_forward_j;
634 type y_forward_i_backward_j;
636 for(Index i = 0; i < n; i++)
640 x_backward_2i(i) -=
static_cast<type
>(2.0)*h_i;
641 y_backward_2i = (t.*f)(x_backward_2i);
642 x_backward_2i(i) +=
static_cast<type
>(2.0)*h_i;
644 x_backward_i(i) -= h_i;
645 y_backward_i = (t.*f)(x_backward_i);
646 x_backward_i(i) += h_i;
648 x_forward_i(i) += h_i;
649 y_forward_i = (t.*f)(x_forward_i);
650 x_forward_i(i) -= h_i;
652 x_forward_2i(i) +=
static_cast<type
>(2.0)*h_i;
653 y_forward_2i = (t.*f)(x_forward_2i);
654 x_forward_2i(i) -=
static_cast<type
>(2.0)*h_i;
656 H(i,i) = (-y_forward_2i + type(16.0)*y_forward_i - type(30.0)*y + type(16.0)*y_backward_i - y_backward_2i)/(type(12.0)*
pow(h_i, type(2)));
658 for(Index j = i; j < n; j++)
662 x_backward_ij(i) -= h_i;
663 x_backward_ij(j) -= h_j;
664 y_backward_ij = (t.*f)(x_backward_ij);
665 x_backward_ij(i) += h_i;
666 x_backward_ij(j) += h_j;
668 x_forward_ij(i) += h_i;
669 x_forward_ij(j) += h_j;
670 y_forward_ij = (t.*f)(x_forward_ij);
671 x_forward_ij(i) -= h_i;
672 x_forward_ij(j) -= h_j;
674 x_backward_i_forward_j(i) -= h_i;
675 x_backward_i_forward_j(j) += h_j;
676 y_backward_i_forward_j = (t.*f)(x_backward_i_forward_j);
677 x_backward_i_forward_j(i) += h_i;
678 x_backward_i_forward_j(j) -= h_j;
680 x_forward_i_backward_j(i) += h_i;
681 x_forward_i_backward_j(j) -= h_j;
682 y_forward_i_backward_j = (t.*f)(x_forward_i_backward_j);
683 x_forward_i_backward_j(i) -= h_i;
684 x_forward_i_backward_j(j) += h_j;
686 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(type(4.0)*h_i*h_j);
690 for(Index i = 0; i < n; i++)
692 for(Index j = 0; j < i; j++)
711 Tensor<type, 2>
calculate_hessian(
const T& t, type(T::*f)(
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& dummy,
const Tensor<type, 1>& x)
const
713 const Index n = x.size();
715 type y = (t.*f)(dummy, x);
717 Tensor<type, 2> H(n, n);
722 Tensor<type, 1> x_backward_2i(x);
723 Tensor<type, 1> x_backward_i(x);
725 Tensor<type, 1> x_forward_i(x);
726 Tensor<type, 1> x_forward_2i(x);
728 Tensor<type, 1> x_backward_ij(x);
729 Tensor<type, 1> x_forward_ij(x);
731 Tensor<type, 1> x_backward_i_forward_j(x);
732 Tensor<type, 1> x_forward_i_backward_j(x);
743 type y_backward_i_forward_j;
744 type y_forward_i_backward_j;
746 for(Index i = 0; i < n; i++)
750 x_backward_2i(i) -=
static_cast<type
>(2.0)*h_i;
751 y_backward_2i = (t.*f)(dummy, x_backward_2i);
752 x_backward_2i(i) +=
static_cast<type
>(2.0)*h_i;
754 x_backward_i(i) -= h_i;
755 y_backward_i = (t.*f)(dummy, x_backward_i);
756 x_backward_i(i) += h_i;
758 x_forward_i(i) += h_i;
759 y_forward_i = (t.*f)(dummy, x_forward_i);
760 x_forward_i(i) -= h_i;
762 x_forward_2i(i) +=
static_cast<type
>(2.0)*h_i;
763 y_forward_2i = (t.*f)(dummy, x_forward_2i);
764 x_forward_2i(i) -=
static_cast<type
>(2.0)*h_i;
766 H(i,i) = (-y_forward_2i + type(16.0)*y_forward_i - type(30.0)*y + type(16.0)*y_backward_i - y_backward_2i)/(type(12.0)*
pow(h_i, type(2)));
768 for(Index j = i; j < n; j++)
772 x_backward_ij(i) -= h_i;
773 x_backward_ij(j) -= h_j;
774 y_backward_ij = (t.*f)(dummy, x_backward_ij);
775 x_backward_ij(i) += h_i;
776 x_backward_ij(j) += h_j;
778 x_forward_ij(i) += h_i;
779 x_forward_ij(j) += h_j;
780 y_forward_ij = (t.*f)(dummy, x_forward_ij);
781 x_forward_ij(i) -= h_i;
782 x_forward_ij(j) -= h_j;
784 x_backward_i_forward_j(i) -= h_i;
785 x_backward_i_forward_j(j) += h_j;
786 y_backward_i_forward_j = (t.*f)(dummy, x_backward_i_forward_j);
787 x_backward_i_forward_j(i) += h_i;
788 x_backward_i_forward_j(j) -= h_j;
790 x_forward_i_backward_j(i) += h_i;
791 x_forward_i_backward_j(j) -= h_j;
792 y_forward_i_backward_j = (t.*f)(dummy, x_forward_i_backward_j);
793 x_forward_i_backward_j(i) -= h_i;
794 x_forward_i_backward_j(j) += h_j;
796 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(type(4.0)*h_i*h_j);
800 for(Index i = 0; i < n; i++)
802 for(Index j = 0; j < i; j++)
820 Tensor<type, 2>
calculate_hessian(
const T& t, type(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy,
const Tensor<type, 1>& x)
const
822 const Index n = x.size();
824 type y = (t.*f)(dummy, x);
826 Tensor<type, 2> H(n, n);
831 Tensor<type, 1> x_backward_2i(x);
832 Tensor<type, 1> x_backward_i(x);
834 Tensor<type, 1> x_forward_i(x);
835 Tensor<type, 1> x_forward_2i(x);
837 Tensor<type, 1> x_backward_ij(x);
838 Tensor<type, 1> x_forward_ij(x);
840 Tensor<type, 1> x_backward_i_forward_j(x);
841 Tensor<type, 1> x_forward_i_backward_j(x);
852 type y_backward_i_forward_j;
853 type y_forward_i_backward_j;
855 for(Index i = 0; i < n; i++)
859 x_backward_2i(i) -=
static_cast<type
>(2.0)*h_i;
860 y_backward_2i = (t.*f)(dummy, x_backward_2i);
861 x_backward_2i(i) +=
static_cast<type
>(2.0)*h_i;
863 x_backward_i(i) -= h_i;
864 y_backward_i = (t.*f)(dummy, x_backward_i);
865 x_backward_i(i) += h_i;
867 x_forward_i(i) += h_i;
868 y_forward_i = (t.*f)(dummy, x_forward_i);
869 x_forward_i(i) -= h_i;
871 x_forward_2i(i) +=
static_cast<type
>(2.0)*h_i;
872 y_forward_2i = (t.*f)(dummy, x_forward_2i);
873 x_forward_2i(i) -=
static_cast<type
>(2.0)*h_i;
875 H(i,i) = (-y_forward_2i + type(16.0)*y_forward_i - type(30.0)*y + type(16.0)*y_backward_i - y_backward_2i)/(type(12.0)*
pow(h_i, type(2)));
877 for(Index j = i; j < n; j++)
881 x_backward_ij(i) -= h_i;
882 x_backward_ij(j) -= h_j;
883 y_backward_ij = (t.*f)(dummy, x_backward_ij);
884 x_backward_ij(i) += h_i;
885 x_backward_ij(j) += h_j;
887 x_forward_ij(i) += h_i;
888 x_forward_ij(j) += h_j;
889 y_forward_ij = (t.*f)(dummy, x_forward_ij);
890 x_forward_ij(i) -= h_i;
891 x_forward_ij(j) -= h_j;
893 x_backward_i_forward_j(i) -= h_i;
894 x_backward_i_forward_j(j) += h_j;
895 y_backward_i_forward_j = (t.*f)(dummy, x_backward_i_forward_j);
896 x_backward_i_forward_j(i) += h_i;
897 x_backward_i_forward_j(j) -= h_j;
899 x_forward_i_backward_j(i) += h_i;
900 x_forward_i_backward_j(j) -= h_j;
901 y_forward_i_backward_j = (t.*f)(dummy, x_forward_i_backward_j);
902 x_forward_i_backward_j(i) -= h_i;
903 x_forward_i_backward_j(j) += h_j;
905 H(i,j) = (y_forward_ij - y_forward_i_backward_j - y_backward_i_forward_j + y_backward_ij)/(type(4.0)*h_i*h_j);
909 for(Index i = 0; i < n; i++)
911 for(Index j = 0; j < i; j++)
927 Tensor<type, 2>
calculate_Jacobian(
const T& t, Tensor<type, 1>(T::*f)(
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& x)
const
929 Tensor<type, 1> y = (t.*f)(x);
933 const Index n = x.size();
936 Tensor<type, 1> x_forward(x);
937 Tensor<type, 1> x_backward(x);
939 Tensor<type, 1> y_forward(n);
940 Tensor<type, 1> y_backward(n);
942 Tensor<type, 2> J(m,n);
944 for(Index j = 0; j < n; j++)
949 y_backward = (t.*f)(x_backward);
953 y_forward = (t.*f)(x_forward);
956 for(Index i = 0; i < m; i++)
958 J(i,j) = (y_forward(i) - y_backward(i))/(
static_cast<type
>(2.0)*h);
974 Tensor<type, 2>
calculate_Jacobian(
const T& t, Tensor<type, 1>(T::*f)(
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& dummy,
const Tensor<type, 1>& x)
const
976 Tensor<type, 1> y = (t.*f)(dummy, x);
980 const Index n = x.size();
983 Tensor<type, 1> x_forward(x);
984 Tensor<type, 1> x_backward(x);
986 Tensor<type, 1> y_forward(n);
987 Tensor<type, 1> y_backward(n);
989 Tensor<type, 2> J(m,n);
991 for(Index j = 0; j < n; j++)
996 y_backward = (t.*f)(dummy, x_backward);
1000 y_forward = (t.*f)(dummy, x_forward);
1003 for(Index i = 0; i < m; i++)
1005 J(i,j) = (y_forward(i) - y_backward(i))/(
static_cast<type
>(2.0)*h);
1021 Tensor<type, 2>
calculate_Jacobian(
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy,
const Tensor<type, 1>& x)
const
1023 Tensor<type, 1> y = (t.*f)(dummy, x);
1027 const Index n = x.size();
1030 Tensor<type, 1> x_forward(x);
1031 Tensor<type, 1> x_backward(x);
1033 Tensor<type, 1> y_forward(n);
1034 Tensor<type, 1> y_backward(n);
1036 Tensor<type, 2> J(m,n);
1038 for(Index j = 0; j < n; j++)
1043 y_backward = (t.*f)(dummy, x_backward);
1047 y_forward = (t.*f)(dummy, x_forward);
1050 for(Index i = 0; i < m; i++)
1052 J(i,j) = (y_forward(i) - y_backward(i))/(
static_cast<type
>(2.0)*h);
1070 (
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Index& dummy_int,
const Tensor<type, 1>& dummy_vector,
const Tensor<type, 1>& x)
const
1072 const Index n = x.size();
1074 const Tensor<type, 1> y = (t.*f)(dummy_int, dummy_vector, x);
1075 const Index m = y.size();
1079 Tensor<type, 1> x_forward(x);
1080 Tensor<type, 1> x_backward(x);
1082 Tensor<type, 1> y_forward(n);
1083 Tensor<type, 1> y_backward(n);
1085 Tensor<type, 2> J(m,n);
1087 for(Index j = 0; j < n; j++)
1092 y_backward = (t.*f)(dummy_int, dummy_vector, x_backward);
1096 y_forward = (t.*f)(dummy_int, dummy_vector, x_forward);
1099 for(Index i = 0; i < m; i++)
1101 J(i,j) = (y_forward(i) - y_backward(i))/(
static_cast<type
>(2.0)*h);
1119 (
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy_int_1,
const Index& dummy_int_2,
const Tensor<type, 1>& x)
const
1121 const Tensor<type, 1> y = (t.*f)(dummy_int_1, dummy_int_2, x);
1123 const Index n = x.size();
1124 const Index m = y.size();
1128 Tensor<type, 1> x_forward(x);
1129 Tensor<type, 1> x_backward(x);
1131 Tensor<type, 1> y_forward(n);
1132 Tensor<type, 1> y_backward(n);
1134 Tensor<type, 2> J(m,n);
1136 for(Index j = 0; j < n; j++)
1141 y_backward = (t.*f)(dummy_int_1, dummy_int_2, x_backward);
1145 y_forward = (t.*f)(dummy_int_1, dummy_int_2, x_forward);
1148 for(Index i = 0; i < m; i++)
1150 J(i,j) = (y_forward(i) - y_backward(i))/(
static_cast<type
>(2.0)*h);
1164 Tensor<Tensor<type, 2>, 1>
calculate_hessian(
const T& t, Tensor<type, 1>(T::*f)(
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& x)
const
1166 Tensor<type, 1> y = (t.*f)(x);
1169 const Index n = x.size();
1174 Tensor<type, 1> x_backward_2j(x);
1175 Tensor<type, 1> x_backward_j(x);
1177 Tensor<type, 1> x_forward_j(x);
1178 Tensor<type, 1> x_forward_2j(x);
1180 Tensor<type, 1> x_backward_jk(x);
1181 Tensor<type, 1> x_forward_jk(x);
1183 Tensor<type, 1> x_backward_j_forward_k(x);
1184 Tensor<type, 1> x_forward_j_backward_k(x);
1186 Tensor<type, 1> y_backward_2j;
1187 Tensor<type, 1> y_backward_j;
1189 Tensor<type, 1> y_forward_j;
1190 Tensor<type, 1> y_forward_2j;
1192 Tensor<type, 1> y_backward_jk;
1193 Tensor<type, 1> y_forward_jk;
1195 Tensor<type, 1> y_backward_j_forward_k;
1196 Tensor<type, 1> y_forward_j_backward_k;
1198 Tensor<Tensor<type, 2>, 1> H(s);
1200 for(Index i = 0; i < s; i++)
1204 for(Index j = 0; j < n; j++)
1208 x_backward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1209 y_backward_2j = (t.*f)(x_backward_2j);
1210 x_backward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1212 x_backward_j(j) -= h_j;
1213 y_backward_j = (t.*f)(x_backward_j);
1214 x_backward_j(j) += h_j;
1216 x_forward_j(j) += h_j;
1217 y_forward_j = (t.*f)(x_forward_j);
1218 x_forward_j(j) -= h_j;
1220 x_forward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1221 y_forward_2j = (t.*f)(x_forward_2j);
1222 x_forward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1224 H(i)(j,j) = (-y_forward_2j(i) + type(16.0)*y_forward_j(i) - type(30.0)*y(i) + type(16.0)*y_backward_j(i) - y_backward_2j(i))/(type(12.0)*
pow(h_j, type(2)));
1226 for(Index k = j; k < n; k++)
1230 x_backward_jk(j) -= h_j;
1231 x_backward_jk[k] -= h_k;
1232 y_backward_jk = (t.*f)(x_backward_jk);
1233 x_backward_jk(j) += h_j;
1234 x_backward_jk[k] += h_k;
1236 x_forward_jk(j) += h_j;
1237 x_forward_jk[k] += h_k;
1238 y_forward_jk = (t.*f)(x_forward_jk);
1239 x_forward_jk(j) -= h_j;
1240 x_forward_jk[k] -= h_k;
1242 x_backward_j_forward_k(j) -= h_j;
1243 x_backward_j_forward_k[k] += h_k;
1244 y_backward_j_forward_k = (t.*f)(x_backward_j_forward_k);
1245 x_backward_j_forward_k(j) += h_j;
1246 x_backward_j_forward_k[k] -= h_k;
1248 x_forward_j_backward_k(j) += h_j;
1249 x_forward_j_backward_k[k] -= h_k;
1250 y_forward_j_backward_k = (t.*f)(x_forward_j_backward_k);
1251 x_forward_j_backward_k(j) -= h_j;
1252 x_forward_j_backward_k[k] += h_k;
1254 H(i)(j,k) = (y_forward_jk(i) - y_forward_j_backward_k(i) - y_backward_j_forward_k(i) + y_backward_jk(i))/(type(4.0)*h_j*h_k);
1258 for(Index j = 0; j < n; j++)
1260 for(Index k = 0; k < j; k++)
1262 H(i)(j,k) = H(i)(k,j);
1281 (
const T& t, Tensor<type, 1>(T::*f)(
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Tensor<type, 1>& dummy_vector,
const Tensor<type, 1>& x)
const
1283 Tensor<type, 1> y = (t.*f)(dummy_vector, x);
1286 const Index n = x.size();
1291 Tensor<type, 1> x_backward_2j(x);
1292 Tensor<type, 1> x_backward_j(x);
1294 Tensor<type, 1> x_forward_j(x);
1295 Tensor<type, 1> x_forward_2j(x);
1297 Tensor<type, 1> x_backward_jk(x);
1298 Tensor<type, 1> x_forward_jk(x);
1300 Tensor<type, 1> x_backward_j_forward_k(x);
1301 Tensor<type, 1> x_forward_j_backward_k(x);
1303 Tensor<type, 1> y_backward_2j;
1304 Tensor<type, 1> y_backward_j;
1306 Tensor<type, 1> y_forward_j;
1307 Tensor<type, 1> y_forward_2j;
1309 Tensor<type, 1> y_backward_jk;
1310 Tensor<type, 1> y_forward_jk;
1312 Tensor<type, 1> y_backward_j_forward_k;
1313 Tensor<type, 1> y_forward_j_backward_k;
1315 Tensor<Tensor<type, 2>, 1> H(s);
1317 for(Index i = 0; i < s; i++)
1322 for(Index j = 0; j < n; j++)
1326 x_backward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1327 y_backward_2j = (t.*f)(dummy_vector, x_backward_2j);
1328 x_backward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1330 x_backward_j(j) -= h_j;
1331 y_backward_j = (t.*f)(dummy_vector, x_backward_j);
1332 x_backward_j(j) += h_j;
1334 x_forward_j(j) += h_j;
1335 y_forward_j = (t.*f)(dummy_vector, x_forward_j);
1336 x_forward_j(j) -= h_j;
1338 x_forward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1339 y_forward_2j = (t.*f)(dummy_vector, x_forward_2j);
1340 x_forward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1342 H(i)(j,j) = (-y_forward_2j(i) + type(16.0)*y_forward_j(i) - type(30.0)*y(i) + type(16.0)*y_backward_j(i) - y_backward_2j(i))/(type(12.0)*
pow(h_j, type(2)));
1344 for(Index k = j; k < n; k++)
1348 x_backward_jk(j) -= h_j;
1349 x_backward_jk[k] -= h_k;
1350 y_backward_jk = (t.*f)(dummy_vector, x_backward_jk);
1351 x_backward_jk(j) += h_j;
1352 x_backward_jk[k] += h_k;
1354 x_forward_jk(j) += h_j;
1355 x_forward_jk[k] += h_k;
1356 y_forward_jk = (t.*f)(dummy_vector, x_forward_jk);
1357 x_forward_jk(j) -= h_j;
1358 x_forward_jk[k] -= h_k;
1360 x_backward_j_forward_k(j) -= h_j;
1361 x_backward_j_forward_k[k] += h_k;
1362 y_backward_j_forward_k = (t.*f)(dummy_vector, x_backward_j_forward_k);
1363 x_backward_j_forward_k(j) += h_j;
1364 x_backward_j_forward_k[k] -= h_k;
1366 x_forward_j_backward_k(j) += h_j;
1367 x_forward_j_backward_k[k] -= h_k;
1368 y_forward_j_backward_k = (t.*f)(dummy_vector, x_forward_j_backward_k);
1369 x_forward_j_backward_k(j) -= h_j;
1370 x_forward_j_backward_k[k] += h_k;
1372 H(i)(j,k) = (y_forward_jk(i) - y_forward_j_backward_k(i) - y_backward_j_forward_k(i) + y_backward_jk(i))/(type(4.0)*h_j*h_k);
1376 for(Index j = 0; j < n; j++)
1378 for(Index k = 0; k < j; k++)
1380 H(i)(j,k) = H(i)(k,j);
1397 Tensor<Tensor<type, 2>, 1>
calculate_hessian(
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&)
const,
const Index& dummy,
const Tensor<type, 1>& x)
const
1399 Tensor<type, 1> y = (t.*f)(dummy, x);
1402 const Index n = x.size();
1407 Tensor<type, 1> x_backward_2j(x);
1408 Tensor<type, 1> x_backward_j(x);
1410 Tensor<type, 1> x_forward_j(x);
1411 Tensor<type, 1> x_forward_2j(x);
1413 Tensor<type, 1> x_backward_jk(x);
1414 Tensor<type, 1> x_forward_jk(x);
1416 Tensor<type, 1> x_backward_j_forward_k(x);
1417 Tensor<type, 1> x_forward_j_backward_k(x);
1419 Tensor<type, 1> y_backward_2j;
1420 Tensor<type, 1> y_backward_j;
1422 Tensor<type, 1> y_forward_j;
1423 Tensor<type, 1> y_forward_2j;
1425 Tensor<type, 1> y_backward_jk;
1426 Tensor<type, 1> y_forward_jk;
1428 Tensor<type, 1> y_backward_j_forward_k;
1429 Tensor<type, 1> y_forward_j_backward_k;
1431 Tensor<Tensor<type, 2>, 1> H(s);
1433 for(Index i = 0; i < s; i++)
1437 for(Index j = 0; j < n; j++)
1441 x_backward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1442 y_backward_2j = (t.*f)(dummy, x_backward_2j);
1443 x_backward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1445 x_backward_j(j) -= h_j;
1446 y_backward_j = (t.*f)(dummy, x_backward_j);
1447 x_backward_j(j) += h_j;
1449 x_forward_j(j) += h_j;
1450 y_forward_j = (t.*f)(dummy, x_forward_j);
1451 x_forward_j(j) -= h_j;
1453 x_forward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1454 y_forward_2j = (t.*f)(dummy, x_forward_2j);
1455 x_forward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1457 H(i)(j,j) = (-y_forward_2j(i) + type(16.0)*y_forward_j(i) - type(30.0)*y(i) + type(16.0)*y_backward_j(i) - y_backward_2j(i))/(type(12.0)*
pow(h_j, type(2)));
1459 for(Index k = j; k < n; k++)
1463 x_backward_jk(j) -= h_j;
1464 x_backward_jk[k] -= h_k;
1465 y_backward_jk = (t.*f)(dummy, x_backward_jk);
1466 x_backward_jk(j) += h_j;
1467 x_backward_jk[k] += h_k;
1469 x_forward_jk(j) += h_j;
1470 x_forward_jk[k] += h_k;
1471 y_forward_jk = (t.*f)(dummy, x_forward_jk);
1472 x_forward_jk(j) -= h_j;
1473 x_forward_jk[k] -= h_k;
1475 x_backward_j_forward_k(j) -= h_j;
1476 x_backward_j_forward_k[k] += h_k;
1477 y_backward_j_forward_k = (t.*f)(dummy, x_backward_j_forward_k);
1478 x_backward_j_forward_k(j) += h_j;
1479 x_backward_j_forward_k[k] -= h_k;
1481 x_forward_j_backward_k(j) += h_j;
1482 x_forward_j_backward_k[k] -= h_k;
1483 y_forward_j_backward_k = (t.*f)(dummy, x_forward_j_backward_k);
1484 x_forward_j_backward_k(j) -= h_j;
1485 x_forward_j_backward_k[k] += h_k;
1487 H(i)(j,k) = (y_forward_jk(i) - y_forward_j_backward_k(i) - y_backward_j_forward_k(i) + y_backward_jk(i))/(type(4.0)*h_j*h_k);
1491 for(Index j = 0; j < n; j++)
1493 for(Index k = 0; k < j; k++)
1495 H(i)(j,k) = H(i)(k,j);
1514 (
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Index& dummy_int,
const Tensor<type, 1>& dummy_vector,
const Tensor<type, 1>& x)
const
1516 const Tensor<type, 1> y = (t.*f)(dummy_int, dummy_vector, x);
1519 const Index n = x.size();
1524 Tensor<type, 1> x_backward_2j(x);
1525 Tensor<type, 1> x_backward_j(x);
1527 Tensor<type, 1> x_forward_j(x);
1528 Tensor<type, 1> x_forward_2j(x);
1530 Tensor<type, 1> x_backward_jk(x);
1531 Tensor<type, 1> x_forward_jk(x);
1533 Tensor<type, 1> x_backward_j_forward_k(x);
1534 Tensor<type, 1> x_forward_j_backward_k(x);
1536 Tensor<type, 1> y_backward_2j;
1537 Tensor<type, 1> y_backward_j;
1539 Tensor<type, 1> y_forward_j;
1540 Tensor<type, 1> y_forward_2j;
1542 Tensor<type, 1> y_backward_jk;
1543 Tensor<type, 1> y_forward_jk;
1545 Tensor<type, 1> y_backward_j_forward_k;
1546 Tensor<type, 1> y_forward_j_backward_k;
1548 Tensor<Tensor<type, 2>, 1> H(s);
1550 for(Index i = 0; i < s; i++)
1554 for(Index j = 0; j < n; j++)
1558 x_backward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1559 y_backward_2j = (t.*f)(dummy_int, dummy_vector, x_backward_2j);
1560 x_backward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1562 x_backward_j(j) -= h_j;
1563 y_backward_j = (t.*f)(dummy_int, dummy_vector, x_backward_j);
1564 x_backward_j(j) += h_j;
1566 x_forward_j(j) += h_j;
1567 y_forward_j = (t.*f)(dummy_int, dummy_vector, x_forward_j);
1568 x_forward_j(j) -= h_j;
1570 x_forward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1571 y_forward_2j = (t.*f)(dummy_int, dummy_vector, x_forward_2j);
1572 x_forward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1574 H(i)(j,j) = (-y_forward_2j(i) + type(16.0)*y_forward_j(i) - type(30.0)*y(i) + type(16.0)*y_backward_j(i) - y_backward_2j(i))/(type(12.0)*
pow(h_j, type(2)));
1576 for(Index k = j; k < n; k++)
1580 x_backward_jk(j) -= h_j;
1581 x_backward_jk[k] -= h_k;
1582 y_backward_jk = (t.*f)(dummy_int, dummy_vector, x_backward_jk);
1583 x_backward_jk(j) += h_j;
1584 x_backward_jk[k] += h_k;
1586 x_forward_jk(j) += h_j;
1587 x_forward_jk[k] += h_k;
1588 y_forward_jk = (t.*f)(dummy_int, dummy_vector, x_forward_jk);
1589 x_forward_jk(j) -= h_j;
1590 x_forward_jk[k] -= h_k;
1592 x_backward_j_forward_k(j) -= h_j;
1593 x_backward_j_forward_k[k] += h_k;
1594 y_backward_j_forward_k = (t.*f)(dummy_int, dummy_vector, x_backward_j_forward_k);
1595 x_backward_j_forward_k(j) += h_j;
1596 x_backward_j_forward_k[k] -= h_k;
1598 x_forward_j_backward_k(j) += h_j;
1599 x_forward_j_backward_k[k] -= h_k;
1600 y_forward_j_backward_k = (t.*f)(dummy_int, dummy_vector, x_forward_j_backward_k);
1601 x_forward_j_backward_k(j) -= h_j;
1602 x_forward_j_backward_k[k] += h_k;
1604 H(i)(j,k) = (y_forward_jk(i) - y_forward_j_backward_k(i) - y_backward_j_forward_k(i) + y_backward_jk(i))/(type(4.0)*h_j*h_k);
1608 for(Index j = 0; j < n; j++)
1610 for(Index k = 0; k < j; k++)
1612 H(i)(j,k) = H(i)(k,j);
1631 (
const T& t, Tensor<type, 1>(T::*f)(
const Index&,
const Tensor<type, 1>&,
const Tensor<type, 1>&)
const,
const Index& dummy_int,
const Tensor<type, 1>& dummy_vector,
const Tensor<type, 1>& x)
const
1633 const Tensor<type, 1> y = (t.*f)(dummy_int, dummy_vector, x);
1636 const Index n = x.size();
1641 Tensor<type, 1> x_backward_2j(x);
1642 Tensor<type, 1> x_backward_j(x);
1644 Tensor<type, 1> x_forward_j(x);
1645 Tensor<type, 1> x_forward_2j(x);
1647 Tensor<type, 1> x_backward_jk(x);
1648 Tensor<type, 1> x_forward_jk(x);
1650 Tensor<type, 1> x_backward_j_forward_k(x);
1651 Tensor<type, 1> x_forward_j_backward_k(x);
1653 Tensor<type, 1> y_backward_2j;
1654 Tensor<type, 1> y_backward_j;
1656 Tensor<type, 1> y_forward_j;
1657 Tensor<type, 1> y_forward_2j;
1659 Tensor<type, 1> y_backward_jk;
1660 Tensor<type, 1> y_forward_jk;
1662 Tensor<type, 1> y_backward_j_forward_k;
1663 Tensor<type, 1> y_forward_j_backward_k;
1665 Tensor< Tensor<type, 2>, 2> H;
1669 for(Index i = 0; i < s; i++)
1671 for(Index t = 0; t < n; t++)
1675 for(Index j = 0; j < n; j++)
1679 x_backward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1680 y_backward_2j = (t.*f)(dummy_int, dummy_vector, x_backward_2j);
1681 x_backward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1683 x_backward_j(j) -= h_j;
1684 y_backward_j = (t.*f)(dummy_int, dummy_vector, x_backward_j);
1685 x_backward_j(j) += h_j;
1687 x_forward_j(j) += h_j;
1688 y_forward_j = (t.*f)(dummy_int, dummy_vector, x_forward_j);
1689 x_forward_j(j) -= h_j;
1691 x_forward_2j(j) +=
static_cast<type
>(2.0)*h_j;
1692 y_forward_2j = (t.*f)(dummy_int, dummy_vector, x_forward_2j);
1693 x_forward_2j(j) -=
static_cast<type
>(2.0)*h_j;
1695 H(i)(j,j) = (-y_forward_2j(i) + type(16.0)*y_forward_j(i) - type(30.0)*y(i) + type(16.0)*y_backward_j(i) - y_backward_2j(i))/(type(12.0)*
pow(h_j, type(2)));
1697 for(Index k = j; k < s; k++)
1701 x_backward_jk(j) -= h_j;
1702 x_backward_jk[k] -= h_k;
1703 y_backward_jk = (t.*f)(dummy_int, dummy_vector, x_backward_jk);
1704 x_backward_jk(j) += h_j;
1705 x_backward_jk[k] += h_k;
1707 x_forward_jk(j) += h_j;
1708 x_forward_jk[k] += h_k;
1709 y_forward_jk = (t.*f)(dummy_int, dummy_vector, x_forward_jk);
1710 x_forward_jk(j) -= h_j;
1711 x_forward_jk[k] -= h_k;
1713 x_backward_j_forward_k(j) -= h_j;
1714 x_backward_j_forward_k[k] += h_k;
1715 y_backward_j_forward_k = (t.*f)(dummy_int, dummy_vector, x_backward_j_forward_k);
1716 x_backward_j_forward_k(j) += h_j;
1717 x_backward_j_forward_k[k] -= h_k;
1719 x_forward_j_backward_k(j) += h_j;
1720 x_forward_j_backward_k[k] -= h_k;
1721 y_forward_j_backward_k = (t.*f)(dummy_int, dummy_vector, x_forward_j_backward_k);
1722 x_forward_j_backward_k(j) -= h_j;
1723 x_forward_j_backward_k[k] += h_k;
1725 H(i,t)(j,k) = (y_forward_jk(i) - y_forward_j_backward_k(i) - y_backward_j_forward_k(i) + y_backward_jk(i))/(type(4.0)*h_j*h_k);
1729 for(Index j = 0; j < n; j++)
1731 for(Index k = 0; k < j; k++)
1733 H(i,t)(j,k) = H(i)(k,j);
Tensor< type, 1 > calculate_gradient(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 2 > &) const, const Index &dummy, const Tensor< type, 2 > &x) const
Tensor< type, 2 > calculate_hessian(const T &t, type(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
const Index & get_precision_digits() const
Enumeration of available methods for numerical differentiation.
type calculate_h(const type &) const
Tensor< type, 2 > calculate_hessian(const T &t, type(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
Tensor< type, 2 > calculate_Jacobian(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Index &, const Tensor< type, 1 > &) const, const Index &dummy_int_1, const Index &dummy_int_2, const Tensor< type, 1 > &x) const
const bool & get_display() const
Returns the flag used by this class for displaying or not displaying warnings.
type calculate_second_derivatives(const T &t, type(T::*f)(const type &) const, const type &x) const
Tensor< type, 1 > calculate_gradient(const T &t, type(T::*f)(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Tensor< type, 1 > &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_gradient(const T &t, type(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_derivatives(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
Tensor< type, 2 > calculate_Jacobian(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
bool display
Flag for displaying warning messages from this class.
Tensor< type, 1 > calculate_gradient(const T &t, type(T::*f)(const Tensor< type, 1 > &), const Tensor< type, 1 > &x) const
Tensor< Tensor< type, 2 >, 1 > calculate_hessian(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Index &dummy_int, const Tensor< type, 1 > &dummy_vector, const Tensor< type, 1 > &x) const
Tensor< type, 2 > calculate_Jacobian(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_derivatives(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_gradient(const T &t, type(T::*f)(const Tensor< Index, 1 > &, const Tensor< type, 1 > &) const, const Tensor< Index, 1 > &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_second_derivatives(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_second_derivatives(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
Index precision_digits
Number of precision digits.
Tensor< Tensor< type, 2 >, 1 > calculate_hessian(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Tensor< type, 1 > &dummy_vector, const Tensor< type, 1 > &x) const
Tensor< Tensor< type, 2 >, 1 > calculate_hessian(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &) const, const Index &dummy, const Tensor< type, 1 > &x) const
Tensor< Tensor< type, 2 >, 1 > calculate_hessian(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
Tensor< Tensor< type, 2 >, 2 > calculate_hessian_matrices(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Index &dummy_int, const Tensor< type, 1 > &dummy_vector, const Tensor< type, 1 > &x) const
void set_display(const bool &)
virtual ~NumericalDifferentiation()
Destructor.
Tensor< type, 2 > calculate_Jacobian(const T &t, Tensor< type, 1 >(T::*f)(const Index &, const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Index &dummy_int, const Tensor< type, 1 > &dummy_vector, const Tensor< type, 1 > &x) const
Tensor< type, 1 > calculate_gradient(const T &t, type(T::*f)(const Tensor< type, 1 > &) const, const Tensor< type, 1 > &x) const
NumericalDifferentiation()
Tensor< type, 2 > calculate_hessian(const T &t, type(T::*f)(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Tensor< type, 1 > &dummy, const Tensor< type, 1 > &x) const
Tensor< type, 2 > calculate_Jacobian(const T &t, Tensor< type, 1 >(T::*f)(const Tensor< type, 1 > &, const Tensor< type, 1 > &) const, const Tensor< type, 1 > &dummy, const Tensor< type, 1 > &x) const
void set_precision_digits(const Index &)
Extensions to the C++ standard library.