format DiscreteMarginals.h
parent
dc79f492b2
commit
4b3c4093d5
|
@ -20,9 +20,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
||||
#include <gtsam/discrete/DiscreteBayesTree.h>
|
||||
#include <gtsam/base/Vector.h>
|
||||
#include <gtsam/discrete/DiscreteBayesTree.h>
|
||||
#include <gtsam/discrete/DiscreteFactorGraph.h>
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
|
@ -31,17 +31,15 @@ namespace gtsam {
|
|||
* @ingroup discrete
|
||||
*/
|
||||
class DiscreteMarginals {
|
||||
|
||||
protected:
|
||||
|
||||
DiscreteBayesTree::shared_ptr bayesTree_;
|
||||
|
||||
public:
|
||||
|
||||
DiscreteMarginals() {}
|
||||
|
||||
/** Construct a marginals class.
|
||||
* @param graph The factor graph defining the full joint distribution on all variables.
|
||||
* @param graph The factor graph defining the full joint
|
||||
* distribution on all variables.
|
||||
*/
|
||||
DiscreteMarginals(const DiscreteFactorGraph& graph) {
|
||||
bayesTree_ = graph.eliminateMultifrontal();
|
||||
|
@ -50,8 +48,8 @@ class DiscreteMarginals {
|
|||
/** Compute the marginal of a single variable */
|
||||
DiscreteFactor::shared_ptr operator()(Key variable) const {
|
||||
// Compute marginal
|
||||
DiscreteFactor::shared_ptr marginalFactor;
|
||||
marginalFactor = bayesTree_->marginalFactor(variable, &EliminateDiscrete);
|
||||
DiscreteFactor::shared_ptr marginalFactor =
|
||||
bayesTree_->marginalFactor(variable, &EliminateDiscrete);
|
||||
return marginalFactor;
|
||||
}
|
||||
|
||||
|
@ -61,8 +59,7 @@ class DiscreteMarginals {
|
|||
*/
|
||||
Vector marginalProbabilities(const DiscreteKey& key) const {
|
||||
// Compute marginal
|
||||
DiscreteFactor::shared_ptr marginalFactor;
|
||||
marginalFactor = bayesTree_->marginalFactor(key.first, &EliminateDiscrete);
|
||||
DiscreteFactor::shared_ptr marginalFactor = this->operator()(key.first);
|
||||
|
||||
// Create result
|
||||
Vector vResult(key.second);
|
||||
|
@ -73,7 +70,6 @@ class DiscreteMarginals {
|
|||
}
|
||||
return vResult;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} /* namespace gtsam */
|
||||
|
|
Loading…
Reference in New Issue