10 #include <gtest/gtest.h> 12 #include <Eigen/Dense> 18 #if EIGEN_VERSION_AT_LEAST(3, 1, 0) // Requires Eigen>=3.1 23 vector<double>& parent,
size_t nodeid,
double observation,
26 m_observation(observation),
27 m_information(information)
29 this->node_id = nodeid;
32 double evaluateResidual()
const override 34 return m_parent[node_id] - m_observation;
36 double getInformation()
const override {
return m_information; }
37 void evalJacobian(
double& dr_dx)
const override { dr_dx = 1.0; }
40 vector<double>& m_parent;
41 double m_observation, m_information;
47 vector<double>& parent,
size_t nodeid_i,
size_t nodeid_j,
49 : m_parent(parent), m_information(information)
51 this->node_id_i = nodeid_i;
52 this->node_id_j = nodeid_j;
55 double evaluateResidual()
const override 57 return m_parent[node_id_i] - m_parent[node_id_j];
59 double getInformation()
const override {
return m_information; }
60 void evalJacobian(
double& dr_dx_i,
double& dr_dx_j)
const override 67 vector<double>& m_parent;
74 vector<double> my_map(N, .0);
81 std::deque<MySimpleUnaryEdge> edges1;
83 edges1.emplace_back(my_map, 0, 1.0, 4.0);
84 edges1.emplace_back(my_map, 1, 5.0, 4.0);
85 edges1.emplace_back(my_map, 2, 3.0, 4.0);
86 edges1.emplace_back(my_map, 3, 2.0, 16.0);
98 EXPECT_NEAR(x_incr[0], 1.0, 1e-9);
99 EXPECT_NEAR(x_incr[1], 5.0, 1e-9);
100 EXPECT_NEAR(x_incr[2], 3.0, 1e-9);
101 EXPECT_NEAR(x_incr[3], 2.0, 1e-9);
103 EXPECT_NEAR(x_var[0], 1.0 / 4.0, 1e-9);
104 EXPECT_NEAR(x_var[1], 1.0 / 4.0, 1e-9);
105 EXPECT_NEAR(x_var[2], 1.0 / 4.0, 1e-9);
106 EXPECT_NEAR(x_var[3], 1.0 / 16.0, 1e-9);
112 my_map.assign(N, .0);
115 edges1.emplace_back(my_map, 0, 4.0, 2.0);
121 EXPECT_NEAR(x_incr[0], 2.0, 1e-9);
122 EXPECT_NEAR(x_incr[1], 5.0, 1e-9);
123 EXPECT_NEAR(x_incr[2], 3.0, 1e-9);
124 EXPECT_NEAR(x_incr[3], 2.0, 1e-9);
126 EXPECT_NEAR(x_var[0], 1.0 / (4.0 + 2.0), 1e-9);
127 EXPECT_NEAR(x_var[1], 1.0 / 4.0, 1e-9);
128 EXPECT_NEAR(x_var[2], 1.0 / 4.0, 1e-9);
129 EXPECT_NEAR(x_var[3], 1.0 / 16.0, 1e-9);
136 vector<double> my_map(N, .0);
144 MySimpleUnaryEdge edge_val0(my_map, 0, 1.0 , 1.0 );
147 MySimpleBinaryEdge edge_01(my_map, 0, 1, .1);
149 MySimpleBinaryEdge edge_12(my_map, 1, 2, .1);
151 MySimpleBinaryEdge edge_23(my_map, 2, 3, .1);
153 MySimpleBinaryEdge edge_30(my_map, 3, 0, .1);
159 my_map.assign(N, .0);
164 EXPECT_NEAR(x_incr[0], 1.0, 1e-6);
165 EXPECT_NEAR(x_incr[1], 1.0, 1e-6);
166 EXPECT_NEAR(x_incr[2], 1.0, 1e-6);
167 EXPECT_NEAR(x_incr[3], 1.0, 1e-6);
169 EXPECT_NEAR(x_var[0], 1.0, 1e-6);
171 EXPECT_GT(x_var[1], x_var[0]);
172 EXPECT_GT(x_var[3], x_var[0]);
174 EXPECT_GT(x_var[2], x_var[1]);
175 EXPECT_GT(x_var[2], x_var[3]);
void initialize(const size_t nodeCount)
Initialize the GMRF internal state and copy the prior factors.
Simple, scalar (1-dim) constraint (edge) for a GMRF.
void updateEstimation(mrpt::math::CVectorDouble &solved_x_inc, mrpt::math::CVectorDouble *solved_variances=nullptr)
Abstract graph and tree data structures, plus generic graph algorithms.
TEST(NodeletsTests, pub_sub_multithread_test)
void enableProfiler(bool enable=true)
void addConstraint(const UnaryFactorVirtualBase &listOfConstraints)
Insert constraints into the GMRF problem.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Simple, scalar (1-dim) constraint (edge) for a GMRF.
Sparse solver for GMRF (Gaussian Markov Random Fields) graphical models.