Added tests for matrix/vector conversion
parent
42284355f4
commit
1c2646000b
|
|
@ -21,6 +21,8 @@
|
||||||
#include <gtsam/base/Testable.h>
|
#include <gtsam/base/Testable.h>
|
||||||
#include <gtsam/base/numericalDerivative.h>
|
#include <gtsam/base/numericalDerivative.h>
|
||||||
|
|
||||||
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
#include <boost/tuple/tuple.hpp>
|
||||||
#include <boost/assign/list_of.hpp>
|
#include <boost/assign/list_of.hpp>
|
||||||
#include <boost/assign/std/list.hpp> // for operator +=
|
#include <boost/assign/std/list.hpp> // for operator +=
|
||||||
using namespace boost::assign;
|
using namespace boost::assign;
|
||||||
|
|
@ -28,13 +30,11 @@ using namespace boost::assign;
|
||||||
// STL/C++
|
// STL/C++
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <CppUnitLite/TestHarness.h>
|
|
||||||
#include <boost/tuple/tuple.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gtsam;
|
using namespace gtsam;
|
||||||
|
|
||||||
static const Key _x_=0, _y_=1;
|
static const Key _x_ = 11, _y_ = 22, _z_ = 33;
|
||||||
|
|
||||||
static GaussianBayesNet smallBayesNet =
|
static GaussianBayesNet smallBayesNet =
|
||||||
list_of(GaussianConditional(_x_, Vector1::Constant(9), I_1x1, _y_, I_1x1))(
|
list_of(GaussianConditional(_x_, Vector1::Constant(9), I_1x1, _y_, I_1x1))(
|
||||||
|
|
@ -42,9 +42,9 @@ static GaussianBayesNet smallBayesNet =
|
||||||
|
|
||||||
static GaussianBayesNet noisyBayesNet =
|
static GaussianBayesNet noisyBayesNet =
|
||||||
list_of(GaussianConditional(_x_, Vector1::Constant(9), I_1x1, _y_, I_1x1,
|
list_of(GaussianConditional(_x_, Vector1::Constant(9), I_1x1, _y_, I_1x1,
|
||||||
noiseModel::Diagonal::Sigmas(Vector1::Constant(2))))(
|
noiseModel::Isotropic::Sigma(1, 2.0)))(
|
||||||
GaussianConditional(_y_, Vector1::Constant(5), I_1x1,
|
GaussianConditional(_y_, Vector1::Constant(5), I_1x1,
|
||||||
noiseModel::Diagonal::Sigmas(Vector1::Constant(3))));
|
noiseModel::Isotropic::Sigma(1, 3.0)));
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( GaussianBayesNet, Matrix )
|
TEST( GaussianBayesNet, Matrix )
|
||||||
|
|
@ -140,11 +140,33 @@ TEST( GaussianBayesNet, optimize3 )
|
||||||
TEST(GaussianBayesNet, ordering)
|
TEST(GaussianBayesNet, ordering)
|
||||||
{
|
{
|
||||||
Ordering expected;
|
Ordering expected;
|
||||||
expected += 0, 1;
|
expected += _x_, _y_;
|
||||||
const auto actual = noisyBayesNet.ordering();
|
const auto actual = noisyBayesNet.ordering();
|
||||||
EXPECT(assert_equal(expected, actual));
|
EXPECT(assert_equal(expected, actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
TEST( GaussianBayesNet, MatrixStress )
|
||||||
|
{
|
||||||
|
GaussianBayesNet bn;
|
||||||
|
using GC = GaussianConditional;
|
||||||
|
bn.emplace_shared<GC>(_x_, Vector2(1, 2), 1 * I_2x2, _y_, 2 * I_2x2, _z_, 3 * I_2x2);
|
||||||
|
bn.emplace_shared<GC>(_y_, Vector2(3, 4), 4 * I_2x2, _z_, 5 * I_2x2);
|
||||||
|
bn.emplace_shared<GC>(_z_, Vector2(5, 6), 6 * I_2x2);
|
||||||
|
|
||||||
|
const VectorValues expected = bn.optimize();
|
||||||
|
for (const auto keys :
|
||||||
|
{KeyVector({_x_, _y_, _z_}), KeyVector({_x_, _z_, _y_}),
|
||||||
|
KeyVector({_y_, _x_, _z_}), KeyVector({_y_, _z_, _x_}),
|
||||||
|
KeyVector({_z_, _x_, _y_}), KeyVector({_z_, _y_, _x_})}) {
|
||||||
|
const Ordering ordering(keys);
|
||||||
|
Matrix R;
|
||||||
|
Vector d;
|
||||||
|
boost::tie(R, d) = bn.matrix(ordering);
|
||||||
|
EXPECT(assert_equal(expected.vector(ordering), R.inverse() * d));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TEST( GaussianBayesNet, backSubstituteTranspose )
|
TEST( GaussianBayesNet, backSubstituteTranspose )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue