42 using namespace gtsam;
51 HybridGaussianFactor::const_iterator const_it = factor.
begin();
53 HybridGaussianFactor::iterator it = factor.
begin();
61 auto A1 = Matrix::Zero(2, 1);
62 auto A2 = Matrix::Zero(2, 2);
63 auto b = Matrix::Zero(2, 1);
65 auto f10 = std::make_shared<JacobianFactor>(
X(1),
A1,
X(2),
A2,
b);
66 auto f11 = std::make_shared<JacobianFactor>(
X(1),
A1,
X(2),
A2,
b);
75 std::vector<GaussianFactorValuePair> pairs{{
f10, 0.0}, {
f11, 0.0}};
90 auto A3 = Matrix::Zero(2, 3);
91 auto f20 = std::make_shared<JacobianFactor>(
X(1),
A1,
X(3),
A3,
b);
92 auto f21 = std::make_shared<JacobianFactor>(
X(1),
A1,
X(3),
A3,
b);
93 auto f22 = std::make_shared<JacobianFactor>(
X(1),
A1,
X(3),
A3,
b);
110 sum += hybridFactorA;
111 sum += hybridFactorB;
117 auto actual = sum(
mode);
119 EXPECT(actual.at(1) == f22);
128 R
"(HybridGaussianFactor
163 keys.push_back(
X(0));
164 keys.push_back(
X(1));
167 dKeys.emplace_back(
M(0), 2);
168 dKeys.emplace_back(
M(1), 2);
170 auto gaussians = std::make_shared<GaussianConditional>();
182 auto A01 = Matrix2::Identity();
183 auto A02 = Matrix2::Identity();
185 auto A11 = Matrix2::Identity();
186 auto A12 = Matrix2::Identity() * 2;
188 auto b = Vector2::Zero();
190 auto f0 = std::make_shared<JacobianFactor>(
X(1), A01,
X(2), A02,
b);
191 auto f1 = std::make_shared<JacobianFactor>(
X(1),
A11,
X(2),
A12,
b);
200 hybridFactor.errorTree(continuousValues);
202 std::vector<DiscreteKey> discrete_keys = {
m1};
204 std::vector<double> errors = {1, 4};
211 discreteValues[
m1.first] = 1;
213 4.0, hybridFactor.error({continuousValues, discreteValues}), 1
e-9);
224 double prob_m_z(
double mu0,
double mu1,
double sigma0,
double sigma1,
226 double x1 = ((
z - mu0) / sigma0),
x2 = ((
z - mu1) /
sigma1);
233 double sigma0,
double sigma1) {
237 auto model0 = noiseModel::Isotropic::Sigma(1, sigma0);
240 auto c0 = make_shared<GaussianConditional>(
z,
Vector1(mu0), I_1x1, model0),
248 std::vector{c0,
c1}));
250 auto mixing = make_shared<DiscreteConditional>(
m,
"50/50");
271 double mu0 = 1.0, mu1 = 3.0;
281 double midway = mu1 - mu0,
lambda = 4;
291 bn->at(0)->asDiscrete()->operator()(
DiscreteValues{{m.first, 1}}),
310 bn->at(0)->asDiscrete()->operator()(
DiscreteValues{{m.first, 1}}),
323 bn->at(0)->asDiscrete()->operator()(
DiscreteValues{{m.first, 1}}),
343 double mu0 = 1.0, mu1 = 3.0;
344 double sigma0 = 8.0,
sigma1 = 4.0;
351 double m1_high = 3.133,
lambda = 4;
385 bn->at(0)->asDiscrete()->operator()(
DiscreteValues{{m.first, 1}}),
398 bn->at(0)->asDiscrete()->operator()(
DiscreteValues{{m.first, 1}}),
408 auto measurement_model = noiseModel::Isotropic::Sigma(1,
sigma);
410 -I_1x1, measurement_model);
415 double mu0,
double mu1,
double sigma0,
double sigma1) {
416 auto model0 = noiseModel::Isotropic::Sigma(1, sigma0);
418 auto c0 = make_shared<GaussianConditional>(
X(1),
Vector1(mu0), I_1x1,
X(0),
420 c1 = make_shared<GaussianConditional>(
X(1),
Vector1(mu1), I_1x1,
X(0),
423 return std::make_shared<HybridGaussianConditional>(
426 std::vector{c0,
c1}));
432 bool add_second_measurement =
false) {
439 if (add_second_measurement) {
460 q.push_back(hybridMotionModel);
462 X(0), given.
at(
Z(0)), 3.0));
466 double w0 = 0.0, w1 = 0.0;
467 std::mt19937_64
rng(42);
468 for (
int i = 0;
i <
N;
i++) {
471 double weight = hbn.
evaluate(sample) /
q.evaluate(sample);
472 (sample.
atDiscrete(
M(1)) == 0) ? w0 += weight : w1 += weight;
474 double pm1 = w1 / (w0 + w1);
475 std::cout <<
"p(m0) = " << 100 * (1.0 - pm1) << std::endl;
476 std::cout <<
"p(m1) = " << 100 * pm1 << std::endl;
477 return {1.0 - pm1, pm1};
497 double mu0 = 1.0, mu1 = 3.0;
553 double mu0 = 1.0, mu1 = 3.0;
554 double sigma0 = 0.5,
sigma1 = 2.0;
583 auto p_m = bn->at(2)->asDiscrete();
648 double sigma0 = 0.5,
sigma1 = 2.0;
677 auto p_m = bn->at(2)->asDiscrete();
734 double mu0 = 0.0, mu1 = 10.0;
735 double sigma0 = 0.2,
sigma1 = 5.0;
768 double measurement_noise = 1
e-3) {
769 auto model0 = noiseModel::Isotropic::Sigma(1,
sigmas[0]);
770 auto model1 = noiseModel::Isotropic::Sigma(1,
sigmas[1]);
771 auto prior_noise = noiseModel::Isotropic::Sigma(1, measurement_noise);
774 std::make_shared<BetweenFactor<double>>(
X(0),
X(1),
means[0], model0)
783 std::vector<GaussianFactorValuePair>
factors{{
f0, model0->negLogConstant()},
811 double x1 = 0.0,
x2 = 1.75;
815 std::vector<double>
means = {0.0, 2.0},
sigmas = {1
e-0, 1
e-0};
842 auto prior_noise = noiseModel::Isotropic::Sigma(1, 1
e-3);
886 double x1 = 1.0,
x2 = 1.0;
890 std::vector<double>
means = {0.0, 0.0},
sigmas = {1e2, 1
e-2};