Working on HessianFactor

release/4.3a0
Richard Roberts 2013-08-02 02:04:40 +00:00
parent afb8a9aa1b
commit 29e450dc00
4 changed files with 35 additions and 26 deletions

View File

@ -214,6 +214,8 @@ namespace gtsam {
} }
} }
friend class VerticalBlockMatrix;
private: private:
/** Serialization function */ /** Serialization function */
friend class boost::serialization::access; friend class boost::serialization::access;

View File

@ -17,6 +17,7 @@
* @date Sep 18, 2010 */ * @date Sep 18, 2010 */
#include <gtsam/base/VerticalBlockMatrix.h> #include <gtsam/base/VerticalBlockMatrix.h>
#include <gtsam/base/SymmetricBlockMatrix.h>
namespace gtsam { namespace gtsam {
@ -33,4 +34,17 @@ namespace gtsam {
return result; return result;
} }
/* ************************************************************************* */
VerticalBlockMatrix VerticalBlockMatrix::LikeActiveViewOf(const SymmetricBlockMatrix& rhs, DenseIndex height)
{
VerticalBlockMatrix result;
result.variableColOffsets_.resize(rhs.nBlocks() + 1);
std::copy(rhs.variableColOffsets_.begin() + rhs.blockStart_, rhs.variableColOffsets_.end(),
result.variableColOffsets_.begin());
result.matrix_.resize(height, result.variableColOffsets_.back());
result.rowEnd_ = height;
result.assertInvariants();
return result;
}
} }

View File

@ -93,6 +93,18 @@ namespace gtsam {
matrix_.resize(height, variableColOffsets_.back()); matrix_.resize(height, variableColOffsets_.back());
assertInvariants(); assertInvariants();
} }
/** Copy the block structure and resize the underlying matrix, but do not copy the matrix data.
* If blockStart(), rowStart(), and/or rowEnd() have been modified, this copies the structure of
* the corresponding matrix view. In the destination VerticalBlockView, blockStart() and
* rowStart() will thus be 0, rowEnd() will be cols() of the source VerticalBlockView, and the
* underlying matrix will be the size of the view of the source matrix. */
static VerticalBlockMatrix LikeActiveViewOf(const VerticalBlockMatrix& rhs);
/** Copy the block structure, but do not copy the matrix data. If blockStart() has been
* modified, this copies the structure of the corresponding matrix view. In the destination
* VerticalBlockMatrix, blockStart() will be 0. */
static VerticalBlockMatrix LikeActiveViewOf(const SymmetricBlockMatrix& rhs, DenseIndex height);
/// Row size /// Row size
DenseIndex rows() const { assertInvariants(); return rowEnd_ - rowStart_; } DenseIndex rows() const { assertInvariants(); return rowEnd_ - rowStart_; }
@ -173,13 +185,6 @@ namespace gtsam {
/** Non-const access to full matrix (*including* any portions excluded by rowStart(), rowEnd(), and firstBlock()) */ /** Non-const access to full matrix (*including* any portions excluded by rowStart(), rowEnd(), and firstBlock()) */
Matrix& matrix() { return matrix_; } Matrix& matrix() { return matrix_; }
/** Copy the block structure and resize the underlying matrix, but do not copy the matrix data.
* If blockStart(), rowStart(), and/or rowEnd() have been modified, this copies the structure of
* the corresponding matrix view. In the destination VerticalBlockView, blockStart() and
* rowStart() will thus be 0, rowEnd() will be cols() of the source VerticalBlockView, and the
* underlying matrix will be the size of the view of the source matrix. */
static VerticalBlockMatrix LikeActiveViewOf(const VerticalBlockMatrix& rhs);
protected: protected:
void assertInvariants() const { void assertInvariants() const {
assert(matrix_.cols() == variableColOffsets_.back()); assert(matrix_.cols() == variableColOffsets_.back());

View File

@ -393,32 +393,20 @@ GaussianConditional::shared_ptr HessianFactor::splitEliminatedFactor(size_t nrFr
{ {
static const bool debug = false; static const bool debug = false;
// Extract conditionals
gttic(extract_conditionals);
typedef VerticalBlockView<Matrix> BlockAb;
BlockAb Ab(matrix_, info_);
size_t varDim = info_.offset(nrFrontals);
Ab.rowEnd() = Ab.rowStart() + varDim;
// Create one big conditionals with many frontal variables. // Create one big conditionals with many frontal variables.
gttic(construct_cond); gttic(Construct_conditional);
size_t varDim = info_.offset(nrFrontals);
VerticalBlockMatrix Ab() VerticalBlockMatrix Ab = VerticalBlockMatrix::LikeActiveViewOf(info_, varDim);
GaussianConditional::shared_ptr conditional = boost::make_shared<GaussianConditional>( GaussianConditional::shared_ptr conditional = boost::make_shared<GaussianConditional>(
keys_, nrFrontals, Ab); keys_, nrFrontals, Ab);
gttoc(construct_cond); gttoc(Construct_conditional);
gttoc(extract_conditionals);
gttic(Remaining_factor);
// Take lower-right block of Ab_ to get the new factor // Take lower-right block of Ab_ to get the new factor
gttic(remaining_factor);
info_.blockStart() = nrFrontals; info_.blockStart() = nrFrontals;
// Assign the keys // Assign the keys
vector<Index> remainingKeys(keys_.size() - nrFrontals); keys_.erase(begin(), begin() + nrFrontals);
remainingKeys.assign(keys_.begin() + nrFrontals, keys_.end()); gttoc(Remaining_factor);
keys_.swap(remainingKeys);
gttoc(remaining_factor);
return conditional; return conditional;
} }