Go to the documentation of this file.
32 std::cout << (
s.empty() ?
"" :
s +
" ") << std::endl;
33 std::cout <<
"size: " <<
size() << std::endl;
36 ss <<
"factor " <<
i <<
": ";
39 std::cout << std::endl;
48 const std::function<
bool(
const Factor* ,
double ,
49 size_t )>& printCondition)
const {
50 std::cout <<
str <<
"size: " <<
size() << std::endl << std::endl;
56 std::cout <<
"Factor " <<
i <<
": ";
59 ss.str(std::string());
61 if (
auto mf = std::dynamic_pointer_cast<HybridNonlinearFactor>(
factor)) {
63 std::cout <<
"nullptr"
66 factor->print(
ss.str(), keyFormatter);
67 std::cout <<
"error = ";
68 mf->errorTree(
values.nonlinear()).print(
"", keyFormatter);
69 std::cout << std::endl;
72 std::dynamic_pointer_cast<HybridGaussianFactor>(
factor)) {
74 std::cout <<
"nullptr"
77 factor->print(
ss.str(), keyFormatter);
78 std::cout <<
"error = ";
79 gmf->errorTree(
values.continuous()).print(
"", keyFormatter);
80 std::cout << std::endl;
82 }
else if (
auto gm = std::dynamic_pointer_cast<HybridGaussianConditional>(
85 std::cout <<
"nullptr"
88 factor->print(
ss.str(), keyFormatter);
89 std::cout <<
"error = ";
90 gm->errorTree(
values.continuous()).print(
"", keyFormatter);
91 std::cout << std::endl;
93 }
else if (
auto nf = std::dynamic_pointer_cast<NonlinearFactor>(
factor)) {
94 const double errorValue = (
factor !=
nullptr ? nf->error(
values) : .0);
95 if (!printCondition(
factor.get(), errorValue,
i))
99 std::cout <<
"nullptr"
102 factor->print(
ss.str(), keyFormatter);
103 std::cout <<
"error = " << errorValue <<
"\n";
105 }
else if (
auto gf = std::dynamic_pointer_cast<GaussianFactor>(
factor)) {
106 const double errorValue = (
factor !=
nullptr ? gf->error(
values) : .0);
107 if (!printCondition(
factor.get(), errorValue,
i))
111 std::cout <<
"nullptr"
114 factor->print(
ss.str(), keyFormatter);
115 std::cout <<
"error = " << errorValue <<
"\n";
117 }
else if (
auto df = std::dynamic_pointer_cast<DiscreteFactor>(
factor)) {
119 std::cout <<
"nullptr"
122 factor->print(
ss.str(), keyFormatter);
123 std::cout <<
"error = ";
124 df->errorTree().print(
"", keyFormatter);
125 std::cout << std::endl;
139 const Values& continuousValues)
const {
140 using std::dynamic_pointer_cast;
143 auto linearFG = std::make_shared<HybridGaussianFactorGraph>();
145 linearFG->reserve(
size());
154 if (
auto mf = dynamic_pointer_cast<HybridNonlinearFactor>(
f)) {
156 mf->linearize(continuousValues);
157 linearFG->push_back(gmf);
158 }
else if (
auto nlf = dynamic_pointer_cast<NonlinearFactor>(
f)) {
160 linearFG->push_back(gf);
161 }
else if (dynamic_pointer_cast<DiscreteFactor>(
f)) {
163 linearFG->push_back(
f);
164 }
else if (
auto gmf = dynamic_pointer_cast<HybridGaussianFactor>(
f)) {
165 linearFG->push_back(gmf);
166 }
else if (
auto gm = dynamic_pointer_cast<HybridGaussianConditional>(
f)) {
167 linearFG->push_back(gm);
168 }
else if (dynamic_pointer_cast<GaussianFactor>(
f)) {
169 linearFG->push_back(
f);
172 throw std::invalid_argument(
173 std::string(
"HybridNonlinearFactorGraph::linearize: factor type "
188 if (
auto hnf = std::dynamic_pointer_cast<HybridNonlinearFactor>(
factor)) {
192 }
else if (
auto nf = std::dynamic_pointer_cast<NonlinearFactor>(
factor)) {
197 }
else if (
auto df = std::dynamic_pointer_cast<DiscreteFactor>(
factor)) {
202 throw std::runtime_error(
203 "HybridNonlinearFactorGraph::errorTree(Values) not implemented for "
214 const Values& continuousValues)
const {
226 using std::dynamic_pointer_cast;
236 if (
auto hf = dynamic_pointer_cast<HybridFactor>(
f)) {
237 result.push_back(hf->restrict(discreteValues));
238 }
else if (
auto df = dynamic_pointer_cast<DiscreteFactor>(
f)) {
239 auto restricted_df = df->restrict(discreteValues);
245 if (restricted_df->discreteKeys().size() > 0) {
246 result.push_back(restricted_df);
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.
HybridNonlinearFactorGraph restrict(const DiscreteValues &assignment) const
Restrict all factors in the graph to the given discrete values.
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 Wed May 28 2025 03:01:25