From cf5a43a6c6cea7cabdfe120cdb725924d8bb7bc1 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Tue, 18 Jun 2013 04:37:46 +0000 Subject: [PATCH] WhiteNoiseFactor was defunct but now compiles and has at least one (simple) test. Shame on whomever moved this to GTSAM for not adding a test. --- .cproject | 362 +++++++++--------- gtsam/nonlinear/WhiteNoiseFactor.h | 43 ++- .../nonlinear/tests/testWhiteNoiseFactor.cpp | 38 ++ 3 files changed, 241 insertions(+), 202 deletions(-) create mode 100644 gtsam/nonlinear/tests/testWhiteNoiseFactor.cpp diff --git a/.cproject b/.cproject index 46f9a60fb..56b3a0cae 100644 --- a/.cproject +++ b/.cproject @@ -1,5 +1,7 @@ - + + + @@ -307,6 +309,14 @@ true true + + make + -j2 + testGaussianFactor.run + true + true + true + make -j2 @@ -333,7 +343,6 @@ make - tests/testBayesTree.run true false @@ -341,7 +350,6 @@ make - testBinaryBayesNet.run true false @@ -389,7 +397,6 @@ make - testSymbolicBayesNet.run true false @@ -397,7 +404,6 @@ make - tests/testSymbolicFactor.run true false @@ -405,7 +411,6 @@ make - testSymbolicFactorGraph.run true false @@ -421,20 +426,11 @@ make - tests/testBayesTree true false true - - make - -j2 - testGaussianFactor.run - true - true - true - make -j5 @@ -531,22 +527,6 @@ false true - - make - -j2 - tests/testPose2.run - true - true - true - - - make - -j2 - tests/testPose3.run - true - true - true - make -j2 @@ -563,6 +543,22 @@ true true + + make + -j2 + tests/testPose2.run + true + true + true + + + make + -j2 + tests/testPose3.run + true + true + true + make -j2 @@ -587,26 +583,42 @@ true true - + make - -j2 - all + -j5 + testValues.run true true true - + make - -j2 - check + -j5 + testOrdering.run true true true - + make - -j2 - clean + -j5 + testKey.run + true + true + true + + + make + -j5 + testLinearContainerFactor.run + true + true + true + + + make + -j5 + testWhiteNoiseFactor.run true true true @@ -643,34 +655,26 @@ true true - + make - -j5 - testValues.run + -j2 + all true true true - + make - -j5 - testOrdering.run + -j2 + check true true true - + make - -j5 - testKey.run - true - true - true - - - make - -j5 - testLinearContainerFactor.run + -j2 + clean true true true @@ -1037,7 +1041,6 @@ make - testGraph.run true false @@ -1045,7 +1048,6 @@ make - testJunctionTree.run true false @@ -1053,7 +1055,6 @@ make - testSymbolicBayesNetB.run true false @@ -1229,7 +1230,6 @@ make - testErrors.run true false @@ -1275,6 +1275,14 @@ true true + + make + -j2 + testGaussianFactor.run + true + true + true + make -j2 @@ -1355,14 +1363,6 @@ true true - - make - -j2 - testGaussianFactor.run - true - true - true - make -j2 @@ -1677,6 +1677,7 @@ make + testSimulated2DOriented.run true false @@ -1716,6 +1717,7 @@ make + testSimulated2D.run true false @@ -1723,6 +1725,7 @@ make + testSimulated3D.run true false @@ -1922,6 +1925,7 @@ make + tests/testGaussianISAM2 true false @@ -1943,6 +1947,102 @@ true true + + make + -j2 + testRot3.run + true + true + true + + + make + -j2 + testRot2.run + true + true + true + + + make + -j2 + testPose3.run + true + true + true + + + make + -j2 + timeRot3.run + true + true + true + + + make + -j2 + testPose2.run + true + true + true + + + make + -j2 + testCal3_S2.run + true + true + true + + + make + -j2 + testSimpleCamera.run + true + true + true + + + make + -j2 + testHomography2.run + true + true + true + + + make + -j2 + testCalibratedCamera.run + true + true + true + + + make + -j2 + check + true + true + true + + + make + -j2 + clean + true + true + true + + + make + -j2 + testPoint2.run + true + true + true + make -j3 @@ -2144,7 +2244,6 @@ cpack - -G DEB true false @@ -2152,7 +2251,6 @@ cpack - -G RPM true false @@ -2160,7 +2258,6 @@ cpack - -G TGZ true false @@ -2168,7 +2265,6 @@ cpack - --config CPackSourceConfig.cmake true false @@ -2310,98 +2406,34 @@ true true - + make - -j2 - testRot3.run + -j5 + testSpirit.run true true true - + make - -j2 - testRot2.run + -j5 + testWrap.run true true true - + make - -j2 - testPose3.run + -j5 + check.wrap true true true - + make - -j2 - timeRot3.run - true - true - true - - - make - -j2 - testPose2.run - true - true - true - - - make - -j2 - testCal3_S2.run - true - true - true - - - make - -j2 - testSimpleCamera.run - true - true - true - - - make - -j2 - testHomography2.run - true - true - true - - - make - -j2 - testCalibratedCamera.run - true - true - true - - - make - -j2 - check - true - true - true - - - make - -j2 - clean - true - true - true - - - make - -j2 - testPoint2.run + -j5 + wrap true true true @@ -2445,38 +2477,6 @@ false true - - make - -j5 - testSpirit.run - true - true - true - - - make - -j5 - testWrap.run - true - true - true - - - make - -j5 - check.wrap - true - true - true - - - make - -j5 - wrap - true - true - true - diff --git a/gtsam/nonlinear/WhiteNoiseFactor.h b/gtsam/nonlinear/WhiteNoiseFactor.h index abe0598df..26e20ac08 100644 --- a/gtsam/nonlinear/WhiteNoiseFactor.h +++ b/gtsam/nonlinear/WhiteNoiseFactor.h @@ -32,22 +32,21 @@ namespace gtsam { * This factor uses the mean-precision parameterization. * * Takes three template arguments: - * MKEY: key type to use for mean - * PKEY: key type to use for precision - * VALUES: Values type for optimization + * Key: key type to use for mean + * Key: key type to use for precision + * Values: Values type for optimization * \nosubgrouping */ - template - class WhiteNoiseFactor: public NonlinearFactor { + class WhiteNoiseFactor: public NonlinearFactor { private: double z_; ///< Measurement - MKEY meanKey_; ///< key by which to access mean variable - PKEY precisionKey_; ///< key by which to access precision variable + Key meanKey_; ///< key by which to access mean variable + Key precisionKey_; ///< key by which to access precision variable - typedef NonlinearFactor Base; + typedef NonlinearFactor Base; public: @@ -93,7 +92,7 @@ namespace gtsam { * @param meanKey Key for mean variable * @param precisionKey Key for precision variable */ - WhiteNoiseFactor(double z, const MKEY& meanKey, const PKEY& precisionKey) : + WhiteNoiseFactor(double z, Key meanKey, Key precisionKey) : Base(), z_(z), meanKey_(meanKey), precisionKey_(precisionKey) { } @@ -110,8 +109,9 @@ namespace gtsam { /// @{ /// Print - void print(const std::string& p = "WhiteNoiseFactor") const { - Base::print(p); + void print(const std::string& p = "WhiteNoiseFactor", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { + Base::print(p, keyFormatter); std::cout << p + ".z: " << z_ << std::endl; } @@ -125,8 +125,8 @@ namespace gtsam { } /// Calculate the error of the factor, typically equal to log-likelihood - inline double error(const VALUES& x) const { - return f(z_, x[meanKey_].value(), x[precisionKey_].value()); + inline double error(const Values& x) const { + return f(z_, x.at(meanKey_), x.at(precisionKey_)); } /** @@ -136,7 +136,7 @@ namespace gtsam { * Here we shoehorn sqrt(2*error(p)) * TODO: Where is this used? should disappear. */ - virtual Vector unwhitenedError(const VALUES& x) const { + virtual Vector unwhitenedError(const Values& x) const { return Vector_(1, sqrt(2 * error(x))); } @@ -154,19 +154,20 @@ namespace gtsam { /// @{ /// linearize returns a Hessianfactor that is an approximation of error(p) - virtual boost::shared_ptr linearize(const VALUES& x, + virtual boost::shared_ptr linearize(const Values& x, const Ordering& ordering) const { - double u = x[meanKey_].value(); - double p = x[precisionKey_].value(); + double u = x.at(meanKey_); + double p = x.at(precisionKey_); Index j1 = ordering[meanKey_]; Index j2 = ordering[precisionKey_]; return linearize(z_, u, p, j1, j2); } - /// @return a deep copy of this factor - virtual gtsam::NonlinearFactor::shared_ptr clone() const { - return boost::static_pointer_cast( - gtsam::NonlinearFactor::shared_ptr(new This(*this))); } + // TODO: Frank commented this out for now, can it go? + // /// @return a deep copy of this factor + // virtual gtsam::NonlinearFactor::shared_ptr clone() const { + // return boost::static_pointer_cast( + // gtsam::NonlinearFactor::shared_ptr(new This(*this))); } /// @} diff --git a/gtsam/nonlinear/tests/testWhiteNoiseFactor.cpp b/gtsam/nonlinear/tests/testWhiteNoiseFactor.cpp new file mode 100644 index 000000000..a141641e3 --- /dev/null +++ b/gtsam/nonlinear/tests/testWhiteNoiseFactor.cpp @@ -0,0 +1,38 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file testWhiteNoiseFactor.cpp + * @author Frank Dellaert + */ + +#include +#include + +#include +#include // for operator += +using namespace boost::assign; + +using namespace gtsam; +using namespace std; + +/* ************************************************************************* */ +TEST( WhiteNoiseFactor, constructor ) +{ + double z = 0.1; + Key meanKey=1, precisionKey=2; + WhiteNoiseFactor factor(z,meanKey, precisionKey); + LONGS_EQUAL(2,factor.dim()); +} + +/* ************************************************************************* */ +int main() { TestResult tr; return TestRegistry::runAllTests(tr); } +/* ************************************************************************* */