diff --git a/cpp/NonlinearFactorGraph-inl.h b/cpp/NonlinearFactorGraph-inl.h index a7bdff8e8..b0dce3ede 100644 --- a/cpp/NonlinearFactorGraph-inl.h +++ b/cpp/NonlinearFactorGraph-inl.h @@ -12,8 +12,19 @@ #include "GaussianFactorGraph.h" #include "NonlinearFactorGraph.h" +using namespace std; + namespace gtsam { + /* ************************************************************************* */ + template + Vector NonlinearFactorGraph::error_vector(const Config& c) const { + list errors; + BOOST_FOREACH(typename NonlinearFactorGraph::sharedFactor factor, this->factors_) + errors.push_back(factor->error_vector(c)); + return concatVectors(errors); + } + /* ************************************************************************* */ template double NonlinearFactorGraph::error(const Config& c) const { @@ -21,9 +32,9 @@ namespace gtsam { // iterate over all the factors_ to accumulate the log probabilities BOOST_FOREACH(typename NonlinearFactorGraph::sharedFactor factor, this->factors_) total_error += factor->error(c); - return total_error; } + /* ************************************************************************* */ template boost::shared_ptr NonlinearFactorGraph::linearize_( diff --git a/cpp/NonlinearFactorGraph.h b/cpp/NonlinearFactorGraph.h index 86ffb4bf0..a96006be0 100644 --- a/cpp/NonlinearFactorGraph.h +++ b/cpp/NonlinearFactorGraph.h @@ -31,6 +31,9 @@ namespace gtsam { /** unnormalized error */ double error(const Config& c) const; + /** all individual errors */ + Vector error_vector(const Config& c) const; + /** Unnormalized probability. O(n) */ double probPrime(const Config& c) const { return exp(-0.5 * error(c)); @@ -41,10 +44,11 @@ namespace gtsam { */ GaussianFactorGraph linearize(const Config& config) const; - /** - * shared pointer versions for MATLAB - */ - boost::shared_ptr linearize_(const Config& config) const; + /** + * shared pointer versions for MATLAB + */ + boost::shared_ptr + linearize_(const Config& config) const; };