added printSignature and evaluate
parent
3f4bf163e7
commit
968b207135
|
@ -45,6 +45,16 @@ namespace gtsam {
|
||||||
return Base::equals(other, tol);
|
return Base::equals(other, tol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
double DiscreteBayesTree::evaluate(
|
||||||
|
const DiscreteConditional::Values& values) const {
|
||||||
|
double result = 1.0;
|
||||||
|
for (const auto& root : roots_) {
|
||||||
|
result *= root->evaluate(values);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
} // \namespace gtsam
|
} // \namespace gtsam
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file DiscreteBayesTree.h
|
* @file DiscreteBayesTree.h
|
||||||
* @brief Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree
|
* @brief Discrete Bayes Tree, the result of eliminating a
|
||||||
|
* DiscreteJunctionTree
|
||||||
* @brief DiscreteBayesTree
|
* @brief DiscreteBayesTree
|
||||||
* @author Frank Dellaert
|
* @author Frank Dellaert
|
||||||
* @author Richard Roberts
|
* @author Richard Roberts
|
||||||
|
@ -22,36 +23,47 @@
|
||||||
#include <gtsam/discrete/DiscreteBayesNet.h>
|
#include <gtsam/discrete/DiscreteBayesNet.h>
|
||||||
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
||||||
#include <gtsam/inference/BayesTree.h>
|
#include <gtsam/inference/BayesTree.h>
|
||||||
|
#include <gtsam/inference/Conditional.h>
|
||||||
#include <gtsam/inference/BayesTreeCliqueBase.h>
|
#include <gtsam/inference/BayesTreeCliqueBase.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
class DiscreteConditional;
|
class DiscreteConditional;
|
||||||
class VectorValues;
|
class VectorValues;
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/** A clique in a DiscreteBayesTree */
|
/** A clique in a DiscreteBayesTree */
|
||||||
class GTSAM_EXPORT DiscreteBayesTreeClique :
|
class GTSAM_EXPORT DiscreteBayesTreeClique
|
||||||
public BayesTreeCliqueBase<DiscreteBayesTreeClique, DiscreteFactorGraph>
|
: public BayesTreeCliqueBase<DiscreteBayesTreeClique, DiscreteFactorGraph> {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
typedef DiscreteBayesTreeClique This;
|
typedef DiscreteBayesTreeClique This;
|
||||||
typedef BayesTreeCliqueBase<DiscreteBayesTreeClique, DiscreteFactorGraph> Base;
|
typedef BayesTreeCliqueBase<DiscreteBayesTreeClique, DiscreteFactorGraph>
|
||||||
|
Base;
|
||||||
typedef boost::shared_ptr<This> shared_ptr;
|
typedef boost::shared_ptr<This> shared_ptr;
|
||||||
typedef boost::weak_ptr<This> weak_ptr;
|
typedef boost::weak_ptr<This> weak_ptr;
|
||||||
DiscreteBayesTreeClique() {}
|
DiscreteBayesTreeClique() {}
|
||||||
DiscreteBayesTreeClique(const boost::shared_ptr<DiscreteConditional>& conditional) : Base(conditional) {}
|
DiscreteBayesTreeClique(
|
||||||
|
const boost::shared_ptr<DiscreteConditional>& conditional)
|
||||||
|
: Base(conditional) {}
|
||||||
|
|
||||||
|
/// print index signature only
|
||||||
|
void printSignature(
|
||||||
|
const std::string& s = "Clique: ",
|
||||||
|
const KeyFormatter& formatter = DefaultKeyFormatter) const {
|
||||||
|
conditional_->printSignature(s, formatter);
|
||||||
|
}
|
||||||
|
|
||||||
//** evaluate conditional probability of subtree for given Values */
|
//** evaluate conditional probability of subtree for given Values */
|
||||||
double evaluate(const DiscreteConditional::Values & values) const;
|
double evaluate(const DiscreteConditional::Values& values) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
/** A Bayes tree representing a Discrete density */
|
/** A Bayes tree representing a Discrete density */
|
||||||
class GTSAM_EXPORT DiscreteBayesTree :
|
class GTSAM_EXPORT DiscreteBayesTree
|
||||||
public BayesTree<DiscreteBayesTreeClique>
|
: public BayesTree<DiscreteBayesTreeClique> {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
typedef BayesTree<DiscreteBayesTreeClique> Base;
|
typedef BayesTree<DiscreteBayesTreeClique> Base;
|
||||||
|
|
||||||
|
@ -64,6 +76,9 @@ namespace gtsam {
|
||||||
|
|
||||||
/** Check equality */
|
/** Check equality */
|
||||||
bool equals(const This& other, double tol = 1e-9) const;
|
bool equals(const This& other, double tol = 1e-9) const;
|
||||||
};
|
|
||||||
|
|
||||||
}
|
//** evaluate probability for given Values */
|
||||||
|
double evaluate(const DiscreteConditional::Values& values) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace gtsam
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,6 +94,13 @@ public:
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
/// print index signature only
|
||||||
|
void printSignature(
|
||||||
|
const std::string& s = "Discrete Conditional: ",
|
||||||
|
const KeyFormatter& formatter = DefaultKeyFormatter) const {
|
||||||
|
static_cast<const BaseConditional*>(this)->print(s, formatter);
|
||||||
|
}
|
||||||
|
|
||||||
/// Evaluate, just look up in AlgebraicDecisonTree
|
/// Evaluate, just look up in AlgebraicDecisonTree
|
||||||
virtual double operator()(const Values& values) const {
|
virtual double operator()(const Values& values) const {
|
||||||
return Potentials::operator()(values);
|
return Potentials::operator()(values);
|
||||||
|
|
|
@ -65,6 +65,8 @@ namespace gtsam {
|
||||||
Conditional(size_t nrFrontals) : nrFrontals_(nrFrontals) {}
|
Conditional(size_t nrFrontals) : nrFrontals_(nrFrontals) {}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
public:
|
||||||
/// @name Testable
|
/// @name Testable
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
@ -76,7 +78,6 @@ namespace gtsam {
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
public:
|
|
||||||
/// @name Standard Interface
|
/// @name Standard Interface
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue