new helper method in DiscreteBayesNet to compute joint conditional
parent
1514a0d62e
commit
4d97136f5c
|
@ -71,16 +71,14 @@ DiscreteValues DiscreteBayesNet::sample(DiscreteValues result) const {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// The implementation is: build the entire joint into one factor and then prune.
|
// The implementation is: build the entire joint into one factor and then prune.
|
||||||
// TODO(Frank): This can be quite expensive *unless* the factors have already
|
// NOTE: This can be quite expensive *unless* the factors have already
|
||||||
// been pruned before. Another, possibly faster approach is branch and bound
|
// been pruned before. Another, possibly faster approach is branch and bound
|
||||||
// search to find the K-best leaves and then create a single pruned conditional.
|
// search to find the K-best leaves and then create a single pruned conditional.
|
||||||
DiscreteBayesNet DiscreteBayesNet::prune(
|
DiscreteBayesNet DiscreteBayesNet::prune(
|
||||||
size_t maxNrLeaves, const std::optional<double>& marginalThreshold,
|
size_t maxNrLeaves, const std::optional<double>& marginalThreshold,
|
||||||
DiscreteValues* fixedValues) const {
|
DiscreteValues* fixedValues) const {
|
||||||
// Multiply into one big conditional. NOTE: possibly quite expensive.
|
// Multiply into one big conditional. NOTE: possibly quite expensive.
|
||||||
DiscreteConditional joint;
|
DiscreteConditional joint = this->joint();
|
||||||
for (const DiscreteConditional::shared_ptr& conditional : *this)
|
|
||||||
joint = joint * (*conditional);
|
|
||||||
|
|
||||||
// Prune the joint. NOTE: imperative and, again, possibly quite expensive.
|
// Prune the joint. NOTE: imperative and, again, possibly quite expensive.
|
||||||
DiscreteConditional pruned = joint;
|
DiscreteConditional pruned = joint;
|
||||||
|
@ -122,6 +120,15 @@ DiscreteBayesNet DiscreteBayesNet::prune(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* *********************************************************************** */
|
||||||
|
DiscreteConditional DiscreteBayesNet::joint() const {
|
||||||
|
DiscreteConditional joint;
|
||||||
|
for (const DiscreteConditional::shared_ptr& conditional : *this)
|
||||||
|
joint = joint * (*conditional);
|
||||||
|
|
||||||
|
return joint;
|
||||||
|
}
|
||||||
|
|
||||||
/* *********************************************************************** */
|
/* *********************************************************************** */
|
||||||
std::string DiscreteBayesNet::markdown(
|
std::string DiscreteBayesNet::markdown(
|
||||||
const KeyFormatter& keyFormatter,
|
const KeyFormatter& keyFormatter,
|
||||||
|
|
|
@ -136,6 +136,16 @@ class GTSAM_EXPORT DiscreteBayesNet: public BayesNet<DiscreteConditional> {
|
||||||
const std::optional<double>& marginalThreshold = {},
|
const std::optional<double>& marginalThreshold = {},
|
||||||
DiscreteValues* fixedValues = nullptr) const;
|
DiscreteValues* fixedValues = nullptr) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Multiply all conditionals into one big joint conditional
|
||||||
|
* and return it.
|
||||||
|
*
|
||||||
|
* NOTE: possibly quite expensive.
|
||||||
|
*
|
||||||
|
* @return DiscreteConditional
|
||||||
|
*/
|
||||||
|
DiscreteConditional joint() const;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
/// @name Wrapper support
|
/// @name Wrapper support
|
||||||
/// @{
|
/// @{
|
||||||
|
|
Loading…
Reference in New Issue