2010-10-14 12:54:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-22 06:23:24 +08:00
|
|
|
/**
|
|
|
|
* @file testNonlinearFactorGraph.cpp
|
|
|
|
* @brief Unit tests for Non-Linear Factor Graph
|
|
|
|
* @brief testNonlinearFactorGraph
|
|
|
|
* @author Carlos Nieto
|
|
|
|
* @author Christian Potthast
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*STL/C++*/
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2009-12-09 23:25:50 +08:00
|
|
|
#include <boost/assign/std/list.hpp>
|
|
|
|
using namespace boost::assign;
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/CppUnitLite/TestHarness.h>
|
2009-08-22 06:23:24 +08:00
|
|
|
|
2010-01-18 03:34:57 +08:00
|
|
|
#define GTSAM_MAGIC_KEY
|
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/base/Matrix.h>
|
|
|
|
#include <gtsam/slam/smallExample.h>
|
|
|
|
#include <gtsam/inference/FactorGraph-inl.h>
|
|
|
|
#include <gtsam/nonlinear/NonlinearFactorGraph-inl.h>
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
using namespace gtsam;
|
2010-01-19 13:33:44 +08:00
|
|
|
using namespace example;
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-01-19 13:33:44 +08:00
|
|
|
TEST( Graph, equals )
|
2009-09-09 12:43:04 +08:00
|
|
|
{
|
2010-01-19 13:33:44 +08:00
|
|
|
Graph fg = createNonlinearFactorGraph();
|
|
|
|
Graph fg2 = createNonlinearFactorGraph();
|
2009-09-09 12:43:04 +08:00
|
|
|
CHECK( fg.equals(fg2) );
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2010-01-19 13:33:44 +08:00
|
|
|
TEST( Graph, error )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-01-19 13:33:44 +08:00
|
|
|
Graph fg = createNonlinearFactorGraph();
|
2010-10-09 11:09:58 +08:00
|
|
|
Values c1 = createValues();
|
2009-09-09 12:43:04 +08:00
|
|
|
double actual1 = fg.error(c1);
|
|
|
|
DOUBLES_EQUAL( 0.0, actual1, 1e-9 );
|
2009-08-22 06:23:24 +08:00
|
|
|
|
2010-10-09 11:09:58 +08:00
|
|
|
Values c2 = createNoisyValues();
|
2009-09-09 12:43:04 +08:00
|
|
|
double actual2 = fg.error(c2);
|
|
|
|
DOUBLES_EQUAL( 5.625, actual2, 1e-9 );
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 23:25:50 +08:00
|
|
|
/* ************************************************************************* */
|
2010-01-19 13:33:44 +08:00
|
|
|
TEST( Graph, GET_ORDERING)
|
2009-12-09 23:25:50 +08:00
|
|
|
{
|
2010-10-09 06:04:47 +08:00
|
|
|
Ordering expected; expected += "x1","l1","x2";
|
2010-01-19 13:33:44 +08:00
|
|
|
Graph nlfg = createNonlinearFactorGraph();
|
2010-10-15 23:53:36 +08:00
|
|
|
Ordering actual = *nlfg.orderingCOLAMD(createNoisyValues());
|
2009-12-09 23:25:50 +08:00
|
|
|
CHECK(assert_equal(expected,actual));
|
|
|
|
}
|
|
|
|
|
2009-08-22 06:23:24 +08:00
|
|
|
/* ************************************************************************* */
|
2010-01-19 13:33:44 +08:00
|
|
|
TEST( Graph, probPrime )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-01-19 13:33:44 +08:00
|
|
|
Graph fg = createNonlinearFactorGraph();
|
2010-10-09 11:09:58 +08:00
|
|
|
Values cfg = createValues();
|
2009-08-22 06:23:24 +08:00
|
|
|
|
2009-09-09 12:43:04 +08:00
|
|
|
// evaluate the probability of the factor graph
|
|
|
|
double actual = fg.probPrime(cfg);
|
|
|
|
double expected = 1.0;
|
|
|
|
DOUBLES_EQUAL(expected,actual,0);
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
2010-01-27 12:39:35 +08:00
|
|
|
/* ************************************************************************* */
|
2010-01-19 13:33:44 +08:00
|
|
|
TEST( Graph, linearize )
|
2009-08-22 06:23:24 +08:00
|
|
|
{
|
2010-01-19 13:33:44 +08:00
|
|
|
Graph fg = createNonlinearFactorGraph();
|
2010-10-09 11:09:58 +08:00
|
|
|
Values initial = createNoisyValues();
|
2010-10-09 06:04:47 +08:00
|
|
|
boost::shared_ptr<GaussianFactorGraph> linearized = fg.linearize(initial, *initial.orderingArbitrary());
|
|
|
|
GaussianFactorGraph expected = createGaussianFactorGraph(*initial.orderingArbitrary());
|
2010-02-22 05:17:47 +08:00
|
|
|
CHECK(assert_equal(expected,*linearized)); // Needs correct linearizations
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ************************************************************************* */
|
2009-09-09 12:43:04 +08:00
|
|
|
int main() {
|
|
|
|
TestResult tr;
|
|
|
|
return TestRegistry::runAllTests(tr);
|
2009-08-22 06:23:24 +08:00
|
|
|
}
|
|
|
|
/* ************************************************************************* */
|