more descriptive names, get rid of value confusion
parent
69c31d20e1
commit
8fecac46c0
|
|
@ -135,7 +135,7 @@ T Expression<T>::value(const Values& values,
|
||||||
if (H) {
|
if (H) {
|
||||||
// Call private version that returns derivatives in H
|
// Call private version that returns derivatives in H
|
||||||
KeysAndDims pair = keysAndDims();
|
KeysAndDims pair = keysAndDims();
|
||||||
return value(values, pair.first, pair.second, *H);
|
return valueAndDerivatives(values, pair.first, pair.second, *H);
|
||||||
} else
|
} else
|
||||||
// no derivatives needed, just return value
|
// no derivatives needed, just return value
|
||||||
return root_->value(values);
|
return root_->value(values);
|
||||||
|
|
@ -154,8 +154,9 @@ size_t Expression<T>::traceSize() const {
|
||||||
// Private methods:
|
// Private methods:
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Expression<T>::value(const Values& values, const FastVector<Key>& keys,
|
T Expression<T>::valueAndDerivatives(const Values& values,
|
||||||
const FastVector<int>& dims, std::vector<Matrix>& H) const {
|
const FastVector<Key>& keys, const FastVector<int>& dims,
|
||||||
|
std::vector<Matrix>& H) const {
|
||||||
|
|
||||||
// H should be pre-allocated
|
// H should be pre-allocated
|
||||||
assert(H.size()==keys.size());
|
assert(H.size()==keys.size());
|
||||||
|
|
@ -167,7 +168,7 @@ T Expression<T>::value(const Values& values, const FastVector<Key>& keys,
|
||||||
internal::JacobianMap jacobianMap(keys, Ab);
|
internal::JacobianMap jacobianMap(keys, Ab);
|
||||||
|
|
||||||
// Call unsafe version
|
// Call unsafe version
|
||||||
T result = value(values, jacobianMap);
|
T result = valueAndJacobianMap(values, jacobianMap);
|
||||||
|
|
||||||
// Copy blocks into the vector of jacobians passed in
|
// Copy blocks into the vector of jacobians passed in
|
||||||
for (DenseIndex i = 0; i < static_cast<DenseIndex>(keys.size()); i++)
|
for (DenseIndex i = 0; i < static_cast<DenseIndex>(keys.size()); i++)
|
||||||
|
|
@ -184,7 +185,8 @@ T Expression<T>::traceExecution(const Values& values,
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Expression<T>::value(const Values& values, internal::JacobianMap& jacobians) const {
|
T Expression<T>::valueAndJacobianMap(const Values& values,
|
||||||
|
internal::JacobianMap& jacobians) const {
|
||||||
// The following piece of code is absolutely crucial for performance.
|
// The following piece of code is absolutely crucial for performance.
|
||||||
// We allocate a block of memory on the stack, which can be done at runtime
|
// We allocate a block of memory on the stack, which can be done at runtime
|
||||||
// with modern C++ compilers. The traceExecution then fills this memory
|
// with modern C++ compilers. The traceExecution then fills this memory
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ private:
|
||||||
KeysAndDims keysAndDims() const;
|
KeysAndDims keysAndDims() const;
|
||||||
|
|
||||||
/// private version that takes keys and dimensions, returns derivatives
|
/// private version that takes keys and dimensions, returns derivatives
|
||||||
T value(const Values& values, const FastVector<Key>& keys,
|
T valueAndDerivatives(const Values& values, const FastVector<Key>& keys,
|
||||||
const FastVector<int>& dims, std::vector<Matrix>& H) const;
|
const FastVector<int>& dims, std::vector<Matrix>& H) const;
|
||||||
|
|
||||||
/// trace execution, very unsafe
|
/// trace execution, very unsafe
|
||||||
|
|
@ -178,10 +178,11 @@ private:
|
||||||
void* traceStorage) const;
|
void* traceStorage) const;
|
||||||
|
|
||||||
/// brief Return value and derivatives, reverse AD version
|
/// brief Return value and derivatives, reverse AD version
|
||||||
T value(const Values& values, internal::JacobianMap& jacobians) const;
|
T valueAndJacobianMap(const Values& values,
|
||||||
|
internal::JacobianMap& jacobians) const;
|
||||||
|
|
||||||
// be very selective on who can access these private methods:
|
// be very selective on who can access these private methods:
|
||||||
friend class ExpressionFactor<T>;
|
friend class ExpressionFactor<T> ;
|
||||||
friend class internal::ExpressionNode<T>;
|
friend class internal::ExpressionNode<T>;
|
||||||
|
|
||||||
// and add tests
|
// and add tests
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual Vector unwhitenedError(const Values& x,
|
virtual Vector unwhitenedError(const Values& x,
|
||||||
boost::optional<std::vector<Matrix>&> H = boost::none) const {
|
boost::optional<std::vector<Matrix>&> H = boost::none) const {
|
||||||
if (H) {
|
if (H) {
|
||||||
const T value = expression_.value(x, keys_, dims_, *H);
|
const T value = expression_.valueAndDerivatives(x, keys_, dims_, *H);
|
||||||
return traits<T>::Local(measurement_, value);
|
return traits<T>::Local(measurement_, value);
|
||||||
} else {
|
} else {
|
||||||
const T value = expression_.value(x);
|
const T value = expression_.value(x);
|
||||||
|
|
@ -95,7 +95,7 @@ public:
|
||||||
Ab.matrix().setZero();
|
Ab.matrix().setZero();
|
||||||
|
|
||||||
// Get value and Jacobians, writing directly into JacobianFactor
|
// Get value and Jacobians, writing directly into JacobianFactor
|
||||||
T value = expression_.value(x, jacobianMap); // <<< Reverse AD happens here !
|
T value = expression_.valueAndJacobianMap(x, jacobianMap); // <<< Reverse AD happens here !
|
||||||
|
|
||||||
// Evaluate error and set RHS vector b
|
// Evaluate error and set RHS vector b
|
||||||
Ab(size()).col(0) = -traits<T>::Local(measurement_, value);
|
Ab(size()).col(0) = -traits<T>::Local(measurement_, value);
|
||||||
|
|
@ -109,5 +109,5 @@ public:
|
||||||
};
|
};
|
||||||
// ExpressionFactor
|
// ExpressionFactor
|
||||||
|
|
||||||
} // \ namespace gtsam
|
}// \ namespace gtsam
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue