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