diff --git a/.cproject b/.cproject
index b9903731f..a668ce85f 100644
--- a/.cproject
+++ b/.cproject
@@ -676,6 +676,14 @@
true
true
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
make
-j2
@@ -692,6 +700,22 @@
true
true
+
+ make
+ -j2
+ all
+ true
+ true
+ true
+
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
make
-j2
@@ -756,6 +780,22 @@
true
true
+
+ make
+ -j2
+ tests/testSymbolicFactorGraph.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/testSymbolicBayesNet.run
+ true
+ true
+ true
+
make
-j2
@@ -820,14 +860,6 @@
true
true
-
- make
- -j2
- testGaussianFactorGraph
- true
- true
- true
-
make
-j2
@@ -876,6 +908,14 @@
true
true
+
+ make
+ -j2
+ testNonlinearFactor.run
+ true
+ true
+ true
+
make
-j2
@@ -1411,6 +1451,22 @@
true
true
+
+ make
+ -j2
+ testVirtual.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/timeVirtual.run
+ true
+ true
+ true
+
make
-j2
@@ -1443,6 +1499,22 @@
true
true
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/testGaussianFactorGraph.run
+ true
+ true
+ true
+
make
-j2
@@ -2359,6 +2431,14 @@
true
true
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
make
-j2
@@ -2375,6 +2455,22 @@
true
true
+
+ make
+ -j2
+ all
+ true
+ true
+ true
+
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
make
-j2
@@ -2439,6 +2535,22 @@
true
true
+
+ make
+ -j2
+ tests/testSymbolicFactorGraph.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/testSymbolicBayesNet.run
+ true
+ true
+ true
+
make
-j2
@@ -2503,14 +2615,6 @@
true
true
-
- make
- -j2
- testGaussianFactorGraph
- true
- true
- true
-
make
-j2
@@ -2559,6 +2663,14 @@
true
true
+
+ make
+ -j2
+ testNonlinearFactor.run
+ true
+ true
+ true
+
make
-j2
@@ -3094,6 +3206,22 @@
true
true
+
+ make
+ -j2
+ testVirtual.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/timeVirtual.run
+ true
+ true
+ true
+
make
-j2
@@ -3126,6 +3254,22 @@
true
true
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/testGaussianFactorGraph.run
+ true
+ true
+ true
+
make
-j2
diff --git a/gtsam/base/Testable.h b/gtsam/base/Testable.h
index e02cb2e10..8e62e08e1 100644
--- a/gtsam/base/Testable.h
+++ b/gtsam/base/Testable.h
@@ -97,6 +97,7 @@ namespace gtsam {
double tol_;
equals_star(double tol = 1e-9) : tol_(tol) {}
bool operator()(const boost::shared_ptr& expected, const boost::shared_ptr& actual) {
+ if (!actual || !expected) return false;
return (actual->equals(*expected, tol_));
}
};
diff --git a/gtsam/inference/BayesTree-inl.h b/gtsam/inference/BayesTree-inl.h
index 4a4495c15..9f950096e 100644
--- a/gtsam/inference/BayesTree-inl.h
+++ b/gtsam/inference/BayesTree-inl.h
@@ -280,8 +280,8 @@ namespace gtsam {
// TODO, why do we actually return a shared pointer, why does eliminate?
/* ************************************************************************* */
template
- BayesNet
- BayesTree::Clique::shortcut(shared_ptr R) {
+ BayesNet BayesTree::Clique::shortcut(shared_ptr R,
+ Eliminate function) {
static const bool debug = false;
@@ -296,17 +296,17 @@ namespace gtsam {
}
// The root conditional
- FactorGraph p_R(*R);
+ FactorGraph p_R(*R);
// The parent clique has a CONDITIONAL for each frontal node in Fp
// so we can obtain P(Fp|Sp) in factor graph form
- FactorGraph p_Fp_Sp(*parent);
+ FactorGraph p_Fp_Sp(*parent);
// If not the base case, obtain the parent shortcut P(Sp|R) as factors
- FactorGraph p_Sp_R(parent->shortcut(R));
+ FactorGraph p_Sp_R(parent->shortcut(R, function));
// now combine P(Cp|R) = P(Fp|Sp) * P(Sp|R)
- FactorGraph p_Cp_R;
+ FactorGraph p_Cp_R;
p_Cp_R.push_back(p_R);
p_Cp_R.push_back(p_Fp_Sp);
p_Cp_R.push_back(p_Sp_R);
@@ -345,9 +345,10 @@ namespace gtsam {
vector(variablesAtBack.begin(), variablesAtBack.end()),
R->back()->key() + 1);
Permutation::shared_ptr toBackInverse(toBack.inverse());
- BOOST_FOREACH(const typename CONDITIONAL::FactorType::shared_ptr& factor, p_Cp_R) {
+ BOOST_FOREACH(const typename FactorType::shared_ptr& factor, p_Cp_R) {
factor->permuteWithInverse(*toBackInverse); }
- typename BayesNet::shared_ptr eliminated(EliminationTree::Create(p_Cp_R)->eliminate());
+ typename BayesNet::shared_ptr eliminated(EliminationTree<
+ FactorType>::Create(p_Cp_R)->eliminate(function));
// Take only the conditionals for p(S|R). We check for each variable being
// in the separator set because if some separator variables overlap with
@@ -380,34 +381,37 @@ namespace gtsam {
// Because the root clique could be very big.
/* ************************************************************************* */
template
- FactorGraph BayesTree::Clique::marginal(shared_ptr R) {
+ FactorGraph BayesTree::Clique::marginal(
+ shared_ptr R, Eliminate function) {
// If we are the root, just return this root
// NOTE: immediately cast to a factor graph
if (R.get()==this) return *R;
// Combine P(F|S), P(S|R), and P(R)
- BayesNet p_FSR = this->shortcut(R);
+ BayesNet p_FSR = this->shortcut(R, function);
p_FSR.push_front(*this);
p_FSR.push_back(*R);
assertInvariants();
- return *GenericSequentialSolver(p_FSR).jointFactorGraph(keys());
+ GenericSequentialSolver solver(p_FSR);
+ return *solver.jointFactorGraph(keys(), function);
}
/* ************************************************************************* */
// P(C1,C2) = \int_R P(F1|S1) P(S1|R) P(F2|S1) P(S2|R) P(R)
/* ************************************************************************* */
template
- FactorGraph BayesTree::Clique::joint(shared_ptr C2, shared_ptr R) {
+ FactorGraph BayesTree::Clique::joint(
+ shared_ptr C2, shared_ptr R, Eliminate function) {
// For now, assume neither is the root
// Combine P(F1|S1), P(S1|R), P(F2|S2), P(S2|R), and P(R)
- FactorGraph joint;
- if (!isRoot()) joint.push_back(*this); // P(F1|S1)
- if (!isRoot()) joint.push_back(shortcut(R)); // P(S1|R)
- if (!C2->isRoot()) joint.push_back(*C2); // P(F2|S2)
- if (!C2->isRoot()) joint.push_back(C2->shortcut(R)); // P(S2|R)
- joint.push_back(*R); // P(R)
+ FactorGraph joint;
+ if (!isRoot()) joint.push_back(*this); // P(F1|S1)
+ if (!isRoot()) joint.push_back(shortcut(R, function)); // P(S1|R)
+ if (!C2->isRoot()) joint.push_back(*C2); // P(F2|S2)
+ if (!C2->isRoot()) joint.push_back(C2->shortcut(R, function)); // P(S2|R)
+ joint.push_back(*R); // P(R)
// Find the keys of both C1 and C2
vector keys1(keys());
@@ -420,7 +424,8 @@ namespace gtsam {
vector keys12vector; keys12vector.reserve(keys12.size());
keys12vector.insert(keys12vector.begin(), keys12.begin(), keys12.end());
assertInvariants();
- return *GenericSequentialSolver(joint).jointFactorGraph(keys12vector);
+ GenericSequentialSolver solver(joint);
+ return *solver.jointFactorGraph(keys12vector, function);
}
/* ************************************************************************* */
@@ -729,53 +734,59 @@ namespace gtsam {
// First finds clique marginal then marginalizes that
/* ************************************************************************* */
template
- typename CONDITIONAL::FactorType::shared_ptr BayesTree::marginalFactor(Index key) const {
+ typename CONDITIONAL::FactorType::shared_ptr BayesTree::marginalFactor(
+ Index key, Eliminate function) const {
// get clique containing key
sharedClique clique = (*this)[key];
// calculate or retrieve its marginal
- FactorGraph cliqueMarginal = clique->marginal(root_);
+ FactorGraph cliqueMarginal = clique->marginal(root_,function);
- return GenericSequentialSolver(cliqueMarginal).marginalFactor(key);
+ return GenericSequentialSolver (cliqueMarginal).marginalFactor(
+ key, function);
}
/* ************************************************************************* */
template
- typename BayesNet::shared_ptr BayesTree::marginalBayesNet(Index key) const {
+ typename BayesNet::shared_ptr BayesTree::marginalBayesNet(
+ Index key, Eliminate function) const {
// calculate marginal as a factor graph
- FactorGraph fg;
- fg.push_back(this->marginalFactor(key));
+ FactorGraph fg;
+ fg.push_back(this->marginalFactor(key,function));
// eliminate factor graph marginal to a Bayes net
- return GenericSequentialSolver(fg).eliminate();
+ return GenericSequentialSolver(fg).eliminate(function);
}
/* ************************************************************************* */
// Find two cliques, their joint, then marginalizes
/* ************************************************************************* */
template
- typename FactorGraph::shared_ptr
- BayesTree::joint(Index key1, Index key2) const {
+ typename FactorGraph::shared_ptr BayesTree<
+ CONDITIONAL>::joint(Index key1, Index key2, Eliminate function) const {
// get clique C1 and C2
sharedClique C1 = (*this)[key1], C2 = (*this)[key2];
// calculate joint
- FactorGraph p_C1C2(C1->joint(C2, root_));
+ FactorGraph p_C1C2(C1->joint(C2, root_, function));
// eliminate remaining factor graph to get requested joint
vector key12(2); key12[0] = key1; key12[1] = key2;
- return GenericSequentialSolver(p_C1C2).jointFactorGraph(key12);
+ GenericSequentialSolver solver(p_C1C2);
+ return solver.jointFactorGraph(key12,function);
}
/* ************************************************************************* */
template
- typename BayesNet::shared_ptr BayesTree::jointBayesNet(Index key1, Index key2) const {
+ typename BayesNet::shared_ptr BayesTree::jointBayesNet(
+ Index key1, Index key2, Eliminate function) const {
- // eliminate factor graph marginal to a Bayes net
- return GenericSequentialSolver(*this->joint(key1, key2)).eliminate();
+ // eliminate factor graph marginal to a Bayes net
+ return GenericSequentialSolver (
+ *this->joint(key1, key2, function)).eliminate(function);
}
/* ************************************************************************* */
diff --git a/gtsam/inference/BayesTree.h b/gtsam/inference/BayesTree.h
index 8f9a1865a..064a116a1 100644
--- a/gtsam/inference/BayesTree.h
+++ b/gtsam/inference/BayesTree.h
@@ -46,6 +46,8 @@ namespace gtsam {
typedef boost::shared_ptr > shared_ptr;
typedef boost::shared_ptr sharedConditional;
typedef boost::shared_ptr > sharedBayesNet;
+ typedef typename CONDITIONAL::FactorType FactorType;
+ typedef typename FactorGraph::Eliminate Eliminate;
/**
* A Clique in the tree is an incomplete Bayes net: the variables
@@ -63,7 +65,7 @@ namespace gtsam {
weak_ptr parent_;
std::list children_;
std::list separator_; /** separator keys */
- typename CONDITIONAL::FactorType::shared_ptr cachedFactor_;
+ typename FactorType::shared_ptr cachedFactor_;
friend class BayesTree;
@@ -96,7 +98,7 @@ namespace gtsam {
size_t treeSize() const;
/** Access the cached factor (this is a hack) */
- typename CONDITIONAL::FactorType::shared_ptr& cachedFactor() { return cachedFactor_; }
+ typename FactorType::shared_ptr& cachedFactor() { return cachedFactor_; }
/** print this node and entire subtree below it */
void printTree(const std::string& indent="") const;
@@ -113,13 +115,13 @@ namespace gtsam {
/** return the conditional P(S|Root) on the separator given the root */
// TODO: create a cached version
- BayesNet shortcut(shared_ptr root);
+ BayesNet shortcut(shared_ptr root, Eliminate function);
/** return the marginal P(C) of the clique */
- FactorGraph marginal(shared_ptr root);
+ FactorGraph marginal(shared_ptr root, Eliminate function);
/** return the joint P(C1,C2), where C1==this. TODO: not a method? */
- FactorGraph joint(shared_ptr C2, shared_ptr root);
+ FactorGraph joint(shared_ptr C2, shared_ptr root, Eliminate function);
}; // \struct Clique
@@ -262,20 +264,24 @@ namespace gtsam {
CliqueData getCliqueData() const;
/** return marginal on any variable */
- typename CONDITIONAL::FactorType::shared_ptr marginalFactor(Index key) const;
+ typename CONDITIONAL::FactorType::shared_ptr marginalFactor(Index key,
+ Eliminate function) const;
/**
* return marginal on any variable, as a Bayes Net
* NOTE: this function calls marginal, and then eliminates it into a Bayes Net
* This is more expensive than the above function
*/
- typename BayesNet::shared_ptr marginalBayesNet(Index key) const;
+ typename BayesNet::shared_ptr marginalBayesNet(Index key,
+ Eliminate function) const;
/** return joint on two variables */
- typename FactorGraph::shared_ptr joint(Index key1, Index key2) const;
+ typename FactorGraph::shared_ptr joint(Index key1, Index key2,
+ Eliminate function) const;
/** return joint on two variables as a BayesNet */
- typename BayesNet::shared_ptr jointBayesNet(Index key1, Index key2) const;
+ typename BayesNet::shared_ptr jointBayesNet(Index key1,
+ Index key2, Eliminate function) const;
/**
* Read only with side effects
diff --git a/gtsam/inference/Conditional.h b/gtsam/inference/Conditional.h
index 4083d4105..85742388f 100644
--- a/gtsam/inference/Conditional.h
+++ b/gtsam/inference/Conditional.h
@@ -24,10 +24,8 @@
#include
#include
#include
-#include
#include
#include
-#include
namespace gtsam {
@@ -168,18 +166,6 @@ public:
/** print */
void print(const std::string& s = "Conditional") const;
- /** Permute the variables when only separator variables need to be permuted.
- * Returns true if any reordered variables appeared in the separator and
- * false if not.
- */
- bool permuteSeparatorWithInverse(const Permutation& inversePermutation);
-
- /**
- * Permutes the Conditional, but for efficiency requires the permutation
- * to already be inverted.
- */
- void permuteWithInverse(const Permutation& inversePermutation);
-
private:
/** Serialization function */
friend class boost::serialization::access;
@@ -200,37 +186,4 @@ void Conditional::print(const std::string& s) const {
std::cout << ")" << std::endl;
}
-/* ************************************************************************* */
-template
-bool Conditional::permuteSeparatorWithInverse(const Permutation& inversePermutation) {
-#ifndef NDEBUG
- BOOST_FOREACH(Key key, frontals()) { assert(key == inversePermutation[key]); }
-#endif
- bool parentChanged = false;
- BOOST_FOREACH(Key& parent, parents()) {
- Key newParent = inversePermutation[parent];
- if(parent != newParent) {
- parentChanged = true;
- parent = newParent;
- }
- }
- assertInvariants();
- return parentChanged;
-}
-
-/* ************************************************************************* */
-template
-void Conditional::permuteWithInverse(const Permutation& inversePermutation) {
- // The permutation may not move the separators into the frontals
-#ifndef NDEBUG
- BOOST_FOREACH(const Key frontal, this->frontals()) {
- BOOST_FOREACH(const Key separator, this->parents()) {
- assert(inversePermutation[frontal] < inversePermutation[separator]);
- }
- }
-#endif
- FactorType::permuteWithInverse(inversePermutation);
- assertInvariants();
-}
-
-}
+} // gtsam
diff --git a/gtsam/inference/EliminationTree-inl.h b/gtsam/inference/EliminationTree-inl.h
index a4b0b9294..e077bf8fe 100644
--- a/gtsam/inference/EliminationTree-inl.h
+++ b/gtsam/inference/EliminationTree-inl.h
@@ -27,8 +27,8 @@ namespace gtsam {
/* ************************************************************************* */
template
-typename EliminationTree::sharedFactor
-EliminationTree::eliminate_(Conditionals& conditionals) const {
+typename EliminationTree::sharedFactor EliminationTree::eliminate_(
+ Eliminate function, Conditionals& conditionals) const {
static const bool debug = false;
@@ -43,11 +43,11 @@ EliminationTree::eliminate_(Conditionals& conditionals) const {
// for all subtrees, eliminate into Bayes net and a separator factor, added to [factors]
BOOST_FOREACH(const shared_ptr& child, subTrees_) {
- factors.push_back(child->eliminate_(conditionals)); }
+ factors.push_back(child->eliminate_(function, conditionals)); }
// Combine all factors (from this node and from subtrees) into a joint factor
- pair eliminated(
- FACTOR::CombineAndEliminate(factors, 1));
+ pair
+ eliminated(function(factors, 1));
conditionals[this->key_] = eliminated.first->front();
if(debug) cout << "Eliminated " << this->key_ << " to get:\n";
@@ -57,39 +57,6 @@ EliminationTree::eliminate_(Conditionals& conditionals) const {
return eliminated.second;
}
-/* ************************************************************************* */
-// This is the explicit specialization for symbolic factors, i.e. IndexFactor
-template<> inline FastSet EliminationTree::eliminateSymbolic_(Conditionals& conditionals) const {
-
- static const bool debug = false;
-
- if(debug) cout << "ETree: eliminating " << this->key_ << endl;
-
- FastSet variables;
- BOOST_FOREACH(const sharedFactor& factor, factors_) {
- variables.insert(factor->begin(), factor->end());
- }
- BOOST_FOREACH(const shared_ptr& child, subTrees_) {
- sharedFactor factor(child->eliminate_(conditionals));
- variables.insert(factor->begin(), factor->end());
- }
- conditionals[this->key_] = IndexConditional::FromRange(variables.begin(), variables.end(), 1);
- variables.erase(variables.begin());
-
- if(debug) cout << "Eliminated " << this->key_ << " to get:\n";
- if(debug) conditionals[this->key_]->print("Conditional: ");
-
- return variables;
-}
-
-/* ************************************************************************* */
-// This non-specialized version cannot be called.
-template FastSet
-EliminationTree::eliminateSymbolic_(Conditionals& conditionals) const {
- throw invalid_argument("symbolic eliminate should never be called from a non-IndexFactor EliminationTree");
- return FastSet();
-}
-
/* ************************************************************************* */
template
vector EliminationTree::ComputeParents(const VariableIndex& structure) {
@@ -126,8 +93,9 @@ vector EliminationTree::ComputeParents(const VariableIndex& struc
/* ************************************************************************* */
template
template
-typename EliminationTree::shared_ptr
-EliminationTree::Create(const FactorGraph& factorGraph, const VariableIndex& structure) {
+typename EliminationTree::shared_ptr EliminationTree::Create(
+ const FactorGraph& factorGraph,
+ const VariableIndex& structure) {
static const bool debug = false;
@@ -218,12 +186,12 @@ bool EliminationTree::equals(const EliminationTree& ex
/* ************************************************************************* */
template
typename EliminationTree::BayesNet::shared_ptr
-EliminationTree::eliminate() const {
+EliminationTree::eliminate(Eliminate function) const {
// call recursive routine
tic(1, "ET recursive eliminate");
Conditionals conditionals(this->key_ + 1);
- (void)eliminate_(conditionals);
+ (void)eliminate_(function, conditionals);
toc(1, "ET recursive eliminate");
// Add conditionals to BayesNet
@@ -238,28 +206,4 @@ EliminationTree::eliminate() const {
return bayesNet;
}
-/* ************************************************************************* */
-// Specialization for symbolic elimination that calls the optimized eliminateSymbolic_
-template<>
-inline EliminationTree::BayesNet::shared_ptr
-EliminationTree::eliminate() const {
-
- // call recursive routine
- tic(1, "ET recursive eliminate");
- Conditionals conditionals(this->key_ + 1);
- (void)eliminateSymbolic_(conditionals);
- toc(1, "ET recursive eliminate");
-
- // Add conditionals to BayesNet
- tic(2, "assemble BayesNet");
- BayesNet::shared_ptr bayesNet(new BayesNet);
- BOOST_FOREACH(const BayesNet::sharedConditional& conditional, conditionals) {
- if(conditional)
- bayesNet->push_back(conditional);
- }
- toc(2, "assemble BayesNet");
-
- return bayesNet;
-}
-
}
diff --git a/gtsam/inference/EliminationTree.h b/gtsam/inference/EliminationTree.h
index e56da35ce..b2f97c616 100644
--- a/gtsam/inference/EliminationTree.h
+++ b/gtsam/inference/EliminationTree.h
@@ -42,6 +42,9 @@ public:
typedef boost::shared_ptr > shared_ptr;
typedef gtsam::BayesNet BayesNet;
+ /** typedef for an eliminate subroutine */
+ typedef typename FactorGraph::Eliminate Eliminate;
+
private:
typedef FastList Factors;
@@ -70,13 +73,7 @@ private:
/**
* Recursive routine that eliminates the factors arranged in an elimination tree
*/
- sharedFactor eliminate_(Conditionals& conditionals) const;
-
- /**
- * Special optimized eliminate for symbolic factors. Will not compile if
- * called in a non-IndexFactor EliminationTree.
- */
- FastSet eliminateSymbolic_(Conditionals& conditionals) const;
+ sharedFactor eliminate_(Eliminate function, Conditionals& conditionals) const;
// Allow access to constructor and add methods for testing purposes
friend class ::EliminationTreeTester;
@@ -101,7 +98,7 @@ public:
bool equals(const EliminationTree& other, double tol = 1e-9) const;
/** Eliminate the factors to a Bayes Net */
- typename BayesNet::shared_ptr eliminate() const;
+ typename BayesNet::shared_ptr eliminate(Eliminate function) const;
};
}
diff --git a/gtsam/inference/Factor-inl.h b/gtsam/inference/Factor-inl.h
index 68e45f157..543e738e1 100644
--- a/gtsam/inference/Factor-inl.h
+++ b/gtsam/inference/Factor-inl.h
@@ -18,99 +18,81 @@
#pragma once
-#include
-
+#include
#include
#include
-#include
-#include
-#include
-#include
+#include
namespace gtsam {
-/* ************************************************************************* */
-template
-Factor::Factor(const Factor& f) : keys_(f.keys_) { assertInvariants(); }
+ /* ************************************************************************* */
+ template
+ Factor::Factor(const Factor& f) :
+ keys_(f.keys_) {
+ assertInvariants();
+ }
-/* ************************************************************************* */
-template
-Factor::Factor(const ConditionalType& c) : keys_(c.keys()) { assertInvariants(); }
+ /* ************************************************************************* */
+ template
+ Factor::Factor(const ConditionalType& c) :
+ keys_(c.keys()) {
+ assertInvariants();
+ }
-/* ************************************************************************* */
-template
-void Factor::assertInvariants() const {
+ /* ************************************************************************* */
+ template
+ void Factor::assertInvariants() const {
#ifndef NDEBUG
- // Check that keys are all unique
- std::multiset nonunique(keys_.begin(), keys_.end());
- std::set unique(keys_.begin(), keys_.end());
- assert(nonunique.size() == unique.size() && std::equal(nonunique.begin(), nonunique.end(), unique.begin()));
+ // Check that keys are all unique
+ std::multiset nonunique(keys_.begin(), keys_.end());
+ std::set unique(keys_.begin(), keys_.end());
+ assert(nonunique.size() == unique.size() && std::equal(nonunique.begin(), nonunique.end(), unique.begin()));
#endif
-}
+ }
-/* ************************************************************************* */
-template
-void Factor::print(const std::string& s) const {
- std::cout << s << " ";
- BOOST_FOREACH(KEY key, keys_) std::cout << " " << key;
- std::cout << std::endl;
-}
+ /* ************************************************************************* */
+ template
+ void Factor::print(const std::string& s) const {
+ std::cout << s << " ";
+ BOOST_FOREACH(KEY key, keys_)
+ std::cout << " " << key;
+ std::cout << std::endl;
+ }
-/* ************************************************************************* */
-template
-bool Factor::equals(const This& other, double tol) const {
- return keys_ == other.keys_;
-}
+ /* ************************************************************************* */
+ template
+ bool Factor::equals(const This& other, double tol) const {
+ return keys_ == other.keys_;
+ }
-/* ************************************************************************* */
-template
-template
-typename DERIVED::shared_ptr Factor::Combine(const FactorGraph& factors, const FastMap >& variableSlots) {
- typedef const FastMap > VariableSlots;
- typedef typeof(boost::lambda::bind(&VariableSlots::value_type::first, boost::lambda::_1)) FirstGetter;
- typedef boost::transform_iterator<
- FirstGetter, typename VariableSlots::const_iterator,
- KEY, KEY> IndexIterator;
- FirstGetter firstGetter(boost::lambda::bind(&VariableSlots::value_type::first, boost::lambda::_1));
- IndexIterator keysBegin(variableSlots.begin(), firstGetter);
- IndexIterator keysEnd(variableSlots.end(), firstGetter);
- return typename DERIVED::shared_ptr(new DERIVED(keysBegin, keysEnd));
-}
+ /* ************************************************************************* */
+#ifdef TRACK_ELIMINATE
+ template
+ template
+ typename COND::shared_ptr Factor::eliminateFirst() {
+ assert(!keys_.empty());
+ assertInvariants();
+ KEY eliminated = keys_.front();
+ keys_.erase(keys_.begin());
+ assertInvariants();
+ return typename COND::shared_ptr(new COND(eliminated, keys_));
+ }
-/* ************************************************************************* */
-template
-template
-typename CONDITIONAL::shared_ptr Factor::eliminateFirst() {
- assert(!keys_.empty());
- assertInvariants();
- KEY eliminated = keys_.front();
- keys_.erase(keys_.begin());
- assertInvariants();
- return typename CONDITIONAL::shared_ptr(new CONDITIONAL(eliminated, keys_));
-}
-
-/* ************************************************************************* */
-template
-template
-typename BayesNet::shared_ptr Factor::eliminate(size_t nrFrontals) {
- assert(keys_.size() >= nrFrontals);
- assertInvariants();
- typename BayesNet::shared_ptr fragment(new BayesNet());
- const_iterator nextFrontal = this->begin();
- for(KEY n = 0; n < nrFrontals; ++n, ++nextFrontal)
- fragment->push_back(CONDITIONAL::FromRange(
- nextFrontal, const_iterator(this->end()), 1));
- if(nrFrontals > 0)
- keys_.assign(fragment->back()->beginParents(), fragment->back()->endParents());
- assertInvariants();
- return fragment;
-}
-
-/* ************************************************************************* */
-template
-void Factor::permuteWithInverse(const Permutation& inversePermutation) {
- BOOST_FOREACH(KEY& key, keys_) { key = inversePermutation[key]; }
- assertInvariants();
-}
+ /* ************************************************************************* */
+ template
+ template
+ typename BayesNet::shared_ptr Factor::eliminate(size_t nrFrontals) {
+ assert(keys_.size() >= nrFrontals);
+ assertInvariants();
+ typename BayesNet::shared_ptr fragment(new BayesNet ());
+ const_iterator it = this->begin();
+ for (KEY n = 0; n < nrFrontals; ++n, ++it)
+ fragment->push_back(COND::FromRange(it, const_iterator(this->end()), 1));
+ if (nrFrontals > 0) keys_.assign(fragment->back()->beginParents(),
+ fragment->back()->endParents());
+ assertInvariants();
+ return fragment;
+ }
+#endif
}
diff --git a/gtsam/inference/Factor.h b/gtsam/inference/Factor.h
index b484b801a..ea394ca9d 100644
--- a/gtsam/inference/Factor.h
+++ b/gtsam/inference/Factor.h
@@ -21,15 +21,14 @@
#pragma once
-#include
#include