CustomFactor.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 
20 namespace gtsam {
21 
22 /*
23  * Calculates the unwhitened error by invoking the callback functor (i.e. from Python).
24  */
26  if(this->active(x)) {
27 
28  if(H) {
29  /*
30  * In this case, we pass the raw pointer to the `std::vector<Matrix>` object directly to pybind.
31  * As the type `std::vector<Matrix>` has been marked as opaque in `preamble/custom.h`, any changes in
32  * Python will be immediately reflected on the C++ side.
33  *
34  * Example:
35  * ```
36  * def error_func(this: CustomFactor, v: gtsam.Values, H: List[np.ndarray]):
37  * <calculated error>
38  * if not H is None:
39  * <calculate the Jacobian>
40  * H[0] = J1
41  * H[1] = J2
42  * ...
43  * return error
44  * ```
45  */
46  return this->error_function_(*this, x, H);
47  } else {
48  /*
49  * In this case, we pass the a `nullptr` to pybind, and it will translate to `None` in Python.
50  * Users can check for `None` in their callback to determine if the Jacobian is requested.
51  */
52  return this->error_function_(*this, x, nullptr);
53  }
54  } else {
55  return Vector::Zero(this->dim());
56  }
57 }
58 
59 void CustomFactor::print(const std::string &s, const KeyFormatter &keyFormatter) const {
60  std::cout << s << "CustomFactor on ";
61  auto keys_ = this->keys();
62  bool f = false;
63  for (const Key &k: keys_) {
64  if (f)
65  std::cout << ", ";
66  std::cout << keyFormatter(k);
67  f = true;
68  }
69  std::cout << "\n";
70  if (this->noiseModel_)
71  this->noiseModel_->print(" noise model: ");
72  else
73  std::cout << "no noise model" << std::endl;
74 }
75 
76 }
std::vector< Matrix > * OptionalMatrixVecType
size_t dim() const override
void print(const std::string &s, const KeyFormatter &keyFormatter=DefaultKeyFormatter) const override
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:87
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 y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate set rrange [*:*] noreverse nowriteback set trange [*:*] noreverse nowriteback set urange [*:*] noreverse nowriteback set vrange [*:*] noreverse nowriteback set xlabel matrix size set x2label set timefmt d m y n H
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
Eigen::VectorXd Vector
Definition: Vector.h:38
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar s
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
traits
Definition: chartTesting.h:28
SharedNoiseModel noiseModel_
virtual bool active(const Values &) const
CustomErrorFunction error_function_
Definition: CustomFactor.h:47
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:142
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
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
Class to enable arbitrary factors with runtime swappable error function.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:06