Skip to content

Commit 64d9fc6

Browse files
committed
tree based constructors
1 parent 1c74da2 commit 64d9fc6

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

gtsam/hybrid/tests/Switching.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ inline HybridGaussianFactorGraph::shared_ptr makeSwitchingChain(
5757

5858
// keyFunc(1) to keyFunc(n+1)
5959
for (size_t t = 1; t < n; t++) {
60-
std::vector<GaussianFactorValuePair> components = {
61-
{std::make_shared<JacobianFactor>(keyFunc(t), I_3x3, keyFunc(t + 1),
62-
I_3x3, Z_3x1),
63-
0.0},
64-
{std::make_shared<JacobianFactor>(keyFunc(t), I_3x3, keyFunc(t + 1),
65-
I_3x3, Vector3::Ones()),
66-
0.0}};
67-
hfg.add(HybridGaussianFactor({keyFunc(t), keyFunc(t + 1)},
68-
{{dKeyFunc(t), 2}}, components));
60+
DiscreteKeys dKeys{{dKeyFunc(t), 2}};
61+
HybridGaussianFactor::FactorValuePairs components(
62+
dKeys, {{std::make_shared<JacobianFactor>(keyFunc(t), I_3x3,
63+
keyFunc(t + 1), I_3x3, Z_3x1),
64+
0.0},
65+
{std::make_shared<JacobianFactor>(
66+
keyFunc(t), I_3x3, keyFunc(t + 1), I_3x3, Vector3::Ones()),
67+
0.0}});
68+
hfg.add(
69+
HybridGaussianFactor({keyFunc(t), keyFunc(t + 1)}, dKeys, components));
6970

7071
if (t > 1) {
7172
hfg.add(DecisionTreeFactor({{dKeyFunc(t - 1), 2}, {dKeyFunc(t), 2}},

gtsam/hybrid/tests/testHybridBayesNet.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,17 @@ TEST(HybridBayesNet, Sampling) {
383383
HybridNonlinearFactorGraph nfg;
384384

385385
auto noise_model = noiseModel::Diagonal::Sigmas(Vector1(1.0));
386+
nfg.emplace_shared<PriorFactor<double>>(X(0), 0.0, noise_model);
387+
386388
auto zero_motion =
387389
std::make_shared<BetweenFactor<double>>(X(0), X(1), 0, noise_model);
388390
auto one_motion =
389391
std::make_shared<BetweenFactor<double>>(X(0), X(1), 1, noise_model);
390-
std::vector<NonlinearFactorValuePair> factors = {{zero_motion, 0.0},
391-
{one_motion, 0.0}};
392-
nfg.emplace_shared<PriorFactor<double>>(X(0), 0.0, noise_model);
393-
nfg.emplace_shared<HybridNonlinearFactor>(
394-
KeyVector{X(0), X(1)}, DiscreteKeys{DiscreteKey(M(0), 2)}, factors);
392+
DiscreteKeys discreteKeys{DiscreteKey(M(0), 2)};
393+
HybridNonlinearFactor::Factors factors(
394+
discreteKeys, {{zero_motion, 0.0}, {one_motion, 0.0}});
395+
nfg.emplace_shared<HybridNonlinearFactor>(KeyVector{X(0), X(1)}, discreteKeys,
396+
factors);
395397

396398
DiscreteKey mode(M(0), 2);
397399
nfg.emplace_shared<DiscreteDistribution>(mode, "1/1");

0 commit comments

Comments
 (0)