33 {continuousFrontals.begin(), continuousFrontals.end()},
34 KeyVector{continuousParents.begin(), continuousParents.end()}),
36 {discreteFrontals.begin(), discreteFrontals.end()},
37 {discreteParents.begin(), discreteParents.end()}),
38 continuousFrontals.size() + discreteFrontals.size()) {}
42 const std::shared_ptr<GaussianConditional> &continuousConditional)
44 continuousConditional->nrFrontals()) {
45 inner_ = continuousConditional;
50 const std::shared_ptr<DiscreteConditional> &discreteConditional)
52 discreteConditional->nrFrontals()) {
53 inner_ = discreteConditional;
58 const std::shared_ptr<GaussianMixture> &gaussianMixture)
73 inner_->print(
"", formatter);
78 if (
isHybrid()) std::cout <<
"Hybrid ";
83 const size_t N =
keys().size();
96 std::cout <<
"(" <<
formatter(dk.first) <<
", " << dk.second <<
")";
106 if (e ==
nullptr)
return false;
109 return other !=
nullptr && gm->
equals(*other, tol);
113 return other !=
nullptr && gc->
equals(*other, tol);
117 return other !=
nullptr && dc->
equals(*other, tol);
130 return gm->error(values);
133 return dc->error(values.
discrete());
135 throw std::runtime_error(
136 "HybridConditional::error: conditional type not handled");
142 return gc->logProbability(values.
continuous());
145 return gm->logProbability(values);
148 return dc->logProbability(values.
discrete());
150 throw std::runtime_error(
151 "HybridConditional::logProbability: conditional type not handled");
157 return gc->logNormalizationConstant();
160 return gm->logNormalizationConstant();
163 return dc->logNormalizationConstant();
165 throw std::runtime_error(
166 "HybridConditional::logProbability: conditional type not handled");
double error(const HybridValues &values) const override
Return the error of the underlying conditional.
const DiscreteKeys & discreteKeys() const
Return the discrete keys for this factor.
double logNormalizationConstant() const override
size_t nrFrontals() const
const VectorValues & continuous() const
Return the multi-dimensional vector values.
double logProbability(const HybridValues &values) const override
Return the log-probability (or density) of the underlying conditional.
const KeyFormatter & formatter
DiscreteConditional::shared_ptr asDiscrete() const
Return conditional as a DiscreteConditional.
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
HybridConditional()=default
Default constructor needed for serialization.
size_t nrContinuous() const
Return the number of continuous variables in this factor.
GaussianConditional::shared_ptr asGaussian() const
Return HybridConditional as a GaussianConditional.
void print(const std::string &s="Hybrid Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
virtual bool equals(const HybridFactor &lf, double tol=1e-9) const
equals
Array< double, 1, 3 > e(1./3., 0.5, 2.)
bool isContinuous() const
True if this is a factor of continuous variables only.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
GaussianMixture::shared_ptr asMixture() const
Return HybridConditional as a GaussianMixture.
double evaluate(const HybridValues &values) const override
Return the probability (or density) of the underlying conditional.
bool isHybrid() const
True is this is a Discrete-Continuous factor.
const DiscreteValues & discrete() const
Return the discrete values.
const KeyVector & keys() const
Access the factor's involved variable keys.
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
bool equals(const HybridFactor &other, double tol=1e-9) const override
GTSAM-style equals.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
DiscreteKeys discreteKeys_
const_iterator begin() const
bool isDiscrete() const
True if this is a factor of discrete variables only.
DiscreteKeys CollectDiscreteKeys(const DiscreteKeys &key1, const DiscreteKeys &key2)
KeyVector CollectKeys(const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys)
std::shared_ptr< Factor > inner_
Type-erased pointer to the inner type.
DiscreteKeys is a set of keys that can be assembled using the & operator.