34 class ExpressionFactor:
public NoiseModelFactor {
35 BOOST_CONCEPT_ASSERT((IsTestable<T>));
39 typedef ExpressionFactor<T> This;
40 static const int Dim = traits<T>::dimension;
48 typedef boost::shared_ptr<ExpressionFactor<T> > shared_ptr;
64 void print(
const std::string& s =
"",
65 const KeyFormatter& keyFormatter = DefaultKeyFormatter)
const {
84 boost::optional<std::vector<Matrix>&> H = boost::none)
const {
91 const T value = expression_.
value(x);
99 return boost::shared_ptr<JacobianFactor>();
103 if (noiseModel_ && noiseModel_->isConstrained()) {
105 noiseModel_)->unit();
109 boost::shared_ptr<JacobianFactor> factor(
114 internal::JacobianMap jacobianMap(
keys_, Ab);
127 Vector b = Ab(
size()).col(0);
128 noiseModel_->WhitenSystem(Ab.
matrix(), b);
135 virtual gtsam::NonlinearFactor::shared_ptr
clone()
const {
137 gtsam::NonlinearFactor::shared_ptr(
new This(*
this)));
153 throw std::invalid_argument(
"ExpressionFactor: no NoiseModel.");
154 if (noiseModel_->dim() != Dim)
155 throw std::invalid_argument(
156 "ExpressionFactor was created with a NoiseModel of incorrect dimension.");
161 boost::tie(
keys_, dims_) = expression_.keysAndDims();
167 throw std::runtime_error(
"ExpressionFactor::expression not provided: cannot deserialize.");
172 template <
class Archive>
173 void save(Archive& ar,
const unsigned int )
const {
175 ar << boost::serialization::make_nvp(
"measured_", this->measured_);
180 template <
class Archive>
181 void load(Archive& ar,
const unsigned int ) {
183 ar >> boost::serialization::make_nvp(
"measured_", this->measured_);
188 BOOST_SERIALIZATION_SPLIT_MEMBER()
190 friend class boost::serialization::access;
195 template <
typename T>
203 template <
typename T,
typename A1,
typename A2>
211 boost::optional<Matrix&> H1 = boost::none,
212 boost::optional<Matrix&> H2 = boost::none)
const {
216 std::vector<Matrix> H(2);
218 if (H1) (*H1) = H[0];
219 if (H2) (*H2) = H[1];
226 throw std::runtime_error(
"ExpressionFactor2::expression not provided: cannot deserialize.");
236 const T& measurement)
238 this->
keys_.push_back(key1);
239 this->
keys_.push_back(key2);
Expression class that supports automatic differentiation.
Definition: Expression.h:49
ExpressionFactor2()
Default constructor, for serialization.
Definition: ExpressionFactor.h:231
void insert(Key j, const Value &val)
Add a variable with the given j, throws KeyAlreadyExists<J> if j is already present.
Definition: Values.cpp:133
Nonlinear factor base class.
Definition: NonlinearFactor.h:52
A nonlinear sum-of-squares factor with a zero-mean noise model implementing the density Templated on...
Definition: NonlinearFactor.h:163
virtual gtsam::NonlinearFactor::shared_ptr clone() const
Definition: ExpressionFactor.h:135
T valueAndDerivatives(const Values &values, const KeyVector &keys, const FastVector< int > &dims, std::vector< Matrix > &H) const
private version that takes keys and dimensions, returns derivatives
Definition: Expression-inl.h:157
noiseModel::Base::shared_ptr SharedNoiseModel
Note, deliberately not in noiseModel namespace.
Definition: NoiseModel.h:1072
Definition: VerticalBlockMatrix.h:41
virtual double error(const Values &c) const
Calculate the error of the factor.
Definition: NonlinearFactor.cpp:97
virtual bool equals(const NonlinearFactor &f, double tol=1e-9) const
Check if two factors are equal.
Definition: NonlinearFactor.cpp:71
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print relies on Testable traits being defined for T
Definition: ExpressionFactor.h:64
T valueAndJacobianMap(const Values &values, internal::JacobianMap &jacobians) const
brief Return value and derivatives, reverse AD version
Definition: Expression-inl.h:188
Expression< T > expression_
the expression that is AD enabled
Definition: ExpressionFactor.h:43
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
virtual void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Print.
Definition: NonlinearFactor.cpp:63
virtual boost::shared_ptr< GaussianFactor > linearize(const Values &x) const
linearize to a GaussianFactor
Definition: ExpressionFactor.h:96
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
size_t size() const
Definition: Factor.h:126
const SharedNoiseModel & noiseModel() const
access to the noise model
Definition: NonlinearFactor.h:212
FastVector< int > dims_
dimensions of the Jacobian matrices
Definition: ExpressionFactor.h:44
virtual Expression< T > expression() const
Recreate expression from keys_ and measured_, used in load below.
Definition: ExpressionFactor.h:166
Binary specialization of ExpressionFactor meant as a base class for binary factors Enforces expressio...
Definition: ExpressionFactor.h:204
const Matrix & matrix() const
Access to full matrix (including any portions excluded by rowStart(), rowEnd(), and firstBlock()) ...
Definition: VerticalBlockMatrix.h:187
ExpressionFactor(const SharedNoiseModel &noiseModel, const T &measurement)
Default constructor, for serialization.
Definition: ExpressionFactor.h:145
ExpressionFactor(const SharedNoiseModel &noiseModel, const T &measurement, const Expression< T > &expression)
Constructor.
Definition: ExpressionFactor.h:51
virtual bool active(const Values &) const
Checks whether a factor should be used based on a set of values.
Definition: NonlinearFactor.h:115
virtual ~ExpressionFactor()
Destructor.
Definition: ExpressionFactor.h:58
FastVector< Key > keys_
The keys involved in this factor.
Definition: Factor.h:69
ExpressionFactor2(Key key1, Key key2, const SharedNoiseModel &noiseModel, const T &measurement)
Constructor takes care of keys, but still need to call initialize.
Definition: ExpressionFactor.h:234
T value(const Values &values, boost::optional< std::vector< Matrix > & > H=boost::none) const
Return value and optional derivatives, reverse AD version Notes: this is not terribly efficient...
Definition: Expression-inl.h:132
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
bool equals(const NonlinearFactor &f, double tol) const
equals relies on Testable traits being defined for T
Definition: ExpressionFactor.h:71
const T & measured() const
return the measurement
Definition: ExpressionFactor.h:61
Factor that supports arbitrary expressions via AD.
Definition: Expression.h:38
virtual Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const
Error function without the NoiseModel, .
Definition: ExpressionFactor.h:83
virtual Expression< T > expression(Key key1, Key key2) const
Recreate expression from given keys_ and measured_, used in load Needed to deserialize a derived fact...
Definition: ExpressionFactor.h:225
void initialize(const Expression< T > &expression)
Initialize with constructor arguments.
Definition: ExpressionFactor.h:151
A Constrained constrained model is a specialization of Diagonal which allows some or all of the sigma...
Definition: NoiseModel.h:372
virtual ~ExpressionFactor2()
Destructor.
Definition: ExpressionFactor.h:207
Non-linear factor base classes.
Vector evaluateError(const A1 &a1, const A2 &a2, boost::optional< Matrix & > H1=boost::none, boost::optional< Matrix & > H2=boost::none) const
Backwards compatible evaluateError, to make existing tests compile.
Definition: ExpressionFactor.h:210
A Gaussian factor in the squared-error form.
Definition: JacobianFactor.h:87
Expressions for Block Automatic Differentiation.
T measured_
the measurement to be compared with the expression
Definition: ExpressionFactor.h:42
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
Concept check for values that can be used in unit tests.