32 #include <boost/archive/xml_iarchive.hpp> 33 #include <boost/assign/std/list.hpp> 34 #include <boost/range/adaptor/reversed.hpp> 35 #include <boost/serialization/export.hpp> 36 #include <boost/tuple/tuple.hpp> 42 using namespace gtsam;
63 double total_error = 0.;
65 total_error += factor->error(x);
118 auto Rc1 = Ab1->eliminateSequential(ord);
134 std::tie(A, b) = Ab.
jacobian(ordering);
135 std::tie(A1, b1) = Ab1->jacobian(ordering);
136 std::tie(A2, b2) = Ab2->jacobian(ordering);
138 Matrix Abar(13 * 2, 9 * 2);
139 Abar.topRows(9 * 2) = Matrix::Identity(9 * 2, 9 * 2);
140 Abar.bottomRows(8) = A2.topRows(8) * R1.inverse();
162 const Vector expected_x1 = vec(xbar) + R1.inverse() * vec(y1);
174 const double alpha = 0.5;
176 for (
size_t i = 0;
i < 13;
i++) {
180 Vector ee1(13 * 2), ee2(13 * 2);
181 ee1 << Vector::Ones(9 * 2), Vector::Zero(4 * 2);
182 ee2 << Vector::Zero(9 * 2), Vector::Ones(4 * 2);
187 Vector expected_y = alpha * Abar.transpose() * ee1;
193 expected_y = alpha * Abar.transpose() * ee2;
198 Vector expected_g = Vector::Zero(18);
209 if (!is.is_open())
throw runtime_error(
"Cannot find file " +
inputFile);
210 boost::archive::xml_iarchive in_archive(is);
212 in_archive >> boost::serialization::make_nvp(
"graph", Ab);
222 const auto Ab2 =
read(
"toy3D");
223 const auto Ab3 =
read(
"randomGrid3D");
226 for (
const auto&
Ab : {Ab1, Ab2, Ab3}) {
229 std::map<Key, Vector>
lambda;
230 system.
build(
Ab, keyInfo, lambda);
233 const auto xbar = system.
Rc1()->optimize();
234 auto values_y = VectorValues::Zero(xbar);
235 auto it = values_y.begin();
236 it->second.setConstant(100);
238 it->second.setConstant(-100);
241 auto values_x = system.
Rc1()->backSubstitute(values_y);
246 const auto ord = system.
Rc1()->ordering();
248 auto ord_y = values_y.vector(ord);
249 auto vector_x = R1.inverse() * ord_y;
256 auto vector_y = values_y.vector(
ordering);
257 const size_t N = R1.cols();
258 Vector solve_x = Vector::Zero(N);
259 system.
solve(vector_y, solve_x);
264 auto values_x2 = system.
Rc1()->backSubstituteTranspose(values_y);
265 Vector solveT_x = Vector::Zero(N);
285 Ab1->eliminateSequential();
void build(const GaussianFactorGraph &gfg, const KeyInfo &info, const std::map< Key, Vector > &lambda) override
build/factorize the preconditioner
static int runAllTests(TestResult &result)
static GaussianFactorGraph read(const string &name)
VectorValues x(const VectorValues &y) const
static enum @843 ordering
double error(const VectorValues &y) const
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
#define DOUBLES_EQUAL(expected, actual, threshold)
BOOST_CLASS_EXPORT_GUID(gtsam::JacobianFactor,"JacobianFactor")
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
Iterative methods, implementation.
boost::shared_ptr< const GaussianBayesNet > sharedBayesNet
Some functions to compute numerical derivatives.
V conjugateGradients(const S &Ab, V x, const ConjugateGradientParameters ¶meters, bool steepest)
boost::shared_ptr< This > shared_ptr
const Ordering & ordering() const
Return the ordering.
VectorValues gradient(const VectorValues &y) const
void g(const string &key, int i)
string findExampleDataFile(const string &name)
static double error(const GaussianFactorGraph &fg, const VectorValues &x)
EIGEN_DEVICE_FUNC RotationMatrixType matrix() const
const sharedBayesNet & Rc1() const
#define EXPECT(condition)
VectorValues zero() const
Eigen::Triplet< double > T
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Linear Factor Graph where all factors are Gaussians.
void transposeSolve(const Vector &y, Vector &x) const override
implement x = R^{-T} y
Q R1(Eigen::AngleAxisd(1, Q_z_axis))
TEST(SubgraphPreconditioner, planarOrdering)
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
static ConjugateGradientParameters parameters
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
std::pair< Matrix, Vector > jacobian(const Ordering &ordering) const
Matrix< Scalar, Dynamic, Dynamic > C
#define LONGS_EQUAL(expected, actual)
Ordering planarOrdering(size_t N)
void transposeMultiplyAdd(double alpha, const Errors &e, VectorValues &y) const
std::pair< GaussianFactorGraph, VectorValues > planarGraph(size_t N)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Vector conjugateGradientDescent(const System &Ab, const Vector &x, const ConjugateGradientParameters ¶meters)
std::pair< GaussianFactorGraph::shared_ptr, GaussianFactorGraph::shared_ptr > splitOffPlanarTree(size_t N, const GaussianFactorGraph &original)
Create small example with two poses and one landmark.
boost::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType=boost::none, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex=boost::none) const
Annotation for function names.
void solve(const Vector &y, Vector &x) const override
implement x = R^{-1} y
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
utility functions for loading datasets
static const Eigen::MatrixBase< Vector2 >::ConstantReturnType Z_2x1