22 using namespace gtsam;
26 assert(x.size() == 2);
38 Vector actual = numericalGradient<Vector2>(
f,
x);
48 expected << -
sin(
x(0)), 0.0, 0.0, -
cos(
x(1));
50 Matrix actual = numericalHessian<Vector2>(
f,
x);
57 assert(x.size() == 2);
63 TEST(testNumericalDerivative, numericalHessian2) {
83 double x1 = 1,
x2 = 5;
86 Matrix actual11 = numericalHessian211<double, double>(
f3,
x1,
x2);
90 Matrix actual12 = numericalHessian212<double, double>(
f3,
x1,
x2);
94 Matrix actual22 = numericalHessian222<double, double>(
f3,
x1,
x2);
105 double f4(
double x,
double y,
double z) {
106 return sin(x) *
cos(y) * z *
z;
112 double x = 1,
y = 2,
z = 3;
114 Matrix actual11 = numericalHessian311<double, double, double>(
f4,
x,
y,
z);
118 Matrix actual12 = numericalHessian312<double, double, double>(
f4,
x,
y,
z);
122 Matrix actual13 = numericalHessian313<double, double, double>(
f4,
x,
y,
z);
126 Matrix actual22 = numericalHessian322<double, double, double>(
f4,
x,
y,
z);
130 Matrix actual23 = numericalHessian323<double, double, double>(
f4,
x,
y,
z);
134 Matrix actual33 = numericalHessian333<double, double, double>(
f4,
x,
y,
z);
139 Vector6
f6(
const double x1,
const double x2,
const double x3,
const double x4,
140 const double x5,
const double x6) {
147 const double x5,
const double x6) {
155 TEST(testNumericalDerivative, numeriDerivative61) {
156 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
158 Matrix expected61 = (
Matrix(6, 1) <<
cos(x1), 0, 0, 0, 0, 0).finished();
160 double, double, double,
double>(
f6,
x1,
x2,
x3,
x4,
x5, x6);
164 Matrix expected61Dynamic = Matrix::Zero(6, 1);
165 expected61Dynamic(0, 0) =
cos(x1);
175 TEST(testNumericalDerivative, numeriDerivative62) {
176 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
184 Matrix expected62Dynamic = Matrix::Zero(6, 1);
185 expected62Dynamic(1, 0) = -
sin(x2);
187 double, double, double, double, 1>(
f6,
x1,
x2,
x3,
x4,
x5, x6);
194 TEST(testNumericalDerivative, numeriDerivative63) {
195 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
197 Matrix expected63 = (
Matrix(6, 1) << 0, 0, 2 *
x3, 0, 0, 0).finished();
203 Matrix expected63Dynamic = Matrix::Zero(6, 1);
204 expected63Dynamic(2, 0) = 2 *
x3;
205 Matrix61 actual63Dynamic =
214 TEST(testNumericalDerivative, numeriDerivative64) {
215 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
217 Matrix expected64 = (
Matrix(6, 1) << 0, 0, 0, 3 *
x4 *
x4, 0, 0).finished();
223 Matrix expected64Dynamic = Matrix::Zero(6, 1);
224 expected64Dynamic(3, 0) = 3 * x4 *
x4;
225 Matrix61 actual64Dynamic =
234 TEST(testNumericalDerivative, numeriDerivative65) {
235 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
243 Matrix expected65Dynamic = Matrix::Zero(6, 1);
244 expected65Dynamic(4, 0) = 0.5 /
sqrt(x5);
245 Matrix61 actual65Dynamic =
254 TEST(testNumericalDerivative, numeriDerivative66) {
255 double x1 = 1,
x2 = 2,
x3 = 3 ,
x4 = 4,
x5 = 5, x6 = 6;
263 Matrix expected66Dynamic = Matrix::Zero(6, 1);
264 expected66Dynamic(5, 0) =
cos(x6) +
sin(x6);
265 Matrix61 actual66Dynamic =
internal::FixedSizeMatrix< X, X >::type numericalHessian(boost::function< double(const X &)> f, const X &x, double delta=1e-5)
internal::FixedSizeMatrix< Y, X6 >::type numericalDerivative66(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
static int runAllTests(TestResult &result)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative61(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
Vector6 f6(const double x1, const double x2, const double x3, const double x4, const double x5, const double x6)
internal::FixedSizeMatrix< X1, X1 >::type numericalHessian211(boost::function< double(const X1 &, const X2 &)> f, const X1 &x1, const X2 &x2, double delta=1e-5)
Vector g6(const double x1, const double x2, const double x3, const double x4, const double x5, const double x6)
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Some functions to compute numerical derivatives.
Pose3 x2(Rot3::Ypr(0.0, 0.0, 0.0), l2)
TEST(testNumericalDerivative, numericalGradient)
double f2(const Vector2 &x)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative62(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
EIGEN_DEVICE_FUNC const CosReturnType cos() const
double f(const Vector2 &x)
internal::FixedSizeMatrix< Y, X5 >::type numericalDerivative65(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
#define EXPECT(condition)
internal::FixedSizeMatrix< X1, X2 >::type numericalHessian212(boost::function< double(const X1 &, const X2 &)> f, const X1 &x1, const X2 &x2, double delta=1e-5)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Eigen::Matrix< double, N, 1 > numericalGradient(boost::function< double(const X &)> h, const X &x, double delta=1e-5)
Numerically compute gradient of scalar function.
internal::FixedSizeMatrix< Y, X3 >::type numericalDerivative63(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
Pose3 x3(Rot3::Ypr(M_PI/4.0, 0.0, 0.0), l2)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
double f4(double x, double y, double z)
double f3(double x1, double x2)
internal::FixedSizeMatrix< X1, X1 >::type numericalHessian311(boost::function< double(const X1 &, const X2 &, const X3 &)> f, const X1 &x1, const X2 &x2, const X3 &x3, double delta=1e-5)
internal::FixedSizeMatrix< Y, X4 >::type numericalDerivative64(boost::function< Y(const X1 &, const X2 &, const X3 &, const X4 &, const X5 &, const X6 &)> h, const X1 &x1, const X2 &x2, const X3 &x3, const X4 &x4, const X5 &x5, const X6 &x6, double delta=1e-5)
EIGEN_DEVICE_FUNC const SinReturnType sin() const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector