33 std::cout << (
s.empty() ?
"" :
s +
" ") << std::endl;
34 std::cout <<
"size: " <<
size() << std::endl;
37 ss <<
"factor " <<
i <<
": ";
40 std::cout << std::endl;
49 const std::function<
bool(
const Factor* ,
double ,
50 size_t )>& printCondition)
const {
51 std::cout <<
str <<
"size: " <<
size() << std::endl << std::endl;
57 std::cout <<
"Factor " <<
i <<
": ";
60 ss.str(std::string());
62 if (
auto mf = std::dynamic_pointer_cast<HybridNonlinearFactor>(factor)) {
63 if (factor ==
nullptr) {
64 std::cout <<
"nullptr"
67 factor->print(
ss.str(), keyFormatter);
68 std::cout <<
"error = ";
69 mf->errorTree(
values.nonlinear()).print(
"", keyFormatter);
70 std::cout << std::endl;
73 std::dynamic_pointer_cast<HybridGaussianFactor>(factor)) {
74 if (factor ==
nullptr) {
75 std::cout <<
"nullptr"
78 factor->print(
ss.str(), keyFormatter);
79 std::cout <<
"error = ";
80 gmf->errorTree(
values.continuous()).print(
"", keyFormatter);
81 std::cout << std::endl;
83 }
else if (
auto gm = std::dynamic_pointer_cast<HybridGaussianConditional>(
85 if (factor ==
nullptr) {
86 std::cout <<
"nullptr"
89 factor->print(
ss.str(), keyFormatter);
90 std::cout <<
"error = ";
91 gm->errorTree(
values.continuous()).print(
"", keyFormatter);
92 std::cout << std::endl;
94 }
else if (
auto nf = std::dynamic_pointer_cast<NonlinearFactor>(factor)) {
95 const double errorValue = (factor !=
nullptr ? nf->error(
values) : .0);
96 if (!printCondition(factor.get(), errorValue,
i))
99 if (factor ==
nullptr) {
100 std::cout <<
"nullptr"
103 factor->print(
ss.str(), keyFormatter);
104 std::cout <<
"error = " << errorValue <<
"\n";
106 }
else if (
auto gf = std::dynamic_pointer_cast<GaussianFactor>(factor)) {
107 const double errorValue = (factor !=
nullptr ? gf->error(
values) : .0);
108 if (!printCondition(factor.get(), errorValue,
i))
111 if (factor ==
nullptr) {
112 std::cout <<
"nullptr"
115 factor->print(
ss.str(), keyFormatter);
116 std::cout <<
"error = " << errorValue <<
"\n";
118 }
else if (
auto df = std::dynamic_pointer_cast<DiscreteFactor>(factor)) {
119 if (factor ==
nullptr) {
120 std::cout <<
"nullptr"
123 factor->print(
ss.str(), keyFormatter);
124 std::cout <<
"error = ";
125 df->errorTree().print(
"", keyFormatter);
126 std::cout << std::endl;
140 const Values& continuousValues)
const {
141 using std::dynamic_pointer_cast;
144 auto linearFG = std::make_shared<HybridGaussianFactorGraph>();
146 linearFG->reserve(
size());
155 if (
auto mf = dynamic_pointer_cast<HybridNonlinearFactor>(
f)) {
157 mf->linearize(continuousValues);
158 linearFG->push_back(gmf);
159 }
else if (
auto nlf = dynamic_pointer_cast<NonlinearFactor>(
f)) {
161 linearFG->push_back(gf);
162 }
else if (dynamic_pointer_cast<DiscreteFactor>(
f)) {
164 linearFG->push_back(
f);
165 }
else if (
auto gmf = dynamic_pointer_cast<HybridGaussianFactor>(
f)) {
166 linearFG->push_back(gmf);
167 }
else if (
auto gm = dynamic_pointer_cast<HybridGaussianConditional>(
f)) {
168 linearFG->push_back(gm);
169 }
else if (dynamic_pointer_cast<GaussianFactor>(
f)) {
170 linearFG->push_back(
f);
173 throw std::invalid_argument(
174 std::string(
"HybridNonlinearFactorGraph::linearize: factor type "
189 if (
auto hnf = std::dynamic_pointer_cast<HybridNonlinearFactor>(factor)) {
193 }
else if (
auto nf = std::dynamic_pointer_cast<NonlinearFactor>(factor)) {
198 }
else if (
auto df = std::dynamic_pointer_cast<DiscreteFactor>(factor)) {
203 throw std::runtime_error(
204 "HybridNonlinearFactorGraph::errorTree(Values) not implemented for "
215 const Values& continuousValues)
const {