Made error a method again: all checks, let me know if project throw errors

release/4.3a0
Frank Dellaert 2011-10-21 05:36:30 +00:00
parent ce5751e454
commit 8535b13809
2 changed files with 21 additions and 24 deletions

View File

@ -32,17 +32,6 @@ namespace gtsam {
struct SharedDiagonal;
/** unnormalized error
* \todo Make this a member function - affects SubgraphPreconditioner */
template<class FACTOR>
double gaussianError(const FactorGraph<FACTOR>& fg, const VectorValues& x) {
double total_error = 0.;
BOOST_FOREACH(const typename FACTOR::shared_ptr& factor, fg) {
total_error += factor->error(x);
}
return total_error;
}
/** return A*x-b
* \todo Make this a member function - affects SubgraphPreconditioner */
template<class FACTOR>
@ -131,9 +120,17 @@ namespace gtsam {
/** Permute the variables in the factors */
void permuteWithInverse(const Permutation& inversePermutation);
/** unnormalized error */
double error(const VectorValues& x) const {
double total_error = 0.;
BOOST_FOREACH(const sharedFactor& factor, *this)
total_error += factor->error(x);
return total_error;
}
/** Unnormalized probability. O(n) */
double probPrime(const VectorValues& c) const {
return exp(-0.5 * gaussianError(*this, c));
return exp(-0.5 * error(c));
}
/**

View File

@ -54,17 +54,17 @@ TEST( GaussianFactorGraph, equals ) {
}
/* ************************************************************************* */
TEST( GaussianFactorGraph, error ) {
Ordering ordering; ordering += "x1","x2","l1";
FactorGraph<JacobianFactor> fg = createGaussianFactorGraph(ordering);
VectorValues cfg = createZeroDelta(ordering);
// note the error is the same as in testNonlinearFactorGraph as a
// zero delta config in the linear graph is equivalent to noisy in
// non-linear, which is really linear under the hood
double actual = gaussianError(fg, cfg);
DOUBLES_EQUAL( 5.625, actual, 1e-9 );
}
//TEST( GaussianFactorGraph, error ) {
// Ordering ordering; ordering += "x1","x2","l1";
// FactorGraph<JacobianFactor> fg = createGaussianFactorGraph(ordering);
// VectorValues cfg = createZeroDelta(ordering);
//
// // note the error is the same as in testNonlinearFactorGraph as a
// // zero delta config in the linear graph is equivalent to noisy in
// // non-linear, which is really linear under the hood
// double actual = fg.error(cfg);
// DOUBLES_EQUAL( 5.625, actual, 1e-9 );
//}
/* ************************************************************************* */
/* unit test for find seperator */
@ -666,7 +666,7 @@ double error(const VectorValues& x) {
Ordering ord; ord += "x2","l1","x1";
GaussianFactorGraph fg = createGaussianFactorGraph(ord);
return gaussianError(fg,x);
return fg.error(x);
}
///* ************************************************************************* */