Skip to content

Commit

Permalink
rename ComputeLogNormalizer to ComputeLogNormalizerConstant
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Sep 19, 2024
1 parent 9b6facd commit 244661a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions gtsam/hybrid/HybridGaussianFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion gtsam/hybrid/tests/testHybridGaussianFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion gtsam/hybrid/tests/testHybridNonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions gtsam/linear/NoiseModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions gtsam/linear/NoiseModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions gtsam/linear/tests/testNoiseModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 244661a

Please sign in to comment.