Go to the documentation of this file.
36 template class FactorGraph<DiscreteFactor>;
37 template class EliminateableFactorGraph<DiscreteFactorGraph>;
56 for (
auto&&
factor : *
this) {
57 if (
auto p = std::dynamic_pointer_cast<DiscreteFactor>(
factor)) {
69 for (
const auto&
factor : *
this) {
89 std::cout <<
s << std::endl;
90 std::cout <<
"size: " <<
size() << std::endl;
93 ss <<
"factor " <<
i <<
": ";
123 std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr>
135 for (
auto&&
key : frontalKeys)
137 for (
auto&&
key :
max->keys())
142 size_t nrFrontals = frontalKeys.size();
143 auto lookup = std::make_shared<DiscreteLookupTable>(
144 nrFrontals, orderedKeys,
product->toDecisionTreeFactor());
147 return {std::dynamic_pointer_cast<DiscreteConditional>(lookup),
max};
153 OptionalOrderingType orderingType)
const {
154 gttic(DiscreteFactorGraph_sumProduct);
161 gttic(DiscreteFactorGraph_sumProduct);
173 OptionalOrderingType orderingType)
const {
174 gttic(DiscreteFactorGraph_maxProduct);
181 gttic(DiscreteFactorGraph_maxProduct);
188 OptionalOrderingType orderingType)
const {
189 gttic(DiscreteFactorGraph_optimize);
195 gttic(DiscreteFactorGraph_optimize);
201 std::pair<DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr>
216 orderedKeys.insert(orderedKeys.end(), frontalKeys.begin(),
218 orderedKeys.insert(orderedKeys.end(), sum->keys().begin(),
223 auto conditional = std::make_shared<DiscreteConditional>(
224 product->toDecisionTreeFactor(), sum->toDecisionTreeFactor(),
228 return {conditional, sum};
236 std::stringstream
ss;
237 ss <<
"`DiscreteFactorGraph` of size " <<
size() << endl << endl;
239 ss <<
"factor " <<
i <<
":\n";
249 std::stringstream
ss;
250 ss <<
"<div><p><tt>DiscreteFactorGraph</tt> of size " <<
size() <<
"</p>";
252 ss <<
"<p>factor " <<
i <<
":</p>";
DiscreteKeys discreteKeys() const
Return the DiscreteKeys in this factor graph.
std::pair< DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr > EliminateDiscrete(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Main elimination function for DiscreteFactorGraph.
std::pair< DiscreteConditional::shared_ptr, DiscreteFactor::shared_ptr > EliminateForMPE(const DiscreteFactorGraph &factors, const Ordering &frontalKeys)
Alternate elimination function for that creates non-normalized lookup tables.
std::shared_ptr< BayesNetType > eliminateSequential(OptionalOrderingType orderingType={}, const Eliminate &function=EliminationTraitsType::DefaultEliminate, OptionalVariableIndex variableIndex={}) const
static const DiscreteBayesNet bayesNet
FastVector< sharedFactor > factors_
DiscreteBayesNet sumProduct(OptionalOrderingType orderingType={}) const
Implement the sum-product algorithm.
const GaussianFactorGraph factors
const KeyFormatter & formatter
DiscreteKeys is a set of keys that can be assembled using the & operator.
void print(const std::string &s="DiscreteFactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
DiscreteLookupDAG maxProduct(OptionalOrderingType orderingType={}) const
Implement the max-product algorithm.
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
static std::stringstream ss
DiscreteFactor::shared_ptr scaledProduct() const
Return product of all factors as a single factor, which is scaled by the max value to prevent underfl...
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
bool equals(const This &fg, double tol=1e-9) const
Check equality up to tolerance.
bool equals(const This &fg, double tol=1e-9) const
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as markdown tables.
DiscreteFactor::shared_ptr product() const
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
static enum @1096 ordering
const gtsam::Symbol key('X', 0)
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
DiscreteValues::Names Names
Translation table from values to strings.
std::pair< iterator, bool > insert(const value_type &value)
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteFactor::Names &names={}) const
Render as html tables.
void product(const MatrixType &m)
DiscreteValues argmax(DiscreteValues given=DiscreteValues()) const
argmax by back-substitution, optionally given certain variables.
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
std::shared_ptr< DiscreteFactor > sharedFactor
Shared pointer to a factor.
static DiscreteLookupDAG FromBayesNet(const DiscreteBayesNet &bayesNet)
Create from BayesNet with LookupTables.
double operator()(const DiscreteValues &values) const
gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:36