Added hessianDiagonal; works for Gaussian factor graphs with JacobianFactors
parent
4b7de1abb8
commit
76959d4d18
|
|
@ -96,6 +96,9 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
virtual Matrix information() const = 0;
|
virtual Matrix information() const = 0;
|
||||||
|
|
||||||
|
/// Return the diagonal of the Hessian for this factor
|
||||||
|
virtual VectorValues hessianDiagonal() const = 0;
|
||||||
|
|
||||||
/** Clone a factor (make a deep copy) */
|
/** Clone a factor (make a deep copy) */
|
||||||
virtual GaussianFactor::shared_ptr clone() const = 0;
|
virtual GaussianFactor::shared_ptr clone() const = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,16 @@ namespace gtsam {
|
||||||
augmented.col(augmented.rows() - 1).head(augmented.rows() - 1));
|
augmented.col(augmented.rows() - 1).head(augmented.rows() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
VectorValues GaussianFactorGraph::hessianDiagonal() const {
|
||||||
|
VectorValues d;
|
||||||
|
BOOST_FOREACH(const sharedFactor& factor, *this) {
|
||||||
|
VectorValues di = factor->hessianDiagonal();
|
||||||
|
d.addInPlace_(di);
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
VectorValues GaussianFactorGraph::optimize(OptionalOrdering ordering, const Eliminate& function) const
|
VectorValues GaussianFactorGraph::optimize(OptionalOrdering ordering, const Eliminate& function) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,9 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
std::pair<Matrix,Vector> hessian(boost::optional<const Ordering&> optionalOrdering = boost::none) const;
|
std::pair<Matrix,Vector> hessian(boost::optional<const Ordering&> optionalOrdering = boost::none) const;
|
||||||
|
|
||||||
|
/** Return only the diagonal of the Hessian A'*A, as a VectorValues */
|
||||||
|
VectorValues hessianDiagonal() const;
|
||||||
|
|
||||||
/** Solve the factor graph by performing multifrontal variable elimination in COLAMD order using
|
/** Solve the factor graph by performing multifrontal variable elimination in COLAMD order using
|
||||||
* the dense elimination function specified in \c function (default EliminatePreferCholesky),
|
* the dense elimination function specified in \c function (default EliminatePreferCholesky),
|
||||||
* followed by back-substitution in the Bayes tree resulting from elimination. Is equivalent
|
* followed by back-substitution in the Bayes tree resulting from elimination. Is equivalent
|
||||||
|
|
|
||||||
|
|
@ -351,6 +351,12 @@ Matrix HessianFactor::information() const
|
||||||
return info_.range(0, this->size(), 0, this->size()).selfadjointView();
|
return info_.range(0, this->size(), 0, this->size()).selfadjointView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
VectorValues HessianFactor::hessianDiagonal() const {
|
||||||
|
VectorValues d;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Matrix HessianFactor::augmentedJacobian() const
|
Matrix HessianFactor::augmentedJacobian() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -336,6 +336,9 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
virtual Matrix information() const;
|
virtual Matrix information() const;
|
||||||
|
|
||||||
|
/// Return the diagonal of the Hessian for this factor
|
||||||
|
virtual VectorValues hessianDiagonal() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return (dense) matrix associated with factor
|
* Return (dense) matrix associated with factor
|
||||||
* @param ordering of variables needed for matrix column order
|
* @param ordering of variables needed for matrix column order
|
||||||
|
|
|
||||||
|
|
@ -438,6 +438,23 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
VectorValues JacobianFactor::hessianDiagonal() const {
|
||||||
|
VectorValues d;
|
||||||
|
for(size_t pos=0; pos<size(); ++pos)
|
||||||
|
{
|
||||||
|
Key j = keys_[pos];
|
||||||
|
size_t nj = Ab_(pos).cols();
|
||||||
|
Vector dj(nj);
|
||||||
|
for (size_t k = 0; k < nj; ++k) {
|
||||||
|
Vector column_k = Ab_(pos).col(k);
|
||||||
|
dj(k) = dot(column_k,column_k);
|
||||||
|
}
|
||||||
|
d.insert(j,dj);
|
||||||
|
}
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Vector JacobianFactor::operator*(const VectorValues& x) const {
|
Vector JacobianFactor::operator*(const VectorValues& x) const {
|
||||||
Vector Ax = zero(Ab_.rows());
|
Vector Ax = zero(Ab_.rows());
|
||||||
|
|
@ -458,8 +475,9 @@ namespace gtsam {
|
||||||
// Just iterate over all A matrices and insert Ai^e into VectorValues
|
// Just iterate over all A matrices and insert Ai^e into VectorValues
|
||||||
for(size_t pos=0; pos<size(); ++pos)
|
for(size_t pos=0; pos<size(); ++pos)
|
||||||
{
|
{
|
||||||
|
Key j = keys_[pos];
|
||||||
// Create the value as a zero vector if it does not exist.
|
// Create the value as a zero vector if it does not exist.
|
||||||
pair<VectorValues::iterator, bool> xi = x.tryInsert(keys_[pos], Vector());
|
pair<VectorValues::iterator, bool> xi = x.tryInsert(j, Vector());
|
||||||
if(xi.second)
|
if(xi.second)
|
||||||
xi.first->second = Vector::Zero(getDim(begin() + pos));
|
xi.first->second = Vector::Zero(getDim(begin() + pos));
|
||||||
gtsam::transposeMultiplyAdd(Ab_(pos), E, xi.first->second);
|
gtsam::transposeMultiplyAdd(Ab_(pos), E, xi.first->second);
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,9 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
virtual Matrix information() const;
|
virtual Matrix information() const;
|
||||||
|
|
||||||
|
/// Return the diagonal of the Hessian for this factor
|
||||||
|
virtual VectorValues hessianDiagonal() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns (dense) A,b pair associated with factor, bakes in the weights
|
* @brief Returns (dense) A,b pair associated with factor, bakes in the weights
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -139,10 +139,10 @@ TEST(GaussianFactorGraph, matrices) {
|
||||||
EXPECT(assert_equal(L, actualL));
|
EXPECT(assert_equal(L, actualL));
|
||||||
EXPECT(assert_equal(eta, actualeta));
|
EXPECT(assert_equal(eta, actualeta));
|
||||||
|
|
||||||
Vector expectLdiagonal(5); // Make explicit that diagonal is sum-squares of columns
|
VectorValues expectLdiagonal; // Make explicit that diagonal is sum-squares of columns
|
||||||
expectLdiagonal << 1+25+81, 4+36+100, 9+49, 121+196, 144+225;
|
expectLdiagonal.insert(0, (Vector(3) << 1+25+81, 4+36+100, 9+49));
|
||||||
EXPECT(assert_equal(L.diagonal(), expectLdiagonal));
|
expectLdiagonal.insert(1, (Vector(2) << 121+196, 144+225));
|
||||||
// EXPECT(assert_equal(expectLdiagonal, gfg.hessianDiagonal()));
|
EXPECT(assert_equal(expectLdiagonal, gfg.hessianDiagonal()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue