34 #include <boost/bind.hpp> 35 #include <boost/assign/std/vector.hpp> 41 using namespace gtsam;
55 ps +=
Point3(1, 0, 0),
Point3(0, 1, 0),
Point3(0, 0, 1),
Point3(1, 1, 0)
60 expectedH = numericalDerivative11<Point3, Unit3>(
point3_,
s);
72 Rot3 R = Rot3::Yaw(0.5);
81 R.
rotate(p, actualH, boost::none);
86 R.
rotate(p, boost::none, actualH);
103 Matrix actualH, expectedH;
107 R.
unrotate(p, actualH, boost::none);
112 R.
unrotate(p, boost::none, actualH);
129 boost::function<double(const Unit3&, const Unit3&)>
f = boost::bind(&
Unit3::dot, _1, _2,
130 boost::none, boost::none);
159 expected = numericalDerivative11<Vector2,Unit3>(
165 expected = numericalDerivative11<Vector2,Unit3>(
186 expected = numericalDerivative21<Vector2, Unit3, Unit3>(
187 boost::bind(&Unit3::errorVector, _1, _2, boost::none, boost::none),
p,
q);
188 p.errorVector(q, actual, boost::none);
192 expected = numericalDerivative21<Vector2, Unit3, Unit3>(
193 boost::bind(&Unit3::errorVector, _1, _2, boost::none, boost::none),
p, r);
194 p.errorVector(r, actual, boost::none);
198 expected = numericalDerivative22<Vector2, Unit3, Unit3>(
199 boost::bind(&Unit3::errorVector, _1, _2, boost::none, boost::none),
p,
q);
200 p.errorVector(q, boost::none, actual);
204 expected = numericalDerivative22<Vector2, Unit3, Unit3>(
205 boost::bind(&Unit3::errorVector, _1, _2, boost::none, boost::none),
p, r);
206 p.errorVector(r, boost::none, actual);
222 expected = numericalGradient<Unit3>(
223 boost::bind(&Unit3::distance, &
p, _1, boost::none),
q);
224 p.distance(q, actual);
228 expected = numericalGradient<Unit3>(
229 boost::bind(&Unit3::distance, &
p, _1, boost::none), r);
230 p.distance(r, actual);
280 Vector2 actual =
p.localCoordinates(q);
285 Vector2 actual =
p.localCoordinates(q);
291 Unit3 p(0, 1, 0),
q(0 - twist, -1 + twist, 0);
292 Vector2 actual =
p.localCoordinates(q);
297 Unit3 p(0, 1, 0),
q(0 + twist, -1 - twist, 0);
298 Vector2 actual =
p.localCoordinates(q);
309 B_vec << B.col(0), B.col(1);
317 expected << 0.0, -0.994169047, 0.97618706, -0.0233922129, 0.216930458, 0.105264958;
320 Matrix62 expectedH = numericalDerivative11<Vector6, Unit3>(
342 std::mt19937
rng(42);
343 for (
int i = 0;
i < num_tests;
i++) {
344 Unit3 p = Unit3::Random(rng);
349 Matrix62 expectedH = numericalDerivative11<Vector6, Unit3>(
378 boost::function<Unit3(const Vector2&)>
f =
379 boost::bind(&Unit3::retract, p, _1, boost::none);
406 std::mt19937
rng(42);
408 Point3 expectedMean(0,0,0), actualMean(0,0,0);
409 for (
size_t i = 0;
i < 100;
i++)
410 actualMean = actualMean + Unit3::Random(rng).point3();
411 actualMean = actualMean / 100;
418 std::mt19937
rng(42);
419 size_t numIterations = 10000;
421 for (
size_t i = 0;
i < numIterations;
i++) {
423 const Unit3 s1 = Unit3::Random(rng);
424 const Unit3 s2 = Unit3::Random(rng);
441 Matrix expectedH = numericalDerivative11<Unit3, Point3>(
442 boost::bind(Unit3::FromPoint3, _1, boost::none),
point);
448 std::vector<Unit3>
data;
449 data.push_back(
Unit3(1.0, 0.0, 0.0));
450 data.push_back(
Unit3(0.0, 0.0, 1.0));
457 for (
size_t i = 0;
i < data.size();
i++) {
463 for (
size_t i = 0;
i < data.size() - 1;
i++) {
470 for (
size_t i = 0;
i < data.size();
i++) {
477 for (
size_t i = 0;
i < data.size();
i++) {
482 for (
size_t i = 0;
i < data.size() - 1;
i++) {
493 EXPECT(p.error(p).isZero());
507 srand(
time(
nullptr));
GTSAM_EXPORT const Matrix32 & basis(OptionalJacobian< 6, 2 > H=boost::none) const
virtual const Values & optimize()
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Factor Graph consisting of non-linear factors.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
void insert(Key j, const Value &val)
bool equalsObj(const T &input=T())
GTSAM_EXPORT Unit3 retract(const Vector2 &v, OptionalJacobian< 2, 2 > H=boost::none) const
The retract function.
Point3 column(int index) const
Rot2 R(Rot2::fromAngle(0.1))
Point3 unrotate(const Point3 &p, OptionalJacobian< 3, 3 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
rotate point from world to rotated frame
GTSAM_EXPORT Vector2 localCoordinates(const Unit3 &s) const
The local coordinates function.
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
GTSAM_EXPORT Vector3 unitVector(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Vector.
Some functions to compute numerical derivatives.
static Unit3 unrotate_(const Rot3 &R, const Unit3 &p)
internal::FixedSizeMatrix< Y, X1 >::type numericalDerivative21(const boost::function< Y(const X1 &, const X2 &)> &h, const X1 &x1, const X2 &x2, double delta=1e-5)
static Unit3 rotate_(const Rot3 &R, const Unit3 &p)
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange[*:*] noreverse nowriteback set trange[*:*] noreverse nowriteback set urange[*:*] noreverse nowriteback set vrange[*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Point3 rotate(const Point3 &p, OptionalJacobian< 3, 3 > H1=boost::none, OptionalJacobian< 3, 3 > H2=boost::none) const
NonlinearFactorGraph graph
Matrix< SCALARB, Dynamic, Dynamic > B
bool equalsXML(const T &input=T())
bool equalsBinary(const T &input=T())
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
int RealScalar int RealScalar int RealScalar RealScalar * ps
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
Represents a 3D point on a unit sphere.
Scalar EIGEN_BLAS_FUNC() dot(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Point3 point3_(const Unit3 &p)
internal::FixedSizeMatrix< Y, X2 >::type numericalDerivative22(boost::function< Y(const X1 &, const X2 &)> h, const X1 &x1, const X2 &x2, double delta=1e-5)
const ValueType at(Key j) const
P unrotate(const T &r, const P &pt)
void addExpressionFactor(const SharedNoiseModel &R, const T &z, const Expression< T > &h)
GTSAM_EXPORT Vector2 errorVector(const Unit3 &q, OptionalJacobian< 2, 2 > H_p=boost::none, OptionalJacobian< 2, 2 > H_q=boost::none) const
#define EXPECT(condition)
P rotate(const T &r, const P &pt)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static const Point3 point3(0.08, 0.08, 0.0)
EIGEN_DEVICE_FUNC const Scalar & q
GTSAM_EXPORT Point3 point3(OptionalJacobian< 3, 2 > H=boost::none) const
Return unit-norm Point3.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
#define GTSAM_CONCEPT_MANIFOLD_INST(T)
GTSAM_EXPORT double dot(const Unit3 &q, OptionalJacobian< 1, 2 > H1=boost::none, OptionalJacobian< 1, 2 > H2=boost::none) const
Return dot product with q.
Vector6 BasisTest(const Unit3 &p, OptionalJacobian< 6, 2 > H)
internal::FixedSizeMatrix< Y, X >::type numericalDerivative11(boost::function< Y(const X &)> h, const X &x, double delta=1e-5)
New-style numerical derivatives using manifold_traits.
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1
#define GTSAM_CONCEPT_TESTABLE_INST(T)
noiseModel::Base::shared_ptr SharedNoiseModel
3D rotation represented as a rotation matrix or quaternion