more descriptive names, get rid of value confusion

release/4.3a0
dellaert 2015-05-11 23:00:50 -07:00
parent 69c31d20e1
commit 8fecac46c0
3 changed files with 15 additions and 12 deletions

View File

@ -135,7 +135,7 @@ T Expression<T>::value(const Values& values,
if (H) {
// Call private version that returns derivatives in H
KeysAndDims pair = keysAndDims();
return value(values, pair.first, pair.second, *H);
return valueAndDerivatives(values, pair.first, pair.second, *H);
} else
// no derivatives needed, just return value
return root_->value(values);
@ -154,8 +154,9 @@ size_t Expression<T>::traceSize() const {
// Private methods:
template<typename T>
T Expression<T>::value(const Values& values, const FastVector<Key>& keys,
const FastVector<int>& dims, std::vector<Matrix>& H) const {
T Expression<T>::valueAndDerivatives(const Values& values,
const FastVector<Key>& keys, const FastVector<int>& dims,
std::vector<Matrix>& H) const {
// H should be pre-allocated
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);
// Call unsafe version
T result = value(values, jacobianMap);
T result = valueAndJacobianMap(values, jacobianMap);
// Copy blocks into the vector of jacobians passed in
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>
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.
// 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

View File

@ -170,7 +170,7 @@ private:
KeysAndDims keysAndDims() const;
/// 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;
/// trace execution, very unsafe
@ -178,10 +178,11 @@ private:
void* traceStorage) const;
/// 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:
friend class ExpressionFactor<T>;
friend class ExpressionFactor<T> ;
friend class internal::ExpressionNode<T>;
// and add tests

View File

@ -65,8 +65,8 @@ public:
*/
virtual Vector unwhitenedError(const Values& x,
boost::optional<std::vector<Matrix>&> H = boost::none) const {
if (H) {
const T value = expression_.value(x, keys_, dims_, *H);
if (H) {
const T value = expression_.valueAndDerivatives(x, keys_, dims_, *H);
return traits<T>::Local(measurement_, value);
} else {
const T value = expression_.value(x);
@ -95,7 +95,7 @@ public:
Ab.matrix().setZero();
// 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
Ab(size()).col(0) = -traits<T>::Local(measurement_, value);
@ -109,5 +109,5 @@ public:
};
// ExpressionFactor
} // \ namespace gtsam
}// \ namespace gtsam