diff --git a/.cproject b/.cproject
index df6fdc5f5..69a891199 100644
--- a/.cproject
+++ b/.cproject
@@ -309,6 +309,14 @@
true
true
+
+ make
+ -j2
+ testGaussianFactor.run
+ true
+ true
+ true
+
make
-j2
@@ -335,7 +343,6 @@
make
-
tests/testBayesTree.run
true
false
@@ -343,7 +350,6 @@
make
-
testBinaryBayesNet.run
true
false
@@ -391,7 +397,6 @@
make
-
testSymbolicBayesNet.run
true
false
@@ -399,7 +404,6 @@
make
-
tests/testSymbolicFactor.run
true
false
@@ -407,7 +411,6 @@
make
-
testSymbolicFactorGraph.run
true
false
@@ -423,20 +426,11 @@
make
-
tests/testBayesTree
true
false
true
-
- make
- -j2
- testGaussianFactor.run
- true
- true
- true
-
make
-j5
@@ -525,22 +519,6 @@
false
true
-
- make
- -j2
- tests/testPose2.run
- true
- true
- true
-
-
- make
- -j2
- tests/testPose3.run
- true
- true
- true
-
make
-j2
@@ -557,6 +535,22 @@
true
true
+
+ make
+ -j2
+ tests/testPose2.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ tests/testPose3.run
+ true
+ true
+ true
+
make
-j2
@@ -581,26 +575,26 @@
true
true
-
+
make
- -j2
- all
+ -j5
+ testValues.run
true
true
true
-
+
make
- -j2
- check
+ -j5
+ testOrdering.run
true
true
true
-
+
make
- -j2
- clean
+ -j5
+ testKey.run
true
true
true
@@ -685,26 +679,26 @@
true
true
-
+
make
- -j5
- testValues.run
+ -j2
+ all
true
true
true
-
+
make
- -j5
- testOrdering.run
+ -j2
+ check
true
true
true
-
+
make
- -j5
- testKey.run
+ -j2
+ clean
true
true
true
@@ -813,6 +807,30 @@
true
true
+
+ make
+ -j5
+ testDiscreteBayesTree.run
+ true
+ true
+ true
+
+
+ make
+ -j5
+ testDiscreteFactorGraph.run
+ true
+ true
+ true
+
+
+ make
+ -j5
+ testDiscreteConditional.run
+ true
+ true
+ true
+
make
-j5
@@ -991,7 +1009,6 @@
make
-
testGraph.run
true
false
@@ -999,7 +1016,6 @@
make
-
testJunctionTree.run
true
false
@@ -1007,7 +1023,6 @@
make
-
testSymbolicBayesNetB.run
true
false
@@ -1167,7 +1182,6 @@
make
-
testErrors.run
true
false
@@ -1213,10 +1227,10 @@
true
true
-
+
make
- -j5
- testLinearContainerFactor.run
+ -j2
+ testGaussianFactor.run
true
true
true
@@ -1301,10 +1315,10 @@
true
true
-
+
make
- -j2
- testGaussianFactor.run
+ -j5
+ testLinearContainerFactor.run
true
true
true
@@ -1639,6 +1653,7 @@
make
+
testSimulated2DOriented.run
true
false
@@ -1678,6 +1693,7 @@
make
+
testSimulated2D.run
true
false
@@ -1685,6 +1701,7 @@
make
+
testSimulated3D.run
true
false
@@ -1876,6 +1893,7 @@
make
+
tests/testGaussianISAM2
true
false
@@ -1897,9 +1915,105 @@
true
true
+
+ make
+ -j2
+ testRot3.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testRot2.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testPose3.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ timeRot3.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testPose2.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testCal3_S2.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testSimpleCamera.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testHomography2.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testCalibratedCamera.run
+ true
+ true
+ true
+
+
+ make
+ -j2
+ check
+ true
+ true
+ true
+
+
+ make
+ -j2
+ clean
+ true
+ true
+ true
+
+
+ make
+ -j2
+ testPoint2.run
+ true
+ true
+ true
+
make
- -j1
+ -j3
install
true
false
@@ -2098,7 +2212,6 @@
cpack
-
-G DEB
true
false
@@ -2106,7 +2219,6 @@
cpack
-
-G RPM
true
false
@@ -2114,7 +2226,6 @@
cpack
-
-G TGZ
true
false
@@ -2122,7 +2233,6 @@
cpack
-
--config CPackSourceConfig.cmake
true
false
@@ -2256,98 +2366,34 @@
true
true
-
+
make
- -j2
- testRot3.run
+ -j5
+ testSpirit.run
true
true
true
-
+
make
- -j2
- testRot2.run
+ -j5
+ testWrap.run
true
true
true
-
+
make
- -j2
- testPose3.run
+ -j5
+ check.wrap
true
true
true
-
+
make
- -j2
- timeRot3.run
- true
- true
- true
-
-
- make
- -j2
- testPose2.run
- true
- true
- true
-
-
- make
- -j2
- testCal3_S2.run
- true
- true
- true
-
-
- make
- -j2
- testSimpleCamera.run
- true
- true
- true
-
-
- make
- -j2
- testHomography2.run
- true
- true
- true
-
-
- make
- -j2
- testCalibratedCamera.run
- true
- true
- true
-
-
- make
- -j2
- check
- true
- true
- true
-
-
- make
- -j2
- clean
- true
- true
- true
-
-
- make
- -j2
- testPoint2.run
+ -j5
+ wrap
true
true
true
@@ -2391,38 +2437,6 @@
false
true
-
- make
- -j5
- testSpirit.run
- true
- true
- true
-
-
- make
- -j5
- testWrap.run
- true
- true
- true
-
-
- make
- -j5
- check.wrap
- true
- true
- true
-
-
- make
- -j5
- wrap
- true
- true
- true
-
diff --git a/gtsam/discrete/DiscreteConditional.h b/gtsam/discrete/DiscreteConditional.h
index 806f0f21d..4512ea7b0 100644
--- a/gtsam/discrete/DiscreteConditional.h
+++ b/gtsam/discrete/DiscreteConditional.h
@@ -144,13 +144,17 @@ namespace gtsam {
DiscreteConditional::shared_ptr DiscreteConditional::Combine(
ITERATOR firstConditional, ITERATOR lastConditional) {
// TODO: check for being a clique
+
+ // multiply all the potentials of the given conditionals
+ size_t nrFrontals = 0;
DecisionTreeFactor product;
- for(ITERATOR it = firstConditional; it != lastConditional; ++it) {
+ for(ITERATOR it = firstConditional; it != lastConditional; ++it, ++nrFrontals) {
DiscreteConditional::shared_ptr c = *it;
DecisionTreeFactor::shared_ptr factor = c->toFactor();
product = (*factor) * product;
}
- return boost::make_shared(1,product);
+ // and then create a new multi-frontal conditional
+ return boost::make_shared(nrFrontals,product);
}
}// gtsam
diff --git a/gtsam/discrete/tests/testDiscreteBayesTree.cpp b/gtsam/discrete/tests/testDiscreteBayesTree.cpp
new file mode 100644
index 000000000..c2bbcb55e
--- /dev/null
+++ b/gtsam/discrete/tests/testDiscreteBayesTree.cpp
@@ -0,0 +1,135 @@
+/* ----------------------------------------------------------------------------
+
+ * GTSAM Copyright 2010, Georgia Tech Research Corporation,
+ * Atlanta, Georgia 30332-0415
+ * All Rights Reserved
+ * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
+
+ * See LICENSE for the license information
+
+ * -------------------------------------------------------------------------- */
+
+/*
+ * @file testDiscreteBayesTree.cpp
+ * @date sept 15, 2012
+ * @author Frank Dellaert
+ */
+
+#include
+#include
+
+#include
+using namespace boost::assign;
+
+#include
+
+using namespace std;
+using namespace gtsam;
+
+static bool debug = false;
+
+/**
+ * Custom clique class to debug shortcuts
+ */
+class Clique: public BayesTreeCliqueBase {
+public:
+
+ typedef BayesTreeCliqueBase Base;
+
+ // Constructors
+ Clique() {
+ }
+ Clique(const DiscreteConditional::shared_ptr& conditional) :
+ Base(conditional) {
+ }
+ Clique(
+ const std::pair& result) :
+ Base(result) {
+ }
+
+ // evaluate value of sub-tree
+ double evaluate(const DiscreteConditional::Values & values) {
+ double result = (*(this->conditional_))(values);
+ // evaluate all children and multiply into result
+ BOOST_FOREACH(boost::shared_ptr c, children_)
+ result *= c->evaluate(values);
+ return result;
+ }
+};
+
+typedef BayesTree DiscreteBayesTree;
+
+/* ************************************************************************* */
+double evaluate(const DiscreteBayesTree& tree,
+ const DiscreteConditional::Values & values) {
+ return tree.root()->evaluate(values);
+}
+
+/* ************************************************************************* */
+
+TEST_UNSAFE( DiscreteMarginals, thinTree ) {
+
+ const int nrNodes = 15;
+ const size_t nrStates = 2;
+
+ // define variables
+ vector key;
+ for (int i = 0; i < nrNodes; i++) {
+ DiscreteKey key_i(i, nrStates);
+ key.push_back(key_i);
+ }
+
+ // create a thin-tree Bayesnet, a la Jean-Guillaume
+ DiscreteBayesNet bayesNet;
+ add_front(bayesNet, key[14] % "1/3");
+
+ add_front(bayesNet, key[13] | key[14] = "1/3 3/1");
+ add_front(bayesNet, key[12] | key[14] = "3/1 3/1");
+
+ add_front(bayesNet, (key[11] | key[13], key[14]) = "1/4 2/3 3/2 4/1");
+ add_front(bayesNet, (key[10] | key[13], key[14]) = "1/4 3/2 2/3 4/1");
+ add_front(bayesNet, (key[9] | key[12], key[14]) = "4/1 2/3 3/2 1/4");
+ add_front(bayesNet, (key[8] | key[12], key[14]) = "2/3 1/4 3/2 4/1");
+
+ add_front(bayesNet, (key[7] | key[11], key[13]) = "1/4 2/3 3/2 4/1");
+ add_front(bayesNet, (key[6] | key[11], key[13]) = "1/4 3/2 2/3 4/1");
+ add_front(bayesNet, (key[5] | key[10], key[13]) = "4/1 2/3 3/2 1/4");
+ add_front(bayesNet, (key[4] | key[10], key[13]) = "2/3 1/4 3/2 4/1");
+
+ add_front(bayesNet, (key[3] | key[9], key[12]) = "1/4 2/3 3/2 4/1");
+ add_front(bayesNet, (key[2] | key[9], key[12]) = "1/4 3/2 2/3 4/1");
+ add_front(bayesNet, (key[1] | key[8], key[12]) = "4/1 2/3 3/2 1/4");
+ add_front(bayesNet, (key[0] | key[8], key[12]) = "2/3 1/4 3/2 4/1");
+
+ if (debug) {
+ GTSAM_PRINT(bayesNet);
+ bayesNet.saveGraph("/tmp/discreteBayesNet.dot");
+ }
+
+ // create a BayesTree out of a Bayes net
+ DiscreteBayesTree bayesTree(bayesNet);
+ if (debug) {
+ GTSAM_PRINT(bayesTree);
+ bayesTree.saveGraph("/tmp/discreteBayesTree.dot");
+ }
+
+ // Check whether BN and BT give the same answer on all configurations
+ vector allPosbValues = cartesianProduct(
+ key[0] & key[1] & key[2] & key[3] & key[4] & key[5] & key[6] & key[7]
+ & key[8] & key[9] & key[10] & key[11] & key[12] & key[13] & key[14]);
+ for (size_t i = 0; i < allPosbValues.size(); ++i) {
+ DiscreteFactor::Values x = allPosbValues[i];
+ double expected = evaluate(bayesNet, x);
+ double actual = evaluate(bayesTree, x);
+ DOUBLES_EQUAL(expected, actual, 1e-9);
+ }
+}
+
+/* ************************************************************************* */
+int main() {
+ TestResult tr;
+ return TestRegistry::runAllTests(tr);
+}
+/* ************************************************************************* */
+
diff --git a/gtsam/discrete/tests/testDiscreteConditional.cpp b/gtsam/discrete/tests/testDiscreteConditional.cpp
index 04bc47f60..568f98db7 100644
--- a/gtsam/discrete/tests/testDiscreteConditional.cpp
+++ b/gtsam/discrete/tests/testDiscreteConditional.cpp
@@ -95,16 +95,16 @@ TEST( DiscreteConditional, constructors3)
}
/* ************************************************************************* */
-TEST( DiscreteConditional, Combine)
-{
- DiscreteKey A(0,2), B(1,2);
+TEST( DiscreteConditional, Combine) {
+ DiscreteKey A(0, 2), B(1, 2);
vector c;
c.push_back(boost::make_shared(A | B = "1/2 2/1"));
c.push_back(boost::make_shared(B % "1/2"));
- DiscreteConditional::shared_ptr actual = DiscreteConditional::Combine(c.begin(), c.end());
- DecisionTreeFactor::shared_ptr actualFactor = actual->toFactor();
- DecisionTreeFactor expected(A & B, "0.333333 0.666667 0.666667 0.333333");
- EXPECT(assert_equal(expected, *actualFactor,1e-5));
+ DecisionTreeFactor factor(A & B, "0.111111 0.444444 0.222222 0.222222");
+ DiscreteConditional expected(2, factor);
+ DiscreteConditional::shared_ptr actual = DiscreteConditional::Combine(
+ c.begin(), c.end());
+ EXPECT(assert_equal(expected, *actual,1e-5));
}
/* ************************************************************************* */
diff --git a/gtsam/inference/BayesTreeCliqueBase-inl.h b/gtsam/inference/BayesTreeCliqueBase-inl.h
index 344f845ac..7ca40345b 100644
--- a/gtsam/inference/BayesTreeCliqueBase-inl.h
+++ b/gtsam/inference/BayesTreeCliqueBase-inl.h
@@ -6,7 +6,6 @@
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
-
* -------------------------------------------------------------------------- */
/**