Prototype framework for Bayes chain (new name for Chordal Bayes net) and Bayes tree class hierarchy

release/4.3a0
Frank Dellaert 2009-10-27 20:23:19 +00:00
parent 94da98411c
commit bb15697cf9
9 changed files with 274 additions and 20 deletions

View File

@ -300,7 +300,6 @@
<buildTargets>
<target name="install" path="wrap" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>install</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -308,7 +307,6 @@
</target>
<target name="check" path="wrap" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>check</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -316,6 +314,7 @@
</target>
<target name="check" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>check</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -323,7 +322,6 @@
</target>
<target name="testSimpleCamera.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testSimpleCamera.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -339,6 +337,7 @@
</target>
<target name="testVSLAMFactor.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testVSLAMFactor.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -346,7 +345,6 @@
</target>
<target name="testCalibratedCamera.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testCalibratedCamera.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -354,6 +352,7 @@
</target>
<target name="testConditionalGaussian.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testConditionalGaussian.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -361,7 +360,6 @@
</target>
<target name="testPose2.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testPose2.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -377,7 +375,6 @@
</target>
<target name="testRot3.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testRot3.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -385,6 +382,7 @@
</target>
<target name="testNonlinearOptimizer.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testNonlinearOptimizer.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -392,7 +390,6 @@
</target>
<target name="testLinearFactor.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testLinearFactor.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -400,7 +397,6 @@
</target>
<target name="testConstrainedNonlinearFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testConstrainedNonlinearFactorGraph.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -408,7 +404,6 @@
</target>
<target name="testLinearFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testLinearFactorGraph.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -416,6 +411,7 @@
</target>
<target name="testNonlinearFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testNonlinearFactorGraph.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -423,7 +419,6 @@
</target>
<target name="testPose3.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testPose3.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -431,6 +426,7 @@
</target>
<target name="testConstrainedLinearFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testConstrainedLinearFactorGraph.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -438,6 +434,7 @@
</target>
<target name="testVectorConfig.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testVectorConfig.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -445,6 +442,7 @@
</target>
<target name="testPoint2.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testPoint2.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -452,7 +450,6 @@
</target>
<target name="testNonlinearFactor.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testNonlinearFactor.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -460,7 +457,6 @@
</target>
<target name="timeLinearFactor.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>timeLinearFactor.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -468,7 +464,6 @@
</target>
<target name="timeLinearFactorGraph.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>timeLinearFactorGraph.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -476,14 +471,30 @@
</target>
<target name="testChordalBayesNet.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testChordalBayesNet.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="testBayesTree.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testBayesTree.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="testSymbolicBayesChain.run" path="cpp" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>testSymbolicBayesChain.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="install" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>install</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -491,6 +502,7 @@
</target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
@ -498,6 +510,7 @@
</target>
<target name="check" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>check</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>

28
cpp/BayesChain.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @file BayesChain
* @brief Bayes Chain, the result of eliminating a factor graph
* @author Frank Dellaert
*/
// \callgraph
#pragma once
#include <list>
#include <boost/serialization/map.hpp>
#include <boost/serialization/list.hpp>
namespace gtsam {
/**
* Bayes Chain, the result of eliminating a factor graph
* This is the base class for SymbolicBayesChain, DiscreteBayesChain, and GaussianBayesChain
* Corresponding to what is used for the "Conditional" template argument:
* a ConditionalProbabilityTable, a ConditionalGaussian, or a SymbolicConditional.
*/
template<class Conditional>
class BayesChain {
public:
};
} /// namespace gtsam

44
cpp/BayesTree.h Normal file
View File

@ -0,0 +1,44 @@
/**
* @file BayesTree
* @brief Bayes Tree is a tree of cliques of a Bayes Chain
* @author Frank Dellaert
*/
// \callgraph
#pragma once
#include <list>
#include <boost/serialization/map.hpp>
#include <boost/serialization/list.hpp>
#include "Testable.h"
#include "BayesChain.h"
namespace gtsam {
/**
* Bayes tree
* Templated on the Conditional class, the type of node in the underlying Bayes chain.
* This could be a ConditionalProbabilityTable, a ConditionalGaussian, or a SymbolicConditional
*/
template <class Conditional>
class BayesTree : public Testable<BayesTree<Conditional> >
{
public:
/** Create a Bayes Tree from a SymbolicBayesChain */
BayesTree(BayesChain<Conditional>& bayesChain) {}
/** Destructor */
virtual ~BayesTree() {}
/** print */
void print(const std::string& s = "") const {}
/** check equality */
bool equals(const BayesTree<Conditional>& other, double tol = 1e-9) const { return false; }
}; // BayesTree
} /// namespace gtsam

View File

@ -86,25 +86,29 @@ timeLinearFactorGraph: CXXFLAGS += -I /opt/local/include -I ..
timeLinearFactorGraph: LDFLAGS += SmallExample.o -L.libs -lgtsam -L../CppUnitLite -lCppUnitLite
# graphs
sources += ChordalBayesNet.cpp
sources += LinearFactorGraph.cpp
sources += SymbolicBayesChain.cpp ChordalBayesNet.cpp
sources += ConstrainedNonlinearFactorGraph.cpp ConstrainedLinearFactorGraph.cpp
check_PROGRAMS += testChordalBayesNet testFactorgraph
check_PROGRAMS += testLinearFactorGraph testNonlinearFactorGraph testNonlinearOptimizer
check_PROGRAMS += testFactorgraph testLinearFactorGraph testNonlinearFactorGraph testNonlinearOptimizer
check_PROGRAMS += testSymbolicBayesChain testChordalBayesNet testBayesTree
check_PROGRAMS += testConstrainedNonlinearFactorGraph testConstrainedLinearFactorGraph
testChordalBayesNet_SOURCES = $(example) testChordalBayesNet.cpp
testFactorgraph_SOURCES = testFactorgraph.cpp
testLinearFactorGraph_SOURCES = $(example) testLinearFactorGraph.cpp
testNonlinearFactorGraph_SOURCES = $(example) testNonlinearFactorGraph.cpp
testNonlinearOptimizer_SOURCES = $(example) testNonlinearOptimizer.cpp
testNonlinearOptimizer_SOURCES = $(example) testNonlinearOptimizer.cpp
testSymbolicBayesChain_SOURCES = $(example) testSymbolicBayesChain.cpp
testChordalBayesNet_SOURCES = $(example) testChordalBayesNet.cpp
testBayesTree_SOURCES = $(example) testBayesTree.cpp
testConstrainedNonlinearFactorGraph_SOURCES = $(example) testConstrainedNonlinearFactorGraph.cpp
testConstrainedLinearFactorGraph_SOURCES = $(example) testConstrainedLinearFactorGraph.cpp
testChordalBayesNet_LDADD = libgtsam.la
testFactorgraph_LDADD = libgtsam.la
testLinearFactorGraph_LDADD = libgtsam.la
testNonlinearFactorGraph_LDADD = libgtsam.la
testNonlinearOptimizer_LDADD = libgtsam.la
testSymbolicBayesChain_LDADD = libgtsam.la
testChordalBayesNet_LDADD = libgtsam.la
testBayesTree_LDADD = libgtsam.la
testConstrainedNonlinearFactorGraph_LDADD = libgtsam.la
testConstrainedLinearFactorGraph_LDADD = libgtsam.la

View File

@ -0,0 +1,17 @@
/**
* @file SymbolicBayesChain-inl.h
* @brief Template definitions for SymbolicBayesChain
* @author Frank Dellaert
*/
#include "SymbolicBayesChain.h"
using namespace std;
using namespace gtsam;
/* ************************************************************************* */
template<class Factor, class Config>
SymbolicBayesChain::SymbolicBayesChain(const FactorGraph<Factor,Config>& factorGraph) {
}
/* ************************************************************************* */

View File

@ -0,0 +1,43 @@
/**
* @file SymbolicBayesChain.cpp
* @brief Chordal Bayes Net, the result of eliminating a factor graph
* @author Frank Dellaert
*/
#include <stdarg.h>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp>
#include "SymbolicBayesChain.h"
using namespace std;
using namespace gtsam;
// trick from some reading group
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
/* ************************************************************************* */
void SymbolicBayesChain::print(const string& s) const {
// BOOST_FOREACH(string key, keys) {
// const_iterator it = nodes.find(key);
// it->second->print("\nNode[" + key + "]");
// }
}
/* ************************************************************************* */
bool SymbolicBayesChain::equals(const SymbolicBayesChain& cbn, double tol) const {
// const_iterator it1 = nodes.begin(), it2 = cbn.nodes.begin();
//
// if(nodes.size() != cbn.nodes.size()) return false;
// for(; it1 != nodes.end(); it1++, it2++){
// const string& j1 = it1->first, j2 = it2->first;
// ConditionalGaussian::shared_ptr node1 = it1->second, node2 = it2->second;
// if (j1 != j2) return false;
// if (!node1->equals(*node2,tol))
// return false;
// }
// return true;
return false;
}
/* ************************************************************************* */

51
cpp/SymbolicBayesChain.h Normal file
View File

@ -0,0 +1,51 @@
/**
* @file SymbolicBayesChain.h
* @brief Symbolic Chordal Bayes Net, the result of eliminating a factor graph
* @author Frank Dellaert
*/
// \callgraph
#pragma once
#include <list>
#include <boost/serialization/map.hpp>
#include <boost/serialization/list.hpp>
#include "Testable.h"
#include "BayesChain.h"
#include "FactorGraph.h"
namespace gtsam {
/**
* Conditional node for use in a symbolic Bayes chain
*/
class SymbolicConditional {
};
/**
* Symbolic Bayes Chain, the (symbolic) result of eliminating a factor graph
*/
class SymbolicBayesChain: public BayesChain<SymbolicConditional> ,
public Testable<SymbolicBayesChain> {
public:
/**
* Construct from any factor graph
*/
template<class Factor, class Config>
SymbolicBayesChain(const FactorGraph<Factor, Config>& factorGraph);
/** Destructor */
virtual ~SymbolicBayesChain() {
}
/** print */
void print(const std::string& s = "") const;
/** check equality */
bool equals(const SymbolicBayesChain& other, double tol = 1e-9) const;
};
} /// namespace gtsam

28
cpp/testBayesTree.cpp Normal file
View File

@ -0,0 +1,28 @@
/**
* @file testBayesTree.cpp
* @brief Unit tests for Bayes Tree
* @author Frank Dellaert
*/
#include <CppUnitLite/TestHarness.h>
#include "SymbolicBayesChain-inl.h"
#include "smallExample.h"
#include "BayesTree.h"
using namespace gtsam;
/* ************************************************************************* */
TEST( BayesTree, constructor )
{
LinearFactorGraph factorGraph = createLinearFactorGraph();
SymbolicBayesChain symbolicBayesChain(factorGraph);
BayesTree<SymbolicConditional> bayesTree(symbolicBayesChain);
}
/* ************************************************************************* */
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */

View File

@ -0,0 +1,26 @@
/**
* @file testSymbolicBayesChain.cpp
* @brief Unit tests for a symbolic Bayes chain
* @author Frank Dellaert
*/
#include <CppUnitLite/TestHarness.h>
#include "smallExample.h"
#include "SymbolicBayesChain-inl.h"
using namespace gtsam;
/* ************************************************************************* */
TEST( SymbolicBayesChain, constructor )
{
LinearFactorGraph factorGraph = createLinearFactorGraph();
SymbolicBayesChain symbolicChordalBayesNet(factorGraph);
}
/* ************************************************************************* */
int main() {
TestResult tr;
return TestRegistry::runAllTests(tr);
}
/* ************************************************************************* */