Go to the documentation of this file.
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)) {
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)) {
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>(
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))
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))
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)) {
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 {
std::shared_ptr< This > shared_ptr
shared_ptr to This
FastVector< sharedFactor > factors_
void print(const std::string &s="HybridNonlinearFactorGraph", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Print the factor graph.
A hybrid conditional in the Conditional Linear Gaussian scheme.
double error(const HybridValues &values) const
std::shared_ptr< This > shared_ptr
Nonlinear hybrid factor graph that uses type erasure.
void printErrors(const HybridValues &values, const std::string &str="HybridNonlinearFactorGraph: ", const KeyFormatter &keyFormatter=DefaultKeyFormatter, const std::function< bool(const Factor *, double, size_t)> &printCondition=[](const Factor *, double, size_t) { return true;}) const
AlgebraicDecisionTree< Key > discretePosterior(const Values &continuousValues) const
Computer posterior P(M|X=x) when all continuous values X are given. This is efficient as this simply ...
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
AlgebraicDecisionTree< Key > errorTree(const Values &values) const
Compute error of (hybrid) nonlinear factors and discrete factors over each discrete assignment,...
DecisionTreeFactor factor(D &C &B &A, "0.0 0.0 0.0 0.60658897 0.61241912 0.61241969 0.61247685 0.61247742 0.0 " "0.0 0.0 0.99995287 1.0 1.0 1.0 1.0")
static std::stringstream ss
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
std::shared_ptr< This > shared_ptr
shared_ptr to this class
DecisionTree apply(const Unary &op) const
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Non-linear factor base classes.
A set of nonlinear factors indexed by a set of discrete keys.
Linearized Hybrid factor graph that uses type erasure.
std::string demangle(const char *name)
Pretty print Value type name.
std::shared_ptr< HybridGaussianFactorGraph > linearize(const Values &continuousValues) const
Linearize all the continuous factors in the HybridNonlinearFactorGraph.
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:40