Merge pull request #916 from borglab/feature/gfg-printErrors
Add printErrors method to GaussianFactorGraphrelease/4.3a0
commit
1b1ea146ac
|
@ -510,4 +510,33 @@ namespace gtsam {
|
|||
return optimize(function);
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void GaussianFactorGraph::printErrors(
|
||||
const VectorValues& values, const std::string& str,
|
||||
const KeyFormatter& keyFormatter,
|
||||
const std::function<bool(const Factor* /*factor*/,
|
||||
double /*whitenedError*/, size_t /*index*/)>&
|
||||
printCondition) const {
|
||||
cout << str << "size: " << size() << endl << endl;
|
||||
for (size_t i = 0; i < (*this).size(); i++) {
|
||||
const sharedFactor& factor = (*this)[i];
|
||||
const double errorValue =
|
||||
(factor != nullptr ? (*this)[i]->error(values) : .0);
|
||||
if (!printCondition(factor.get(), errorValue, i))
|
||||
continue; // User-provided filter did not pass
|
||||
|
||||
stringstream ss;
|
||||
ss << "Factor " << i << ": ";
|
||||
if (factor == nullptr) {
|
||||
cout << "nullptr"
|
||||
<< "\n";
|
||||
} else {
|
||||
factor->print(ss.str(), keyFormatter);
|
||||
cout << "error = " << errorValue << "\n";
|
||||
}
|
||||
cout << endl; // only one "endl" at end might be faster, \n for each
|
||||
// factor
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gtsam
|
||||
|
|
|
@ -375,6 +375,14 @@ namespace gtsam {
|
|||
/** In-place version e <- A*x that takes an iterator. */
|
||||
void multiplyInPlace(const VectorValues& x, const Errors::iterator& e) const;
|
||||
|
||||
void printErrors(
|
||||
const VectorValues& x,
|
||||
const std::string& str = "GaussianFactorGraph: ",
|
||||
const KeyFormatter& keyFormatter = DefaultKeyFormatter,
|
||||
const std::function<bool(const Factor* /*factor*/,
|
||||
double /*whitenedError*/, size_t /*index*/)>&
|
||||
printCondition =
|
||||
[](const Factor*, double, size_t) { return true; }) const;
|
||||
/// @}
|
||||
|
||||
private:
|
||||
|
|
|
@ -401,6 +401,7 @@ class GaussianFactorGraph {
|
|||
// error and probability
|
||||
double error(const gtsam::VectorValues& c) const;
|
||||
double probPrime(const gtsam::VectorValues& c) const;
|
||||
void printErrors(const gtsam::VectorValues& c, string str = "GaussianFactorGraph: ", const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter) const;
|
||||
|
||||
gtsam::GaussianFactorGraph clone() const;
|
||||
gtsam::GaussianFactorGraph negate() const;
|
||||
|
|
Loading…
Reference in New Issue