Go to the documentation of this file.
40 if (
auto conditional =
41 std::dynamic_pointer_cast<GaussianConditional>(
factor)) {
44 throw std::logic_error(
45 "A HybridGaussianConditional unexpectedly contained a non-conditional");
65 using P = std::vector<std::pair<Vector, double>>;
68 template <
typename... Args>
71 std::vector<GaussianFactorValuePair> fvs;
72 std::vector<GC::shared_ptr> gcs;
73 fvs.reserve(
p.size());
74 gcs.reserve(
p.size());
76 auto gaussianConditional =
78 double value = gaussianConditional->negLogConstant();
80 fvs.emplace_back(gaussianConditional,
value);
81 gcs.push_back(gaussianConditional);
90 if (!
gc)
return {
nullptr, std::numeric_limits<double>::infinity()};
92 double value =
gc->negLogConstant();
98 throw std::runtime_error(
99 "HybridGaussianConditional: need at least one frontal variable. "
100 "Provided conditionals do not contain any frontal variables.");
107 if (!pair.first)
return;
114 throw std::runtime_error(
115 "HybridGaussianConditional: need at least one frontal variable. "
116 "Provided conditionals do not contain any frontal variables.");
129 pair.first, pair.second - helper.minNegLogConstant};
131 std::move(helper.pairs))),
132 BaseConditional(*helper.nrFrontals),
133 negLogConstant_(helper.minNegLogConstant),
138 const std::vector<GaussianConditional::shared_ptr> &
conditionals)
144 const std::vector<std::pair<Vector, double>> &
parameters)
151 const std::vector<std::pair<Vector, double>> &
parameters)
159 const std::vector<std::pair<Vector, double>> &
parameters)
178 return std::dynamic_pointer_cast<GaussianConditional>(pair.first);
186 if (node.first) total += 1;
195 if (!
factor)
return nullptr;
204 const This *
e =
dynamic_cast<const This *
>(&lf);
205 if (
e ==
nullptr)
return false;
212 auto c1 = std::dynamic_pointer_cast<GaussianConditional>(pair1.first),
213 c2 = std::dynamic_pointer_cast<GaussianConditional>(pair2.first);
222 std::cout << (
s.empty() ?
"" :
s +
"\n");
224 std::cout <<
" Discrete Keys = ";
226 std::cout <<
"(" <<
formatter(dk.first) <<
", " << dk.second <<
"), ";
228 std::cout << std::endl
229 <<
" logNormalizationConstant: " << -
negLogConstant() << std::endl
236 std::dynamic_pointer_cast<GaussianConditional>(pair.first)) {
252 const Key key = discreteKey.first;
254 continuousParentKeys.erase(std::remove(continuousParentKeys.begin(),
255 continuousParentKeys.end(),
key),
256 continuousParentKeys.end());
258 return continuousParentKeys;
264 for (
auto &&kv : given) {
265 if (given.find(kv.first) == given.end()) {
276 throw std::runtime_error(
277 "HybridGaussianConditional::likelihood: given values are missing some "
286 if (
auto conditional =
287 std::dynamic_pointer_cast<GaussianConditional>(pair.first)) {
288 const auto likelihood_m = conditional->likelihood(given);
290 return {likelihood_m, pair.second};
292 return {
nullptr, std::numeric_limits<double>::infinity()};
295 return std::make_shared<HybridGaussianFactor>(discreteParentKeys,
301 std::set<DiscreteKey>
s(discreteKeys.begin(), discreteKeys.end());
309 std::set<Key> mine(this->
keys().begin(), this->
keys().
end());
310 std::set<Key> theirs(discreteProbs.
keys().begin(),
311 discreteProbs.
keys().end());
312 std::vector<Key> diff;
313 std::set_difference(theirs.begin(), theirs.end(), mine.begin(), mine.end(),
314 std::back_inserter(diff));
325 if (
max->evaluate(choices) == 0.0)
326 return {
nullptr, std::numeric_limits<double>::infinity()};
330 return {pair.first, pair.second + negLogConstant_};
335 return std::make_shared<HybridGaussianConditional>(discreteKeys(),
336 prunedConditionals,
true);
340 double HybridGaussianConditional::logProbability(
344 return conditional->logProbability(
values.continuous());
351 return conditional->evaluate(
values.continuous());
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
Linear Factor Graph where all factors are Gaussians.
Conditional Gaussian Base class.
Helper(const Conditionals &conditionals)
Construct from tree of GaussianConditionals.
std::shared_ptr< This > shared_ptr
A hybrid conditional in the Conditional Linear Gaussian scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
GaussianConditional::shared_ptr choose(const DiscreteValues &discreteValues) const
Return the conditional Gaussian for the given discrete assignment.
Helper struct for constructing HybridGaussianConditional objects.
Helper(const DiscreteKey &mode, const P &p, Args &&...args)
Construct from a vector of mean and sigma pairs, plus extra args.
bool equals(const DecisionTree &other, const CompareFunc &compare=&DefaultCompare) const
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, const LabelFormatter &labelFormatter, const ValueFormatter &valueFormatter) const
GTSAM-style print.
Chordal Bayes Net, the result of eliminating a factor graph.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
A set of GaussianFactors, indexed by a set of discrete keys.
const std::vector< GaussianConditional::shared_ptr > conditionals
static const double sigma
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")
Double_ range(const Point2_ &p, const Point2_ &q)
GaussianConditional::shared_ptr checkConditional(const GaussianFactor::shared_ptr &factor)
std::pair< GaussianFactor::shared_ptr, double > GaussianFactorValuePair
Alias for pair of GaussianFactor::shared_pointer and a double value.
static const DiscreteKey mode(modeKey, 2)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
static ConjugateGradientParameters parameters
size_t nrComponents() const
Returns the total number of continuous components.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
std::vector< std::pair< Vector, double > > P
A conditional of gaussian conditionals indexed by discrete variables, as part of a Bayes Network....
void visit(Func f) const
Visit all leaves in depth-first fashion.
KeyVector continuousParents() const
Returns the continuous keys among the parents.
const FactorValuePairs & factors() const
Getter for GaussianFactor decision tree.
std::shared_ptr< HybridGaussianFactor > likelihood(const VectorValues &given) const
std::optional< size_t > nrFrontals
const gtsam::Symbol key('X', 0)
std::set< DiscreteKey > DiscreteKeysAsSet(const DiscreteKeys &discreteKeys)
Return the DiscreteKey vector as a set.
const Conditionals conditionals() const
DecisionTree< Key, GaussianConditional::shared_ptr > Conditionals
typedef for Decision Tree of Gaussian Conditionals
DecisionTree< Key, GaussianFactorValuePair > FactorValuePairs
typedef for Decision Tree of Gaussian factors and arbitrary value.
Point3 mean(const CONTAINER &points)
mean
const KeyVector & keys() const
Access the factor's involved variable keys.
bool equals(const This &other, double tol=1e-9) const
check equality
std::pair< Key, size_t > DiscreteKey
shared_ptr max(size_t nrFrontals) const
Create new factor by maximizing over all values with the same separator.
bool allFrontalsGiven(const VectorValues &given) const
Check whether given has values for all frontal keys.
bool equals(const HybridFactor &lf, double tol=1e-9) const override
Test equality with base HybridFactor.
Implementation of a discrete-conditioned hybrid factor. Implements a joint discrete-continuous factor...
std::shared_ptr< This > shared_ptr
shared_ptr to this class
double negLogConstant() const override
Return log normalization constant in negative log space.
HybridGaussianConditional()=default
Default constructor, mainly for serialization.
static const EIGEN_DEPRECATED end_t end
std::uint64_t Key
Integer nonlinear key type.
constexpr descr< N - 1 > _(char const (&text)[N])
Helper(const FactorValuePairs &pairs)
Construct from tree of factor/scalar pairs.
const DiscreteKeys & discreteKeys() const
Return the discrete keys for this factor.
void print(const std::string &s="HybridGaussianConditional\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
Print utility.
std::string str() const
return the string
static shared_ptr sharedMeanAndStddev(Args &&... args)
Create shared pointer by forwarding arguments to fromMeanAndStddev.
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:40