36 template <
class FACTOR>
39 std::cout << (s.empty() ?
"" : s +
" ") << std::endl;
40 std::cout <<
"size: " <<
size() << std::endl;
41 for (
size_t i = 0;
i < factors_.size();
i++) {
43 ss <<
"factor " <<
i <<
": ";
44 if (factors_[i]) factors_[
i]->print(ss.str(),
formatter);
49 template <
class FACTOR>
52 if (factors_.size() != fg.
size())
return false;
55 for (
size_t i = 0;
i < factors_.size();
i++) {
57 if (f1 ==
nullptr && f2 ==
nullptr)
continue;
58 if (f1 ==
nullptr || f2 ==
nullptr)
return false;
59 if (!f1->equals(*f2, tol))
return false;
65 template <
class FACTOR>
68 for (
auto &
f : factors_) {
69 error +=
f->error(values);
75 template <
class FACTOR>
84 template <
class FACTOR>
88 if (factor) keys.insert(factor->begin(), factor->end());
94 template <
class FACTOR>
97 keys.reserve(2 *
size());
99 if (factor) keys.insert(keys.end(), factor->begin(), factor->end());
100 std::sort(keys.begin(), keys.end());
101 auto last = std::unique(keys.begin(), keys.end());
102 keys.erase(last, keys.end());
107 template <
class FACTOR>
108 template <
typename CONTAINER,
typename>
110 bool useEmptySlots) {
111 const size_t num_factors = factors.size();
115 for (
size_t j = 0;
j < num_factors; ++
j) {
129 newFactorIndices[
j] =
i;
133 for (
size_t i = 0;
i < num_factors; ++
i) newFactorIndices[
i] =
i +
size();
136 return newFactorIndices;
140 template <
class FACTOR>
154 for (
size_t i = 0;
i <
size(); ++
i) {
155 const auto& factor = at(
i);
157 const KeyVector& factorKeys = factor->keys();
167 template <
class FACTOR>
170 std::stringstream
ss;
171 dot(ss, keyFormatter, writer);
176 template <
class FACTOR>
180 std::ofstream of(filename.c_str());
181 dot(of, keyFormatter, writer);
const gtsam::Symbol key('X', 0)
void processFactor(size_t i, const KeyVector &keys, const KeyFormatter &keyFormatter, const std::optional< Vector2 > &position, std::ostream *os) const
Draw a single factor, specified by its index i and its variable keys.
bool equals(const This &fg, double tol=1e-9) const
Check equality up to tolerance.
KeyVector keyVector() const
double dot(const V1 &a, const V2 &b)
FactorIndices add_factors(const CONTAINER &factors, bool useEmptySlots=false)
const GaussianFactorGraph factors
double f2(const Vector2 &x)
std::optional< Vector2 > variablePos(Key key) const
Return variable position or none.
virtual void print(const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const
Print out graph to std::cout, with optional key formatter.
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
void graphPreamble(std::ostream *os) const
Write out preamble for graph, including size.
const KeyFormatter & formatter
void saveGraph(const std::string &filename, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const
output to file with graphviz format.
FastVector< FactorIndex > FactorIndices
Define collection types:
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
void dot(std::ostream &os, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DotWriter &writer=DotWriter()) const
Output to graphviz format, stream version.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
static std::stringstream ss
DotWriter is a helper class for writing graphviz .dot files.
void drawVariable(Key key, const KeyFormatter &keyFormatter, const std::optional< Vector2 > &position, std::ostream *os) const
Create a variable dot fragment.
ofstream os("timeSchurFactors.csv")
Point2 f1(const Point3 &p, OptionalJacobian< 2, 3 > H)
Point3_ position(const NavState_ &X)
std::shared_ptr< NonlinearFactor > sharedFactor
Shared pointer to a factor.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
double error(const HybridValues &values) const
FastVector< sharedFactor > factors_
std::uint64_t Key
Integer nonlinear key type.