Made all Bayesnets derive from BayesNet
parent
2fda2a1c00
commit
a07f1497c7
|
@ -31,11 +31,12 @@
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/** A Bayes net made from discrete conditional distributions. */
|
/**
|
||||||
class GTSAM_EXPORT DiscreteBayesNet: public BayesNet<DiscreteConditional>
|
* A Bayes net made from discrete conditional distributions.
|
||||||
{
|
* @addtogroup discrete
|
||||||
public:
|
*/
|
||||||
|
class GTSAM_EXPORT DiscreteBayesNet: public BayesNet<DiscreteConditional> {
|
||||||
|
public:
|
||||||
typedef BayesNet<DiscreteConditional> Base;
|
typedef BayesNet<DiscreteConditional> Base;
|
||||||
typedef DiscreteBayesNet This;
|
typedef DiscreteBayesNet This;
|
||||||
typedef DiscreteConditional ConditionalType;
|
typedef DiscreteConditional ConditionalType;
|
||||||
|
@ -49,16 +50,20 @@ namespace gtsam {
|
||||||
DiscreteBayesNet() {}
|
DiscreteBayesNet() {}
|
||||||
|
|
||||||
/** Construct from iterator over conditionals */
|
/** Construct from iterator over conditionals */
|
||||||
template<typename ITERATOR>
|
template <typename ITERATOR>
|
||||||
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional) : Base(firstConditional, lastConditional) {}
|
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
|
||||||
|
: Base(firstConditional, lastConditional) {}
|
||||||
|
|
||||||
/** Construct from container of factors (shared_ptr or plain objects) */
|
/** Construct from container of factors (shared_ptr or plain objects) */
|
||||||
template<class CONTAINER>
|
template <class CONTAINER>
|
||||||
explicit DiscreteBayesNet(const CONTAINER& conditionals) : Base(conditionals) {}
|
explicit DiscreteBayesNet(const CONTAINER& conditionals)
|
||||||
|
: Base(conditionals) {}
|
||||||
|
|
||||||
/** Implicit copy/downcast constructor to override explicit template container constructor */
|
/** Implicit copy/downcast constructor to override explicit template
|
||||||
template<class DERIVEDCONDITIONAL>
|
* container constructor */
|
||||||
DiscreteBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph) : Base(graph) {}
|
template <class DERIVEDCONDITIONAL>
|
||||||
|
DiscreteBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph)
|
||||||
|
: Base(graph) {}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~DiscreteBayesNet() {}
|
virtual ~DiscreteBayesNet() {}
|
||||||
|
|
|
@ -150,12 +150,13 @@ TEST(DiscreteBayesNet, Dot) {
|
||||||
fragment.add((Either | Tuberculosis, LungCancer) = "F T T T");
|
fragment.add((Either | Tuberculosis, LungCancer) = "F T T T");
|
||||||
|
|
||||||
string actual = fragment.dot();
|
string actual = fragment.dot();
|
||||||
|
cout << actual << endl;
|
||||||
EXPECT(actual ==
|
EXPECT(actual ==
|
||||||
"digraph G{\n"
|
"digraph G{\n"
|
||||||
"0->3\n"
|
|
||||||
"4->6\n"
|
|
||||||
"3->5\n"
|
"3->5\n"
|
||||||
"6->5\n"
|
"6->5\n"
|
||||||
|
"4->6\n"
|
||||||
|
"0->3\n"
|
||||||
"}");
|
"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <boost/range/adaptor/reversed.hpp>
|
#include <boost/range/adaptor/reversed.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ void BayesNet<CONDITIONAL>::dot(std::ostream& os,
|
||||||
const KeyFormatter& keyFormatter) const {
|
const KeyFormatter& keyFormatter) const {
|
||||||
os << "digraph G{\n";
|
os << "digraph G{\n";
|
||||||
|
|
||||||
for (auto conditional : *this) {
|
for (auto conditional : boost::adaptors::reverse(*this)) {
|
||||||
auto frontals = conditional->frontals();
|
auto frontals = conditional->frontals();
|
||||||
const Key me = frontals.front();
|
const Key me = frontals.front();
|
||||||
auto parents = conditional->parents();
|
auto parents = conditional->parents();
|
||||||
|
|
|
@ -18,17 +18,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtsam/inference/FactorGraph.h>
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <gtsam/inference/FactorGraph.h>
|
#include <string>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A BayesNet is a tree of conditionals, stored in elimination order.
|
* A BayesNet is a tree of conditionals, stored in elimination order.
|
||||||
*
|
* @addtogroup inference
|
||||||
* todo: how to handle Bayes nets with an optimize function? Currently using global functions.
|
|
||||||
* \nosubgrouping
|
|
||||||
*/
|
*/
|
||||||
template<class CONDITIONAL>
|
template<class CONDITIONAL>
|
||||||
class BayesNet : public FactorGraph<CONDITIONAL> {
|
class BayesNet : public FactorGraph<CONDITIONAL> {
|
||||||
|
|
|
@ -21,17 +21,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtsam/linear/GaussianConditional.h>
|
#include <gtsam/linear/GaussianConditional.h>
|
||||||
|
#include <gtsam/inference/BayesNet.h>
|
||||||
#include <gtsam/inference/FactorGraph.h>
|
#include <gtsam/inference/FactorGraph.h>
|
||||||
#include <gtsam/global_includes.h>
|
#include <gtsam/global_includes.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/** A Bayes net made from linear-Gaussian densities */
|
/**
|
||||||
class GTSAM_EXPORT GaussianBayesNet: public FactorGraph<GaussianConditional>
|
* GaussianBayesNet is a Bayes net made from linear-Gaussian conditionals.
|
||||||
|
* @addtogroup linear
|
||||||
|
*/
|
||||||
|
class GTSAM_EXPORT GaussianBayesNet: public BayesNet<GaussianConditional>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef FactorGraph<GaussianConditional> Base;
|
typedef BayesNet<GaussianConditional> Base;
|
||||||
typedef GaussianBayesNet This;
|
typedef GaussianBayesNet This;
|
||||||
typedef GaussianConditional ConditionalType;
|
typedef GaussianConditional ConditionalType;
|
||||||
typedef boost::shared_ptr<This> shared_ptr;
|
typedef boost::shared_ptr<This> shared_ptr;
|
||||||
|
@ -44,16 +48,21 @@ namespace gtsam {
|
||||||
GaussianBayesNet() {}
|
GaussianBayesNet() {}
|
||||||
|
|
||||||
/** Construct from iterator over conditionals */
|
/** Construct from iterator over conditionals */
|
||||||
template<typename ITERATOR>
|
template <typename ITERATOR>
|
||||||
GaussianBayesNet(ITERATOR firstConditional, ITERATOR lastConditional) : Base(firstConditional, lastConditional) {}
|
GaussianBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
|
||||||
|
: Base(firstConditional, lastConditional) {}
|
||||||
|
|
||||||
/** Construct from container of factors (shared_ptr or plain objects) */
|
/** Construct from container of factors (shared_ptr or plain objects) */
|
||||||
template<class CONTAINER>
|
template <class CONTAINER>
|
||||||
explicit GaussianBayesNet(const CONTAINER& conditionals) : Base(conditionals) {}
|
explicit GaussianBayesNet(const CONTAINER& conditionals) {
|
||||||
|
push_back(conditionals);
|
||||||
|
}
|
||||||
|
|
||||||
/** Implicit copy/downcast constructor to override explicit template container constructor */
|
/** Implicit copy/downcast constructor to override explicit template
|
||||||
template<class DERIVEDCONDITIONAL>
|
* container constructor */
|
||||||
GaussianBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph) : Base(graph) {}
|
template <class DERIVEDCONDITIONAL>
|
||||||
|
explicit GaussianBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph)
|
||||||
|
: Base(graph) {}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~GaussianBayesNet() {}
|
virtual ~GaussianBayesNet() {}
|
||||||
|
|
|
@ -19,19 +19,19 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtsam/symbolic/SymbolicConditional.h>
|
#include <gtsam/symbolic/SymbolicConditional.h>
|
||||||
|
#include <gtsam/inference/BayesNet.h>
|
||||||
#include <gtsam/inference/FactorGraph.h>
|
#include <gtsam/inference/FactorGraph.h>
|
||||||
#include <gtsam/base/types.h>
|
#include <gtsam/base/types.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/** Symbolic Bayes Net
|
/**
|
||||||
* \nosubgrouping
|
* A SymbolicBayesNet is a Bayes Net of purely symbolic conditionals.
|
||||||
|
* @addtogroup symbolic
|
||||||
*/
|
*/
|
||||||
class SymbolicBayesNet : public FactorGraph<SymbolicConditional> {
|
class SymbolicBayesNet : public BayesNet<SymbolicConditional> {
|
||||||
|
public:
|
||||||
public:
|
typedef BayesNet<SymbolicConditional> Base;
|
||||||
|
|
||||||
typedef FactorGraph<SymbolicConditional> Base;
|
|
||||||
typedef SymbolicBayesNet This;
|
typedef SymbolicBayesNet This;
|
||||||
typedef SymbolicConditional ConditionalType;
|
typedef SymbolicConditional ConditionalType;
|
||||||
typedef boost::shared_ptr<This> shared_ptr;
|
typedef boost::shared_ptr<This> shared_ptr;
|
||||||
|
@ -44,16 +44,21 @@ namespace gtsam {
|
||||||
SymbolicBayesNet() {}
|
SymbolicBayesNet() {}
|
||||||
|
|
||||||
/** Construct from iterator over conditionals */
|
/** Construct from iterator over conditionals */
|
||||||
template<typename ITERATOR>
|
template <typename ITERATOR>
|
||||||
SymbolicBayesNet(ITERATOR firstConditional, ITERATOR lastConditional) : Base(firstConditional, lastConditional) {}
|
SymbolicBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
|
||||||
|
: Base(firstConditional, lastConditional) {}
|
||||||
|
|
||||||
/** Construct from container of factors (shared_ptr or plain objects) */
|
/** Construct from container of factors (shared_ptr or plain objects) */
|
||||||
template<class CONTAINER>
|
template <class CONTAINER>
|
||||||
explicit SymbolicBayesNet(const CONTAINER& conditionals) : Base(conditionals) {}
|
explicit SymbolicBayesNet(const CONTAINER& conditionals) {
|
||||||
|
push_back(conditionals);
|
||||||
|
}
|
||||||
|
|
||||||
/** Implicit copy/downcast constructor to override explicit template container constructor */
|
/** Implicit copy/downcast constructor to override explicit template
|
||||||
template<class DERIVEDCONDITIONAL>
|
* container constructor */
|
||||||
SymbolicBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph) : Base(graph) {}
|
template <class DERIVEDCONDITIONAL>
|
||||||
|
explicit SymbolicBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph)
|
||||||
|
: Base(graph) {}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~SymbolicBayesNet() {}
|
virtual ~SymbolicBayesNet() {}
|
||||||
|
|
Loading…
Reference in New Issue