testGaussianDensity.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
20 #include <gtsam/inference/Symbol.h>
21 
23 
24 using namespace gtsam;
25 using namespace std;
27 
28 /* ************************************************************************* */
30 {
31  Matrix R = (Matrix(2,2) <<
32  -12.1244, -5.1962,
33  0., 4.6904).finished();
34 
35  Vector d = Vector2(1.0, 2.0), s = Vector2(3.0, 4.0);
36  GaussianConditional conditional(1, d, R, noiseModel::Diagonal::Sigmas(s));
37 
38  GaussianDensity copied(conditional);
39  EXPECT(assert_equal(d, copied.d()));
40  EXPECT(assert_equal(s, copied.get_model()->sigmas()));
41 }
42 
43 /* ************************************************************************* */
44 // Test FromMeanAndStddev named constructor
45 TEST(GaussianDensity, FromMeanAndStddev) {
46  Matrix A1 = (Matrix(2, 2) << 1., 2., 3., 4.).finished();
47  const Vector2 b(20, 40), x0(1, 2);
48  const double sigma = 3;
49 
51  values.insert(X(0), x0);
52 
53  auto density = GaussianDensity::FromMeanAndStddev(X(0), b, sigma);
54  Vector2 e = (x0 - b) / sigma;
55  double expected1 = 0.5 * e.dot(e);
56  EXPECT_DOUBLES_EQUAL(expected1, density.error(values), 1e-9);
57 
58  double expected2 = density.logNormalizationConstant()- 0.5 * e.dot(e);
59  EXPECT_DOUBLES_EQUAL(expected2, density.logProbability(values), 1e-9);
60 }
61 
62 /* ************************************************************************* */
63 int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
64 /* ************************************************************************* */
static Matrix A1
static int runAllTests(TestResult &result)
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Definition: Matrix.cpp:40
Eigen::MatrixXd Matrix
Definition: base/Matrix.h:39
Rot2 R(Rot2::fromAngle(0.1))
leaf::MyValues values
Definition: BFloat16.h:88
iterator insert(const std::pair< Key, Vector > &key_value)
Key X(std::uint64_t j)
const constBVector d() const
#define EXPECT_DOUBLES_EQUAL(expected, actual, threshold)
Definition: Test.h:161
A Gaussian Density.
Eigen::VectorXd Vector
Definition: Vector.h:38
static GaussianDensity FromMeanAndStddev(Key key, const Vector &mean, double sigma)
Construct using a mean and standard deviation.
#define EXPECT(condition)
Definition: Test.h:150
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
const G & b
Definition: Group.h:86
traits
Definition: chartTesting.h:28
static Symbol x0('x', 0)
int main()
Eigen::Vector2d Vector2
Definition: Vector.h:42
static shared_ptr Sigmas(const Vector &sigmas, bool smart=true)
Definition: NoiseModel.cpp:270
static const double sigma
TEST(SmartFactorBase, Pinhole)
#define X
Definition: icosphere.cpp:20
const SharedDiagonal & get_model() const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:38:08