use DiscreteLookupDAG for DiscreteBayesNet mode
parent
f6449c0ad8
commit
a43dad2e34
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include <gtsam/discrete/DiscreteBayesNet.h>
|
#include <gtsam/discrete/DiscreteBayesNet.h>
|
||||||
#include <gtsam/discrete/DiscreteConditional.h>
|
#include <gtsam/discrete/DiscreteConditional.h>
|
||||||
|
#include <gtsam/discrete/DiscreteLookupDAG.h>
|
||||||
#include <gtsam/inference/FactorGraph-inst.h>
|
#include <gtsam/inference/FactorGraph-inst.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -56,18 +57,15 @@ DiscreteValues DiscreteBayesNet::sample() const {
|
||||||
|
|
||||||
DiscreteValues DiscreteBayesNet::sample(DiscreteValues result) const {
|
DiscreteValues DiscreteBayesNet::sample(DiscreteValues result) const {
|
||||||
// sample each node in turn in topological sort order (parents first)
|
// sample each node in turn in topological sort order (parents first)
|
||||||
for (auto it = std::make_reverse_iterator(end()); it != std::make_reverse_iterator(begin()); ++it) {
|
for (auto it = std::make_reverse_iterator(end());
|
||||||
|
it != std::make_reverse_iterator(begin()); ++it) {
|
||||||
(*it)->sampleInPlace(&result);
|
(*it)->sampleInPlace(&result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscreteValues DiscreteBayesNet::mode() const {
|
DiscreteValues DiscreteBayesNet::mode() const {
|
||||||
DiscreteValues result;
|
return DiscreteLookupDAG::FromBayesNet(*this).argmax();
|
||||||
for (auto it = begin(); it != end(); ++it) {
|
|
||||||
result[(*it)->firstFrontalKey()] = (*it)->argmax(result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* *********************************************************************** */
|
/* *********************************************************************** */
|
||||||
|
|
Loading…
Reference in New Issue