c++17 style eliminatePartialSequential calls
parent
616b366d8a
commit
eeda8a7ff2
|
@ -131,9 +131,7 @@ TEST(HybridBayesNet, Choose) {
|
||||||
|
|
||||||
const Ordering ordering(s.linearizationPoint.keys());
|
const Ordering ordering(s.linearizationPoint.keys());
|
||||||
|
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet;
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
|
||||||
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
DiscreteValues assignment;
|
DiscreteValues assignment;
|
||||||
|
|
|
@ -99,9 +99,7 @@ TEST(HybridBayesTree, OptimizeAssignment) {
|
||||||
Ordering ordering;
|
Ordering ordering;
|
||||||
for (size_t k = 0; k < s.K; k++) ordering += X(k);
|
for (size_t k = 0; k < s.K; k++) ordering += X(k);
|
||||||
|
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet;
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
|
||||||
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
GaussianBayesNet gbn = hybridBayesNet->choose(assignment);
|
GaussianBayesNet gbn = hybridBayesNet->choose(assignment);
|
||||||
|
@ -143,9 +141,7 @@ TEST(HybridBayesTree, Optimize) {
|
||||||
Ordering ordering;
|
Ordering ordering;
|
||||||
for (size_t k = 0; k < s.K; k++) ordering += X(k);
|
for (size_t k = 0; k < s.K; k++) ordering += X(k);
|
||||||
|
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet;
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
|
||||||
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
s.linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
DiscreteFactorGraph dfg;
|
DiscreteFactorGraph dfg;
|
||||||
|
|
|
@ -239,10 +239,8 @@ std::vector<size_t> getDiscreteSequence(size_t x) {
|
||||||
*/
|
*/
|
||||||
AlgebraicDecisionTree<Key> getProbPrimeTree(
|
AlgebraicDecisionTree<Key> getProbPrimeTree(
|
||||||
const HybridGaussianFactorGraph& graph) {
|
const HybridGaussianFactorGraph& graph) {
|
||||||
HybridBayesNet::shared_ptr bayesNet;
|
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingGraph;
|
|
||||||
Ordering continuous(graph.continuousKeySet());
|
Ordering continuous(graph.continuousKeySet());
|
||||||
std::tie(bayesNet, remainingGraph) =
|
const auto [bayesNet, remainingGraph] =
|
||||||
graph.eliminatePartialSequential(continuous);
|
graph.eliminatePartialSequential(continuous);
|
||||||
|
|
||||||
auto last_conditional = bayesNet->at(bayesNet->size() - 1);
|
auto last_conditional = bayesNet->at(bayesNet->size() - 1);
|
||||||
|
@ -297,9 +295,7 @@ TEST(HybridEstimation, Probability) {
|
||||||
|
|
||||||
// Continuous elimination
|
// Continuous elimination
|
||||||
Ordering continuous_ordering(graph.continuousKeySet());
|
Ordering continuous_ordering(graph.continuousKeySet());
|
||||||
HybridBayesNet::shared_ptr bayesNet;
|
auto [bayesNet, discreteGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr discreteGraph;
|
|
||||||
std::tie(bayesNet, discreteGraph) =
|
|
||||||
graph.eliminatePartialSequential(continuous_ordering);
|
graph.eliminatePartialSequential(continuous_ordering);
|
||||||
|
|
||||||
// Discrete elimination
|
// Discrete elimination
|
||||||
|
@ -347,9 +343,7 @@ TEST(HybridEstimation, ProbabilityMultifrontal) {
|
||||||
|
|
||||||
// Eliminate continuous
|
// Eliminate continuous
|
||||||
Ordering continuous_ordering(graph.continuousKeySet());
|
Ordering continuous_ordering(graph.continuousKeySet());
|
||||||
HybridBayesTree::shared_ptr bayesTree;
|
const auto [bayesTree, discreteGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr discreteGraph;
|
|
||||||
std::tie(bayesTree, discreteGraph) =
|
|
||||||
graph.eliminatePartialMultifrontal(continuous_ordering);
|
graph.eliminatePartialMultifrontal(continuous_ordering);
|
||||||
|
|
||||||
// Get the last continuous conditional which will have all the discrete keys
|
// Get the last continuous conditional which will have all the discrete keys
|
||||||
|
|
|
@ -270,9 +270,7 @@ TEST(HybridGaussianFactorGraph, eliminateFullMultifrontalTwoClique) {
|
||||||
auto ordering_full =
|
auto ordering_full =
|
||||||
Ordering::ColamdConstrainedLast(hfg, {M(0), M(1), M(2), M(3)});
|
Ordering::ColamdConstrainedLast(hfg, {M(0), M(1), M(2), M(3)});
|
||||||
|
|
||||||
HybridBayesTree::shared_ptr hbt;
|
const auto [hbt, remaining] = hfg.eliminatePartialMultifrontal(ordering_full);
|
||||||
HybridGaussianFactorGraph::shared_ptr remaining;
|
|
||||||
std::tie(hbt, remaining) = hfg.eliminatePartialMultifrontal(ordering_full);
|
|
||||||
|
|
||||||
// 9 cliques in the bayes tree and 0 remaining variables to eliminate.
|
// 9 cliques in the bayes tree and 0 remaining variables to eliminate.
|
||||||
EXPECT_LONGS_EQUAL(9, hbt->size());
|
EXPECT_LONGS_EQUAL(9, hbt->size());
|
||||||
|
@ -353,9 +351,7 @@ TEST(HybridGaussianFactorGraph, Switching) {
|
||||||
// GTSAM_PRINT(*hfg);
|
// GTSAM_PRINT(*hfg);
|
||||||
// GTSAM_PRINT(ordering_full);
|
// GTSAM_PRINT(ordering_full);
|
||||||
|
|
||||||
HybridBayesTree::shared_ptr hbt;
|
const auto [hbt, remaining] = hfg->eliminatePartialMultifrontal(ordering_full);
|
||||||
HybridGaussianFactorGraph::shared_ptr remaining;
|
|
||||||
std::tie(hbt, remaining) = hfg->eliminatePartialMultifrontal(ordering_full);
|
|
||||||
|
|
||||||
// 12 cliques in the bayes tree and 0 remaining variables to eliminate.
|
// 12 cliques in the bayes tree and 0 remaining variables to eliminate.
|
||||||
EXPECT_LONGS_EQUAL(12, hbt->size());
|
EXPECT_LONGS_EQUAL(12, hbt->size());
|
||||||
|
@ -411,9 +407,7 @@ TEST(HybridGaussianFactorGraph, SwitchingISAM) {
|
||||||
}
|
}
|
||||||
auto ordering_full = Ordering(ordering);
|
auto ordering_full = Ordering(ordering);
|
||||||
|
|
||||||
HybridBayesTree::shared_ptr hbt;
|
const auto [hbt, remaining] = hfg->eliminatePartialMultifrontal(ordering_full);
|
||||||
HybridGaussianFactorGraph::shared_ptr remaining;
|
|
||||||
std::tie(hbt, remaining) = hfg->eliminatePartialMultifrontal(ordering_full);
|
|
||||||
|
|
||||||
auto new_fg = makeSwitchingChain(12);
|
auto new_fg = makeSwitchingChain(12);
|
||||||
auto isam = HybridGaussianISAM(*hbt);
|
auto isam = HybridGaussianISAM(*hbt);
|
||||||
|
@ -847,10 +841,9 @@ TEST(HybridGaussianFactorGraph, EliminateSwitchingNetwork) {
|
||||||
EXPECT(ratioTest(bn, measurements, fg));
|
EXPECT(ratioTest(bn, measurements, fg));
|
||||||
|
|
||||||
// Do elimination of X(2) only:
|
// Do elimination of X(2) only:
|
||||||
auto result = fg.eliminatePartialSequential(Ordering{X(2)});
|
auto [bn1, fg1] = fg.eliminatePartialSequential(Ordering{X(2)});
|
||||||
auto fg1 = *result.second;
|
fg1->push_back(*bn1);
|
||||||
fg1.push_back(*result.first);
|
EXPECT(ratioTest(bn, measurements, *fg1));
|
||||||
EXPECT(ratioTest(bn, measurements, fg1));
|
|
||||||
|
|
||||||
// Create ordering that eliminates in time order, then discrete modes:
|
// Create ordering that eliminates in time order, then discrete modes:
|
||||||
Ordering ordering {X(2), X(1), X(0), N(0), N(1), N(2), M(1), M(2)};
|
Ordering ordering {X(2), X(1), X(0), N(0), N(1), N(2), M(1), M(2)};
|
||||||
|
|
|
@ -132,9 +132,7 @@ TEST(HybridGaussianElimination, IncrementalInference) {
|
||||||
ordering += X(2);
|
ordering += X(2);
|
||||||
|
|
||||||
// Now we calculate the expected factors using full elimination
|
// Now we calculate the expected factors using full elimination
|
||||||
HybridBayesTree::shared_ptr expectedHybridBayesTree;
|
const auto [expectedHybridBayesTree, expectedRemainingGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr expectedRemainingGraph;
|
|
||||||
std::tie(expectedHybridBayesTree, expectedRemainingGraph) =
|
|
||||||
switching.linearizedFactorGraph.eliminatePartialMultifrontal(ordering);
|
switching.linearizedFactorGraph.eliminatePartialMultifrontal(ordering);
|
||||||
|
|
||||||
// The densities on X(0) should be the same
|
// The densities on X(0) should be the same
|
||||||
|
@ -231,9 +229,7 @@ TEST(HybridGaussianElimination, Approx_inference) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we calculate the actual factors using full elimination
|
// Now we calculate the actual factors using full elimination
|
||||||
HybridBayesTree::shared_ptr unprunedHybridBayesTree;
|
const auto [unprunedHybridBayesTree, unprunedRemainingGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr unprunedRemainingGraph;
|
|
||||||
std::tie(unprunedHybridBayesTree, unprunedRemainingGraph) =
|
|
||||||
switching.linearizedFactorGraph.eliminatePartialMultifrontal(ordering);
|
switching.linearizedFactorGraph.eliminatePartialMultifrontal(ordering);
|
||||||
|
|
||||||
size_t maxNrLeaves = 5;
|
size_t maxNrLeaves = 5;
|
||||||
|
|
|
@ -385,9 +385,7 @@ TEST(HybridFactorGraph, Partial_Elimination) {
|
||||||
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
||||||
|
|
||||||
// Eliminate partially i.e. only continuous part.
|
// Eliminate partially i.e. only continuous part.
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet;
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
|
||||||
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
CHECK(hybridBayesNet);
|
CHECK(hybridBayesNet);
|
||||||
|
@ -415,8 +413,6 @@ TEST(HybridFactorGraph, Full_Elimination) {
|
||||||
auto linearizedFactorGraph = self.linearizedFactorGraph;
|
auto linearizedFactorGraph = self.linearizedFactorGraph;
|
||||||
|
|
||||||
// We first do a partial elimination
|
// We first do a partial elimination
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet_partial;
|
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph_partial;
|
|
||||||
DiscreteBayesNet discreteBayesNet;
|
DiscreteBayesNet discreteBayesNet;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -425,7 +421,7 @@ TEST(HybridFactorGraph, Full_Elimination) {
|
||||||
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
||||||
|
|
||||||
// Eliminate partially.
|
// Eliminate partially.
|
||||||
std::tie(hybridBayesNet_partial, remainingFactorGraph_partial) =
|
const auto [hybridBayesNet_partial, remainingFactorGraph_partial] =
|
||||||
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
DiscreteFactorGraph discrete_fg;
|
DiscreteFactorGraph discrete_fg;
|
||||||
|
@ -489,9 +485,7 @@ TEST(HybridFactorGraph, Printing) {
|
||||||
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
for (size_t k = 0; k < self.K; k++) ordering += X(k);
|
||||||
|
|
||||||
// Eliminate partially.
|
// Eliminate partially.
|
||||||
HybridBayesNet::shared_ptr hybridBayesNet;
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
|
||||||
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
linearizedFactorGraph.eliminatePartialSequential(ordering);
|
||||||
|
|
||||||
string expected_hybridFactorGraph = R"(
|
string expected_hybridFactorGraph = R"(
|
||||||
|
@ -721,11 +715,9 @@ TEST(HybridFactorGraph, DefaultDecisionTree) {
|
||||||
ordering += X(1);
|
ordering += X(1);
|
||||||
|
|
||||||
HybridGaussianFactorGraph linearized = *fg.linearize(initialEstimate);
|
HybridGaussianFactorGraph linearized = *fg.linearize(initialEstimate);
|
||||||
gtsam::HybridBayesNet::shared_ptr hybridBayesNet;
|
|
||||||
gtsam::HybridGaussianFactorGraph::shared_ptr remainingFactorGraph;
|
|
||||||
|
|
||||||
// This should NOT fail
|
// This should NOT fail
|
||||||
std::tie(hybridBayesNet, remainingFactorGraph) =
|
const auto [hybridBayesNet, remainingFactorGraph] =
|
||||||
linearized.eliminatePartialSequential(ordering);
|
linearized.eliminatePartialSequential(ordering);
|
||||||
EXPECT_LONGS_EQUAL(4, hybridBayesNet->size());
|
EXPECT_LONGS_EQUAL(4, hybridBayesNet->size());
|
||||||
EXPECT_LONGS_EQUAL(1, remainingFactorGraph->size());
|
EXPECT_LONGS_EQUAL(1, remainingFactorGraph->size());
|
||||||
|
|
|
@ -149,9 +149,7 @@ TEST(HybridNonlinearISAM, IncrementalInference) {
|
||||||
ordering += X(2);
|
ordering += X(2);
|
||||||
|
|
||||||
// Now we calculate the actual factors using full elimination
|
// Now we calculate the actual factors using full elimination
|
||||||
HybridBayesTree::shared_ptr expectedHybridBayesTree;
|
const auto [expectedHybridBayesTree, expectedRemainingGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr expectedRemainingGraph;
|
|
||||||
std::tie(expectedHybridBayesTree, expectedRemainingGraph) =
|
|
||||||
switching.linearizedFactorGraph
|
switching.linearizedFactorGraph
|
||||||
.BaseEliminateable::eliminatePartialMultifrontal(ordering);
|
.BaseEliminateable::eliminatePartialMultifrontal(ordering);
|
||||||
|
|
||||||
|
@ -250,9 +248,7 @@ TEST(HybridNonlinearISAM, Approx_inference) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we calculate the actual factors using full elimination
|
// Now we calculate the actual factors using full elimination
|
||||||
HybridBayesTree::shared_ptr unprunedHybridBayesTree;
|
const auto [unprunedHybridBayesTree, unprunedRemainingGraph] =
|
||||||
HybridGaussianFactorGraph::shared_ptr unprunedRemainingGraph;
|
|
||||||
std::tie(unprunedHybridBayesTree, unprunedRemainingGraph) =
|
|
||||||
switching.linearizedFactorGraph
|
switching.linearizedFactorGraph
|
||||||
.BaseEliminateable::eliminatePartialMultifrontal(ordering);
|
.BaseEliminateable::eliminatePartialMultifrontal(ordering);
|
||||||
|
|
||||||
|
|
|
@ -72,9 +72,7 @@ namespace gtsam {
|
||||||
gttic(eliminateSequential);
|
gttic(eliminateSequential);
|
||||||
// Do elimination
|
// Do elimination
|
||||||
EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
|
EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
|
||||||
std::shared_ptr<BayesNetType> bayesNet;
|
const auto [bayesNet, factorGraph] = etree.eliminate(function);
|
||||||
std::shared_ptr<FactorGraphType> factorGraph;
|
|
||||||
std::tie(bayesNet,factorGraph) = etree.eliminate(function);
|
|
||||||
// If any factors are remaining, the ordering was incomplete
|
// If any factors are remaining, the ordering was incomplete
|
||||||
if(!factorGraph->empty())
|
if(!factorGraph->empty())
|
||||||
throw InconsistentEliminationRequested();
|
throw InconsistentEliminationRequested();
|
||||||
|
@ -136,9 +134,7 @@ namespace gtsam {
|
||||||
// Do elimination with given ordering
|
// Do elimination with given ordering
|
||||||
EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
|
EliminationTreeType etree(asDerived(), (*variableIndex).get(), ordering);
|
||||||
JunctionTreeType junctionTree(etree);
|
JunctionTreeType junctionTree(etree);
|
||||||
std::shared_ptr<BayesTreeType> bayesTree;
|
const auto [bayesTree, factorGraph] = junctionTree.eliminate(function);
|
||||||
std::shared_ptr<FactorGraphType> factorGraph;
|
|
||||||
std::tie(bayesTree,factorGraph) = junctionTree.eliminate(function);
|
|
||||||
// If any factors are remaining, the ordering was incomplete
|
// If any factors are remaining, the ordering was incomplete
|
||||||
if(!factorGraph->empty())
|
if(!factorGraph->empty())
|
||||||
throw InconsistentEliminationRequested();
|
throw InconsistentEliminationRequested();
|
||||||
|
@ -274,9 +270,7 @@ namespace gtsam {
|
||||||
gttic(marginalMultifrontalBayesNet);
|
gttic(marginalMultifrontalBayesNet);
|
||||||
// An ordering was provided for the marginalized variables, so we can first eliminate them
|
// An ordering was provided for the marginalized variables, so we can first eliminate them
|
||||||
// in the order requested.
|
// in the order requested.
|
||||||
std::shared_ptr<BayesTreeType> bayesTree;
|
const auto [bayesTree, factorGraph] =
|
||||||
std::shared_ptr<FactorGraphType> factorGraph;
|
|
||||||
std::tie(bayesTree,factorGraph) =
|
|
||||||
eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
|
eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
|
||||||
|
|
||||||
if(const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
|
if(const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
|
||||||
|
@ -341,9 +335,7 @@ namespace gtsam {
|
||||||
gttic(marginalMultifrontalBayesTree);
|
gttic(marginalMultifrontalBayesTree);
|
||||||
// An ordering was provided for the marginalized variables, so we can first eliminate them
|
// An ordering was provided for the marginalized variables, so we can first eliminate them
|
||||||
// in the order requested.
|
// in the order requested.
|
||||||
std::shared_ptr<BayesTreeType> bayesTree;
|
const auto [bayesTree, factorGraph] =
|
||||||
std::shared_ptr<FactorGraphType> factorGraph;
|
|
||||||
std::tie(bayesTree,factorGraph) =
|
|
||||||
eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
|
eliminatePartialMultifrontal(marginalizedVariableOrdering, function, variableIndex);
|
||||||
|
|
||||||
if(const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
|
if(const Ordering* varsAsOrdering = boost::get<const Ordering&>(&variables))
|
||||||
|
|
|
@ -198,7 +198,7 @@ namespace gtsam {
|
||||||
allRemainingFactors->push_back(remainingFactors.begin(), remainingFactors.end());
|
allRemainingFactors->push_back(remainingFactors.begin(), remainingFactors.end());
|
||||||
|
|
||||||
// Return result
|
// Return result
|
||||||
return std::make_pair(result, allRemainingFactors);
|
return {result, allRemainingFactors};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
@ -38,12 +38,12 @@ KalmanFilter::solve(const GaussianFactorGraph& factorGraph) const {
|
||||||
|
|
||||||
// Eliminate the graph using the provided Eliminate function
|
// Eliminate the graph using the provided Eliminate function
|
||||||
Ordering ordering(factorGraph.keys());
|
Ordering ordering(factorGraph.keys());
|
||||||
GaussianBayesNet::shared_ptr bayesNet = //
|
const auto bayesNet = //
|
||||||
factorGraph.eliminateSequential(ordering, function_);
|
factorGraph.eliminateSequential(ordering, function_);
|
||||||
|
|
||||||
// As this is a filter, all we need is the posterior P(x_t).
|
// As this is a filter, all we need is the posterior P(x_t).
|
||||||
// This is the last GaussianConditional in the resulting BayesNet
|
// This is the last GaussianConditional in the resulting BayesNet
|
||||||
GaussianConditional::shared_ptr posterior = *(--bayesNet->end());
|
GaussianConditional::shared_ptr posterior = bayesNet->back();
|
||||||
return std::make_shared<GaussianDensity>(*posterior);
|
return std::make_shared<GaussianDensity>(*posterior);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -245,9 +245,7 @@ TEST(GaussianFactorGraph, eliminate_empty) {
|
||||||
// eliminate an empty factor
|
// eliminate an empty factor
|
||||||
GaussianFactorGraph gfg;
|
GaussianFactorGraph gfg;
|
||||||
gfg.add(JacobianFactor());
|
gfg.add(JacobianFactor());
|
||||||
GaussianBayesNet::shared_ptr actualBN;
|
const auto [actualBN, remainingGFG] = gfg.eliminatePartialSequential(Ordering());
|
||||||
GaussianFactorGraph::shared_ptr remainingGFG;
|
|
||||||
std::tie(actualBN, remainingGFG) = gfg.eliminatePartialSequential(Ordering());
|
|
||||||
|
|
||||||
// expected Bayes net is empty
|
// expected Bayes net is empty
|
||||||
GaussianBayesNet expectedBN;
|
GaussianBayesNet expectedBN;
|
||||||
|
|
|
@ -65,17 +65,13 @@ TEST(SymbolicFactorGraph, eliminatePartialSequential) {
|
||||||
const auto expectedSfg = SymbolicFactorGraph(SymbolicFactor(2, 3))(
|
const auto expectedSfg = SymbolicFactorGraph(SymbolicFactor(2, 3))(
|
||||||
SymbolicFactor(4, 5))(SymbolicFactor(2, 3, 4));
|
SymbolicFactor(4, 5))(SymbolicFactor(2, 3, 4));
|
||||||
|
|
||||||
SymbolicBayesNet::shared_ptr actualBayesNet;
|
const auto [actualBayesNet, actualSfg] =
|
||||||
SymbolicFactorGraph::shared_ptr actualSfg;
|
|
||||||
std::tie(actualBayesNet, actualSfg) =
|
|
||||||
simpleTestGraph2.eliminatePartialSequential(Ordering{0, 1});
|
simpleTestGraph2.eliminatePartialSequential(Ordering{0, 1});
|
||||||
|
|
||||||
EXPECT(assert_equal(expectedSfg, *actualSfg));
|
EXPECT(assert_equal(expectedSfg, *actualSfg));
|
||||||
EXPECT(assert_equal(expectedBayesNet, *actualBayesNet));
|
EXPECT(assert_equal(expectedBayesNet, *actualBayesNet));
|
||||||
|
|
||||||
SymbolicBayesNet::shared_ptr actualBayesNet2;
|
const auto [actualBayesNet2, actualSfg2] =
|
||||||
SymbolicFactorGraph::shared_ptr actualSfg2;
|
|
||||||
std::tie(actualBayesNet2, actualSfg2) =
|
|
||||||
simpleTestGraph2.eliminatePartialSequential(Ordering{0, 1});
|
simpleTestGraph2.eliminatePartialSequential(Ordering{0, 1});
|
||||||
|
|
||||||
EXPECT(assert_equal(expectedSfg, *actualSfg2));
|
EXPECT(assert_equal(expectedSfg, *actualSfg2));
|
||||||
|
@ -106,9 +102,7 @@ TEST(SymbolicFactorGraph, eliminatePartialMultifrontal) {
|
||||||
SymbolicFactorGraph(SymbolicFactor(0, 1))(SymbolicFactor(0, 2))(
|
SymbolicFactorGraph(SymbolicFactor(0, 1))(SymbolicFactor(0, 2))(
|
||||||
SymbolicFactor(1, 3))(SymbolicFactor(2, 3))(SymbolicFactor(1));
|
SymbolicFactor(1, 3))(SymbolicFactor(2, 3))(SymbolicFactor(1));
|
||||||
|
|
||||||
SymbolicBayesTree::shared_ptr actualBayesTree;
|
const auto [actualBayesTree, actualFactorGraph] =
|
||||||
SymbolicFactorGraph::shared_ptr actualFactorGraph;
|
|
||||||
std::tie(actualBayesTree, actualFactorGraph) =
|
|
||||||
simpleTestGraph2.eliminatePartialMultifrontal(Ordering{4, 5});
|
simpleTestGraph2.eliminatePartialMultifrontal(Ordering{4, 5});
|
||||||
|
|
||||||
EXPECT(assert_equal(expectedFactorGraph, *actualFactorGraph));
|
EXPECT(assert_equal(expectedFactorGraph, *actualFactorGraph));
|
||||||
|
@ -122,9 +116,7 @@ TEST(SymbolicFactorGraph, eliminatePartialMultifrontal) {
|
||||||
std::make_shared<SymbolicConditional>(5, 4)));
|
std::make_shared<SymbolicConditional>(5, 4)));
|
||||||
expectedBayesTree2.insertRoot(root2);
|
expectedBayesTree2.insertRoot(root2);
|
||||||
|
|
||||||
SymbolicBayesTree::shared_ptr actualBayesTree2;
|
const auto [actualBayesTree2, actualFactorGraph2] =
|
||||||
SymbolicFactorGraph::shared_ptr actualFactorGraph2;
|
|
||||||
std::tie(actualBayesTree2, actualFactorGraph2) =
|
|
||||||
simpleTestGraph2.eliminatePartialMultifrontal(KeyVector{4, 5});
|
simpleTestGraph2.eliminatePartialMultifrontal(KeyVector{4, 5});
|
||||||
|
|
||||||
EXPECT(assert_equal(expectedFactorGraph, *actualFactorGraph2));
|
EXPECT(assert_equal(expectedFactorGraph, *actualFactorGraph2));
|
||||||
|
@ -152,11 +144,11 @@ TEST(SymbolicFactorGraph, eliminate_disconnected_graph) {
|
||||||
|
|
||||||
// create expected Chordal bayes Net
|
// create expected Chordal bayes Net
|
||||||
SymbolicBayesNet expected;
|
SymbolicBayesNet expected;
|
||||||
expected.push_back(std::make_shared<SymbolicConditional>(0, 1, 2));
|
expected.emplace_shared<SymbolicConditional>(0, 1, 2);
|
||||||
expected.push_back(std::make_shared<SymbolicConditional>(1, 2));
|
expected.emplace_shared<SymbolicConditional>(1, 2);
|
||||||
expected.push_back(std::make_shared<SymbolicConditional>(2));
|
expected.emplace_shared<SymbolicConditional>(2);
|
||||||
expected.push_back(std::make_shared<SymbolicConditional>(3, 4));
|
expected.emplace_shared<SymbolicConditional>(3, 4);
|
||||||
expected.push_back(std::make_shared<SymbolicConditional>(4));
|
expected.emplace_shared<SymbolicConditional>(4);
|
||||||
|
|
||||||
Ordering order;
|
Ordering order;
|
||||||
order += 0, 1, 2, 3, 4;
|
order += 0, 1, 2, 3, 4;
|
||||||
|
|
|
@ -178,9 +178,6 @@ void solveStaged(size_t addMutex = 2) {
|
||||||
gttoc_(eliminate);
|
gttoc_(eliminate);
|
||||||
|
|
||||||
// find root node
|
// find root node
|
||||||
// chordal->back()->print("back: ");
|
|
||||||
// chordal->front()->print("front: ");
|
|
||||||
// exit(0);
|
|
||||||
DiscreteConditional::shared_ptr root = chordal->back();
|
DiscreteConditional::shared_ptr root = chordal->back();
|
||||||
if (debug)
|
if (debug)
|
||||||
root->print(""/*scheduler.studentName(s)*/);
|
root->print(""/*scheduler.studentName(s)*/);
|
||||||
|
@ -211,7 +208,6 @@ DiscreteBayesNet::shared_ptr createSampler(size_t i,
|
||||||
SETDEBUG("Scheduler::buildGraph", false);
|
SETDEBUG("Scheduler::buildGraph", false);
|
||||||
scheduler.addStudentSpecificConstraints(0, slot);
|
scheduler.addStudentSpecificConstraints(0, slot);
|
||||||
DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate();
|
DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate();
|
||||||
// chordal->print(scheduler[i].studentKey(0).name()); // large !
|
|
||||||
schedulers.push_back(scheduler);
|
schedulers.push_back(scheduler);
|
||||||
return chordal;
|
return chordal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -584,10 +584,10 @@ TEST( ConcurrentIncrementalSmootherDL, synchronize_3 )
|
||||||
allkeys.erase(key);
|
allkeys.erase(key);
|
||||||
}
|
}
|
||||||
KeyVector variables(allkeys.begin(), allkeys.end());
|
KeyVector variables(allkeys.begin(), allkeys.end());
|
||||||
std::pair<GaussianBayesNet::shared_ptr, GaussianFactorGraph::shared_ptr> result = LinFactorGraph->eliminatePartialSequential(variables, EliminateCholesky);
|
const auto [bn, fg] = LinFactorGraph->eliminatePartialSequential(variables, EliminateCholesky);
|
||||||
|
|
||||||
expectedSmootherSummarization.resize(0);
|
expectedSmootherSummarization.resize(0);
|
||||||
for(const GaussianFactor::shared_ptr& factor: *result.second) {
|
for(const GaussianFactor::shared_ptr& factor: *fg) {
|
||||||
expectedSmootherSummarization.push_back(LinearContainerFactor(factor, allValues));
|
expectedSmootherSummarization.push_back(LinearContainerFactor(factor, allValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -584,10 +584,10 @@ TEST( ConcurrentIncrementalSmootherGN, synchronize_3 )
|
||||||
KeySet allkeys = LinFactorGraph->keys();
|
KeySet allkeys = LinFactorGraph->keys();
|
||||||
for (const auto key : filterSeparatorValues.keys()) allkeys.erase(key);
|
for (const auto key : filterSeparatorValues.keys()) allkeys.erase(key);
|
||||||
KeyVector variables(allkeys.begin(), allkeys.end());
|
KeyVector variables(allkeys.begin(), allkeys.end());
|
||||||
std::pair<GaussianBayesNet::shared_ptr, GaussianFactorGraph::shared_ptr> result = LinFactorGraph->eliminatePartialSequential(variables, EliminateCholesky);
|
const auto [bn, fg] = LinFactorGraph->eliminatePartialSequential(variables, EliminateCholesky);
|
||||||
|
|
||||||
expectedSmootherSummarization.resize(0);
|
expectedSmootherSummarization.resize(0);
|
||||||
for(const GaussianFactor::shared_ptr& factor: *result.second) {
|
for(const GaussianFactor::shared_ptr& factor: *fg) {
|
||||||
expectedSmootherSummarization.push_back(LinearContainerFactor(factor, allValues));
|
expectedSmootherSummarization.push_back(LinearContainerFactor(factor, allValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,8 +86,8 @@ TEST(NonlinearClusterTree, Clusters) {
|
||||||
// Calculate expected result of only evaluating the marginalCluster
|
// Calculate expected result of only evaluating the marginalCluster
|
||||||
Ordering ordering;
|
Ordering ordering;
|
||||||
ordering.push_back(x1);
|
ordering.push_back(x1);
|
||||||
auto expected = gfg->eliminatePartialSequential(ordering);
|
const auto [bn, fg] = gfg->eliminatePartialSequential(ordering);
|
||||||
auto expectedFactor = std::dynamic_pointer_cast<HessianFactor>(expected.second->at(0));
|
auto expectedFactor = std::dynamic_pointer_cast<HessianFactor>(fg->at(0));
|
||||||
if (!expectedFactor)
|
if (!expectedFactor)
|
||||||
throw std::runtime_error("Expected HessianFactor");
|
throw std::runtime_error("Expected HessianFactor");
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ TEST(NonlinearClusterTree, Clusters) {
|
||||||
auto actual = marginalCluster->linearizeAndEliminate(initial);
|
auto actual = marginalCluster->linearizeAndEliminate(initial);
|
||||||
const GaussianBayesNet& bayesNet = actual.first;
|
const GaussianBayesNet& bayesNet = actual.first;
|
||||||
const HessianFactor& factor = *actual.second;
|
const HessianFactor& factor = *actual.second;
|
||||||
EXPECT(assert_equal(*expected.first->at(0), *bayesNet.at(0), 1e-6));
|
EXPECT(assert_equal(*bn->at(0), *bayesNet.at(0), 1e-6));
|
||||||
EXPECT(assert_equal(*expectedFactor, factor, 1e-6));
|
EXPECT(assert_equal(*expectedFactor, factor, 1e-6));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue