34 using namespace gtsam;
40 std::make_shared<GaussianConditional>(
_x_, Vector1::Constant(9), I_1x1,
_y_, I_1x1),
41 std::make_shared<GaussianConditional>(_y_, Vector1::Constant(5), I_1x1)};
44 std::make_shared<GaussianConditional>(
_x_, Vector1::Constant(9), I_1x1,
_y_, I_1x1,
45 noiseModel::Isotropic::Sigma(1, 2.0)),
46 std::make_shared<GaussianConditional>(_y_, Vector1::Constant(5), I_1x1,
47 noiseModel::Isotropic::Sigma(1, 3.0))};
52 const auto [
R,
d] = smallBayesNet.
matrix();
72 const Matrix invSigma = R.transpose() *
R;
80 smallBayesNet.
at(0)->logNormalizationConstant() +
81 smallBayesNet.
at(1)->logNormalizationConstant(),
83 const double actual = smallBayesNet.
evaluate(mean);
92 const Matrix invSigma = R.transpose() *
R;
94 const double actual = noisyBayesNet.
evaluate(mean);
101 const auto [
R,
d] = noisyBayesNet.
matrix();
116 {
_y_, Vector1::Constant(5)}};
123 const auto [
R,
d] = noisyBayesNet.
matrix();
136 _x_, Vector1::Constant(9), I_1x1,
_y_, I_1x1);
143 {
_y_, Vector1::Constant(5)}};
157 {
_y_, Vector1::Constant(5)} };
171 GaussianConditional::sharedMeanAndStddev(
X(0), A1,
X(1),
b, sigma),
172 GaussianDensity::sharedMeanAndStddev(
X(1),
mean, sigma)};
185 std::mt19937_64
rng(4242);
200 constexpr
size_t N = 1000;
202 for (
size_t i = 0;
i <
N;
i++) {
203 const auto X_i = gbn.
sample();
204 sum +=
pow(X_i[
_y_].
x() - 5.0, 2.0);
214 const auto actual = noisyBayesNet.
ordering();
228 for (
const auto&
keys :
233 const auto [
R,
d] = bn.
matrix(ordering);
245 {
_y_, Vector1::Constant(5)}},
246 expected{{
_x_, Vector1::Constant(2)}, {
_y_, Vector1::Constant(3)}};
253 const Vector expected_vector = R.transpose().inverse() *
x.vector(
ordering);
264 expected{{
_x_, Vector1::Constant(4)}, {
_y_, Vector1::Constant(9)}};
271 const Vector expected_vector = R.transpose().inverse() *
x.vector(
ordering);
281 0,
Vector2(3.0, 4.0), (Matrix2() << 1.0, 3.0, 0.0, 4.0).finished(),
282 1, (Matrix2() << 2.0, 1.0, 2.0, 3.0).finished(), noiseModel::Isotropic::Sigma(2, 2.0));
285 1,
Vector2(5.0, 6.0), (Matrix2() << 1.0, 1.0, 0.0, 3.0).finished(),
286 2, (Matrix2() << 1.0, 0.0, 5.0, 2.0).finished(), noiseModel::Isotropic::Sigma(2, 2.0));
289 3,
Vector2(7.0, 8.0), (Matrix2() << 1.0, 1.0, 0.0, 5.0).finished(), noiseModel::Isotropic::Sigma(2, 2.0));
291 double expectedDeterminant = 60.0 / 64.0;
302 return 0.5 * (Rd.first * values - Rd.second).squaredNorm();
312 0,
Vector2(1.0,2.0), (Matrix2() << 3.0,4.0,0.0,6.0).finished(),
313 3, (Matrix2() << 7.0,8.0,9.0,10.0).finished(),
314 4, (Matrix2() << 11.0,12.0,13.0,14.0).finished());
316 1,
Vector2(15.0,16.0), (Matrix2() << 17.0,18.0,0.0,20.0).finished(),
317 2, (Matrix2() << 21.0,22.0,23.0,24.0).finished(),
318 4, (Matrix2() << 25.0,26.0,27.0,28.0).finished());
320 2,
Vector2(29.0,30.0), (Matrix2() << 31.0,32.0,0.0,34.0).finished(),
321 3, (Matrix2() << 35.0,36.0,37.0,38.0).finished());
323 3,
Vector2(39.0,40.0), (Matrix2() << 41.0,42.0,0.0,44.0).finished(),
324 4, (Matrix2() << 45.0,46.0,47.0,48.0).finished());
326 4,
Vector2(49.0,50.0), (Matrix2() << 51.0,52.0,0.0,54.0).finished());
329 Matrix hessian = numericalHessian<Vector10>(
330 std::bind(&computeError, gbn, std::placeholders::_1), Vector10::Zero());
333 Vector gradient = numericalGradient<Vector10>(
334 std::bind(&computeError, gbn, std::placeholders::_1), Vector10::Zero());
339 Vector denseMatrixGradient = -augmentedHessian.col(10).segment(0,10);
343 double step = -gradient.squaredNorm() / (gradient.transpose() * hessian * gradient)(0);
357 EXPECT(newError < origError);
376 " var11[label=\"11\", pos=\"10,20!\"];\n" 377 " var22[label=\"22\", pos=\"50,20!\"];\n"
def step(data, isam, result, truth, currPoseIndex)
double determinant() const
Concept check for values that can be used in unit tests.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
VectorValues sample(std::mt19937_64 *rng) const
void determinant(const MatrixType &m)
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
static const Vector2 b(10, 10)
Rot2 R(Rot2::fromAngle(0.1))
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const
Output to graphviz format, stream version.
static const GaussianBayesNet gbn
Matrix augmentedHessian(const Ordering &ordering) const
Some functions to compute numerical derivatives.
double error(const VectorValues &x) const
std::optional< Vector2 > variablePos(Key key) const
Return variable position or none.
TEST(GaussianBayesNet, Matrix)
EIGEN_DEVICE_FUNC const LogReturnType log() const
static const KeyFormatter DefaultKeyFormatter
static enum @1107 ordering
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
static const Vector2 mean(20, 40)
VectorValues optimize() const
std::map< Key, Vector2 > variablePositions
static GaussianBayesNet smallBayesNet
#define EXPECT(condition)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
VectorValues backSubstituteTranspose(const VectorValues &gx) const
Linear Factor Graph where all factors are Gaussians.
static GaussianBayesNet noisyBayesNet
#define LONGS_EQUAL(expected, actual)
DotWriter is a helper class for writing graphviz .dot files.
std::pair< Matrix, Vector > matrix(const Ordering &ordering) const
#define EXPECT_LONGS_EQUAL(expected, actual)
std::pair< Matrix, Vector > jacobian(const Ordering &ordering) const
double evaluate(const VectorValues &x) const
const sharedFactor at(size_t i) const
VectorValues optimizeGradientSearch() const
Chordal Bayes Net, the result of eliminating a factor graph.
static const double sigma
Ordering ordering() const
Jet< T, N > sqrt(const Jet< T, N > &f)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix
Jet< T, N > pow(const Jet< T, N > &f, double g)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
VectorValues backSubstitute(const VectorValues &gx) const
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
Point3 position(const NavState &X, OptionalJacobian< 3, 9 > H)
std::uint64_t Key
Integer nonlinear key type.