rename ComputeLogNormalizer to ComputeLogNormalizerConstant
parent
9b6facd262
commit
244661afb1
|
|
@ -30,8 +30,8 @@ namespace gtsam {
|
|||
|
||||
/**
|
||||
* @brief Helper function to augment the [A|b] matrices in the factor components
|
||||
* with the normalizer values.
|
||||
* This is done by storing the normalizer value in
|
||||
* with the additional scalar values.
|
||||
* This is done by storing the value in
|
||||
* the `b` vector as an additional row.
|
||||
*
|
||||
* @param factors DecisionTree of GaussianFactors and arbitrary scalars.
|
||||
|
|
@ -56,7 +56,7 @@ HybridGaussianFactor::Factors augment(
|
|||
const HybridGaussianFactor::sharedFactor &gf) {
|
||||
auto jf = std::dynamic_pointer_cast<JacobianFactor>(gf);
|
||||
if (!jf) return gf;
|
||||
// If the log_normalizer is 0, do nothing
|
||||
// If the value is 0, do nothing
|
||||
if (values(assignment) == 0.0) return gf;
|
||||
|
||||
GaussianFactorGraph gfg;
|
||||
|
|
|
|||
|
|
@ -771,7 +771,8 @@ static HybridGaussianFactorGraph CreateFactorGraph(
|
|||
|
||||
// Create HybridGaussianFactor
|
||||
std::vector<GaussianFactorValuePair> factors{
|
||||
{f0, ComputeLogNormalizer(model0)}, {f1, ComputeLogNormalizer(model1)}};
|
||||
{f0, ComputeLogNormalizerConstant(model0)},
|
||||
{f1, ComputeLogNormalizerConstant(model1)}};
|
||||
HybridGaussianFactor motionFactor({X(0), X(1)}, m1, factors);
|
||||
|
||||
HybridGaussianFactorGraph hfg;
|
||||
|
|
|
|||
|
|
@ -869,7 +869,8 @@ static HybridNonlinearFactorGraph CreateFactorGraph(
|
|||
|
||||
// Create HybridNonlinearFactor
|
||||
std::vector<NonlinearFactorValuePair> factors{
|
||||
{f0, ComputeLogNormalizer(model0)}, {f1, ComputeLogNormalizer(model1)}};
|
||||
{f0, ComputeLogNormalizerConstant(model0)},
|
||||
{f1, ComputeLogNormalizerConstant(model1)}};
|
||||
|
||||
HybridNonlinearFactor mixtureFactor({X(0), X(1)}, m1, factors);
|
||||
|
||||
|
|
|
|||
|
|
@ -710,7 +710,7 @@ const RobustModel::shared_ptr &robust, const NoiseModel::shared_ptr noise){
|
|||
} // namespace noiseModel
|
||||
|
||||
/* *******************************************************************************/
|
||||
double ComputeLogNormalizer(
|
||||
double ComputeLogNormalizerConstant(
|
||||
const noiseModel::Gaussian::shared_ptr& noise_model) {
|
||||
// Since noise models are Gaussian, we can get the logDeterminant using
|
||||
// the same trick as in GaussianConditional
|
||||
|
|
@ -725,7 +725,7 @@ double ComputeLogNormalizer(
|
|||
|
||||
size_t n = noise_model->dim();
|
||||
constexpr double log2pi = 1.8378770664093454835606594728112;
|
||||
return n * log2pi + logDeterminantSigma;
|
||||
return 0.5*(n * log2pi + logDeterminantSigma);
|
||||
}
|
||||
|
||||
} // gtsam
|
||||
|
|
|
|||
|
|
@ -757,10 +757,10 @@ namespace gtsam {
|
|||
* We compute this in the log-space for numerical accuracy.
|
||||
*
|
||||
* @param noise_model The Gaussian noise model
|
||||
* whose normalizer we wish to compute.
|
||||
* whose normalization constant we wish to compute.
|
||||
* @return double
|
||||
*/
|
||||
GTSAM_EXPORT double ComputeLogNormalizer(
|
||||
GTSAM_EXPORT double ComputeLogNormalizerConstant(
|
||||
const noiseModel::Gaussian::shared_ptr& noise_model);
|
||||
|
||||
} //\ namespace gtsam
|
||||
|
|
|
|||
|
|
@ -807,11 +807,11 @@ TEST(NoiseModel, NonDiagonalGaussian)
|
|||
}
|
||||
}
|
||||
|
||||
TEST(NoiseModel, ComputeLogNormalizer) {
|
||||
TEST(NoiseModel, ComputeLogNormalizerConstant) {
|
||||
// Very simple 1D noise model, which we can compute by hand.
|
||||
double sigma = 0.1;
|
||||
auto noise_model = Isotropic::Sigma(1, sigma);
|
||||
double actual_value = ComputeLogNormalizer(noise_model);
|
||||
double actual_value = ComputeLogNormalizerConstant(noise_model);
|
||||
// Compute log(|2πΣ|) by hand.
|
||||
// = log(2π) + log(Σ) (since it is 1D)
|
||||
constexpr double log2pi = 1.8378770664093454835606594728112;
|
||||
|
|
@ -821,7 +821,7 @@ TEST(NoiseModel, ComputeLogNormalizer) {
|
|||
// Similar situation in the 3D case
|
||||
size_t n = 3;
|
||||
auto noise_model2 = Isotropic::Sigma(n, sigma);
|
||||
double actual_value2 = ComputeLogNormalizer(noise_model2);
|
||||
double actual_value2 = ComputeLogNormalizerConstant(noise_model2);
|
||||
// We multiply by 3 due to the determinant
|
||||
double expected_value2 = n * (log2pi + log(sigma * sigma));
|
||||
EXPECT_DOUBLES_EQUAL(expected_value2, actual_value2, 1e-9);
|
||||
|
|
|
|||
Loading…
Reference in New Issue