26 throw std::runtime_error(
"NonlinearFactor::error is not implemented");
37 std::cout << s <<
" keys = { ";
39 std::cout << keyFormatter(
key) <<
" ";
41 std::cout <<
"}" << std::endl;
51 const std::map<Key, Key>& rekey_mapping)
const {
53 for (
size_t i = 0;
i < new_factor->size(); ++
i) {
54 Key& cur_key = new_factor->keys()[
i];
55 std::map<Key, Key>::const_iterator mapping = rekey_mapping.find(cur_key);
56 if (mapping != rekey_mapping.end())
57 cur_key = mapping->second;
65 assert(new_keys.size() ==
keys().size());
67 new_factor->keys() = new_keys;
76 noiseModel_->print(
" noise model: ");
98 if (noiseModel && m != noiseModel->dim()) {
99 throw std::invalid_argument(
100 "NoiseModelFactor: NoiseModel has dimension " +
101 std::to_string(noiseModel->dim()) +
102 " instead of " + std::to_string(m) +
".");
108 const Vector b = unwhitenedError(c);
109 check(noiseModel_, b.size());
110 return noiseModel_ ? noiseModel_->whiten(b) :
b;
115 const Vector b = unwhitenedError(c);
116 check(noiseModel_, b.size());
117 return noiseModel_ ? noiseModel_->unweightedWhiten(b) :
b;
124 const Vector b = unwhitenedError(c);
125 check(noiseModel_, b.size());
126 return noiseModel_->weight(b);
138 const Vector b = unwhitenedError(c);
139 check(noiseModel_, b.size());
141 return noiseModel_->loss(noiseModel_->squaredMahalanobisDistance(b));
143 return 0.5 * b.squaredNorm();
155 return std::shared_ptr<JacobianFactor>();
158 std::vector<Matrix>
A(
size());
159 Vector b = -unwhitenedError(x, A);
160 check(noiseModel_, b.size());
164 noiseModel_->WhitenSystem(A, b);
167 std::vector<std::pair<Key, Matrix> > terms(
size());
168 for (
size_t j = 0;
j <
size(); ++
j) {
169 terms[
j].first =
keys()[
j];
170 terms[
j].second.swap(A[
j]);
175 if (noiseModel_ && noiseModel_->isConstrained())
178 std::static_pointer_cast<Constrained>(noiseModel_)->unit()));
const gtsam::Symbol key('X', 0)
virtual double error(const Values &c) const
virtual void print(const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const
print
bool equals(const NonlinearFactor &f, double tol=1e-9) const override
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
Vector unweightedWhitenedError(const Values &c) const
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
std::shared_ptr< Factor > shared_ptr
A shared_ptr to this class.
double weight(const Values &c) const
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< GaussianFactor > linearize(const Values &x) const override
std::shared_ptr< This > shared_ptr
shared_ptr to this class
shared_ptr cloneWithNewNoiseModel(const SharedNoiseModel newNoise) const
std::shared_ptr< This > shared_ptr
SharedNoiseModel noiseModel_
double error(const Values &c) const override
Non-linear factor base classes.
virtual bool active(const Values &) const
std::shared_ptr< This > shared_ptr
virtual shared_ptr rekey(const std::map< Key, Key > &rekey_mapping) const
const KeyVector & keys() const
Access the factor's involved variable keys.
const Values & nonlinear() const
Return the nonlinear values.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
virtual shared_ptr clone() const
static void check(const SharedNoiseModel &noiseModel, size_t m)
Vector whitenedError(const Values &c) const
std::uint64_t Key
Integer nonlinear key type.
noiseModel::Base::shared_ptr SharedNoiseModel
bool equals(const This &other, double tol=1e-9) const
check equality