From 8b6c1a0b9d104c58aac140899f7f56856bb0aeff Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sat, 15 Sep 2012 11:48:21 +0000 Subject: [PATCH] evaluate (interesting that this is not even defined in BayesNet, should move there?) --- gtsam/discrete/DiscreteBayesNet.cpp | 9 +++++++++ gtsam/discrete/DiscreteBayesNet.h | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/gtsam/discrete/DiscreteBayesNet.cpp b/gtsam/discrete/DiscreteBayesNet.cpp index 67f4e4333..1d21d0a4b 100644 --- a/gtsam/discrete/DiscreteBayesNet.cpp +++ b/gtsam/discrete/DiscreteBayesNet.cpp @@ -36,6 +36,15 @@ namespace gtsam { bayesNet.push_back(boost::make_shared(s)); } + /* ************************************************************************* */ + double evaluate(const DiscreteBayesNet& bn, const DiscreteConditional::Values & values) { + // evaluate all conditionals and multiply + double result = 1.0; + BOOST_FOREACH(DiscreteConditional::shared_ptr conditional, bn) + result *= (*conditional)(values); + return result; + } + /* ************************************************************************* */ DiscreteFactor::sharedValues optimize(const DiscreteBayesNet& bn) { // solve each node in turn in topological sort order (parents first) diff --git a/gtsam/discrete/DiscreteBayesNet.h b/gtsam/discrete/DiscreteBayesNet.h index a7c35e135..c8286f3a9 100644 --- a/gtsam/discrete/DiscreteBayesNet.h +++ b/gtsam/discrete/DiscreteBayesNet.h @@ -33,7 +33,10 @@ namespace gtsam { /** Add a DiscreteCondtional in front, when listing parents first*/ void add_front(DiscreteBayesNet&, const Signature& s); - /** Optimize function for back-substitution. */ + //** evaluate for given Values */ + double evaluate(const DiscreteBayesNet& bn, const DiscreteConditional::Values & values); + + /** Optimize function for back-substitution. */ DiscreteFactor::sharedValues optimize(const DiscreteBayesNet& bn); /** Do ancestral sampling */