Adapt to continuous densities

release/4.3a0
Frank Dellaert 2023-01-14 10:23:00 -08:00
parent 0a6334ef1f
commit 693d18233a
2 changed files with 7 additions and 6 deletions

View File

@ -68,12 +68,13 @@ template <class FACTOR, class DERIVEDCONDITIONAL>
template <class VALUES>
bool Conditional<FACTOR, DERIVEDCONDITIONAL>::CheckInvariants(
const DERIVEDCONDITIONAL& conditional, const VALUES& values) {
const double probability = conditional.evaluate(values);
if (probability < 0.0 || probability > 1.0)
return false; // probability is not in [0,1]
const double prob_or_density = conditional.evaluate(values);
if (prob_or_density < 0.0) return false; // prob_or_density is negative.
if (std::abs(prob_or_density - conditional(values)) > 1e-9)
return false; // operator and evaluate differ
const double logProb = conditional.logProbability(values);
if (std::abs(probability - std::exp(logProb)) > 1e-9)
return false; // logProb is not consistent with probability
if (std::abs(prob_or_density - std::exp(logProb)) > 1e-9)
return false; // logProb is not consistent with prob_or_density
const double expected =
conditional.logNormalizationConstant() - conditional.error(values);
if (std::abs(logProb - expected) > 1e-9)

View File

@ -34,7 +34,7 @@ namespace gtsam {
/**
* A GaussianConditional functions as the node in a Bayes network.
* It has a set of parents y,z, etc. and implements a probability density on x.
* The negative log-probability is given by \f$ \frac{1}{2} |Rx - (d - Sy - Tz - ...)|^2 \f$
* The negative log-density is given by \f$ \frac{1}{2} |Rx - (d - Sy - Tz - ...)|^2 \f$
* @ingroup linear
*/
class GTSAM_EXPORT GaussianConditional :