Go to the documentation of this file.
43 size_t maxNrLeaves,
const std::optional<double> &marginalThreshold,
45 #if GTSAM_HYBRID_TIMING
54 marginal.
prune(maxNrLeaves, marginalThreshold, &fixed);
60 if (marginalThreshold && fixedValues) {
69 for (std::shared_ptr<HybridConditional> conditional : *
this) {
70 if (conditional->isDiscrete())
continue;
73 if (marginalThreshold) {
74 conditional = std::static_pointer_cast<HybridConditional>(
75 conditional->restrict(fixed));
79 if (
auto hgc = conditional->asHybrid()) {
81 auto prunedHybridGaussianConditional =
hgc->prune(pruned);
82 if (!prunedHybridGaussianConditional) {
83 throw std::runtime_error(
84 "A HybridGaussianConditional had all its conditionals pruned");
87 result.push_back(prunedHybridGaussianConditional);
88 }
else if (conditional->isContinuous()) {
90 result.push_back(conditional);
92 throw std::runtime_error(
93 "HybrdiBayesNet::prune: Unknown HybridConditional type.");
96 #if GTSAM_HYBRID_TIMING
102 result.push_back(discrete);
110 for (
auto &&conditional : *
this) {
111 if (
auto dc = conditional->asDiscrete()) {
122 for (
auto &&conditional : *
this) {
123 if (
auto gm = conditional->asHybrid()) {
125 gbn.push_back(gm->choose(assignment));
126 }
else if (
auto gc = conditional->asGaussian()) {
129 }
else if (
auto dc = conditional->asDiscrete()) {
143 for (
auto &&conditional : *
this) {
144 if (conditional->isDiscrete()) {
149 dtc->toDecisionTreeFactor()));
151 discrete_fg.
push_back(conditional->asDiscrete());
174 if (std::find(
gbn.begin(),
gbn.end(),
nullptr) !=
gbn.end()) {
177 return gbn.optimize();
182 std::mt19937_64 *
rng)
const {
184 for (
auto &&conditional : *
this) {
185 if (conditional->isDiscrete()) {
187 dbn.
push_back(conditional->asDiscrete());
196 return {
sample, assignment};
211 for (
auto &&conditional : *
this) {
212 result =
result + conditional->errorTree(continuousValues);
220 const std::optional<DiscreteValues> &discrete)
const {
221 double negLogNormConst = 0.0;
223 for (
auto &&conditional : *
this) {
224 if (discrete.has_value()) {
225 if (
auto gm = conditional->asHybrid()) {
226 negLogNormConst += gm->choose(*discrete)->negLogConstant();
227 }
else if (
auto gc = conditional->asGaussian()) {
228 negLogNormConst +=
gc->negLogConstant();
229 }
else if (
auto dc = conditional->asDiscrete()) {
230 negLogNormConst += dc->choose(*discrete)->negLogConstant();
232 throw std::runtime_error(
233 "Unknown conditional type when computing negLogConstant");
236 negLogNormConst += conditional->negLogConstant();
239 return negLogNormConst;
263 for (
auto &&conditional : *
this) {
265 if (
auto gc = conditional->asGaussian()) {
267 }
else if (
auto gm = conditional->asHybrid()) {
270 throw std::runtime_error(
"Unknown conditional type");
bool equals(const This &fg, double tol=1e-9) const
GTSAM-style equals.
void print(const std::string &s="BayesNet", const KeyFormatter &formatter=DefaultKeyFormatter) const override
double error(const HybridValues &values) const
double evaluate(const HybridValues &values) const
Evaluate hybrid probability density for given HybridValues.
const KeyFormatter & formatter
A Bayes net of Gaussian Conditionals indexed by discrete keys.
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
const VectorValues & continuous() const
Return the multi-dimensional vector values.
HybridValues optimize() const
Solve the HybridBayesNet by first computing the MPE of all the discrete variables and then optimizing...
DiscreteConditional joint() const
Multiply all conditionals into one big joint conditional and return it.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
AlgebraicDecisionTree< Key > errorTree(const VectorValues &continuousValues) const
Compute the negative log posterior log P'(M|x) of all assignments up to a constant,...
DiscreteBayesNet prune(size_t maxNrLeaves, const std::optional< double > &marginalThreshold={}, DiscreteValues *fixedValues=nullptr) const
Prune the Bayes net.
bool equals(const This &fg, double tol=1e-9) const
Check equality up to tolerance.
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style printing.
DiscreteValues mpe() const
Compute the Most Probable Explanation (MPE) of the discrete variables.
DiscreteBayesNet discreteMarginal() const
Get the discrete Bayes Net P(M). As the hybrid Bayes net defines P(X,M) = P(X|M) P(M),...
DecisionTree apply(const Unary &op) const
static const GaussianBayesNet gbn
std::shared_ptr< This > shared_ptr
shared_ptr to this class
std::vector< double > measurements
AlgebraicDecisionTree< Key > discretePosterior(const VectorValues &continuousValues) const
Compute normalized posterior P(M|X=x) and return as a tree.
double logProbability(const HybridValues &x) const
HybridValues sample(const HybridValues &given, std::mt19937_64 *rng=nullptr) const
Sample from an incomplete BayesNet, given missing variables.
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
const DiscreteValues & discrete() const
Return the discrete values.
DiscreteValues sample(std::mt19937_64 *rng=nullptr) const
do ancestral sampling
DiscreteValues optimize(OptionalOrderingType orderingType={}) const
Find the maximum probable explanation (MPE) by doing max-product.
HybridBayesNet prune(size_t maxNrLeaves, const std::optional< double > &marginalThreshold={}, DiscreteValues *fixedValues=nullptr) const
Prune the Bayes Net such that we have at most maxNrLeaves leaves.
HybridGaussianFactorGraph toFactorGraph(const VectorValues &measurements) const
GaussianBayesNet choose(const DiscreteValues &assignment) const
Get the Gaussian Bayes net P(X|M=m) corresponding to a specific assignment m for the discrete variabl...
double negLogConstant(const std::optional< DiscreteValues > &discrete) const
Get the negative log of the normalization constant corresponding to the joint density represented by ...
gtsam
Author(s):
autogenerated on Wed May 28 2025 03:01:25