2#include "optimizable_graph.h"
6#include <Eigen/Cholesky>
7#include <Eigen/StdVector>
17 template <s
int04 t_dims,
typename T>
21 static constexpr sint04 Dimension = t_dims;
22 typedef T EstimateType;
25 typedef Eigen::Map<Eigen::Matrix<g_type, t_dims, t_dims>, Eigen::Matrix<g_type, t_dims, t_dims>::Flags& Eigen::PacketAccessBit
27 : Eigen::Unaligned> HessianBlockType;
30 static_assert(t_dims > 0,
"Bad vertex");
33 : OptimizableGraph::OGVertex()
45 Eigen::Matrix<g_type, t_dims, t_dims> tempA =
_hessian
46 + Eigen::Matrix<g_type, t_dims, t_dims>::Identity()* lambda;
47 g_type det = tempA.determinant();
48 if (
IsInvalid(det) || det < std::numeric_limits<g_type>::epsilon())
50 Eigen::Matrix <g_type, t_dims, 1> dx = tempA.llt().solve(
_b);
59 new (&
_hessian) HessianBlockType(d, t_dims, t_dims);
64 const g_type&
hessian(
int i,
int j)
const final override { assert(i < t_dims && j < t_dims);
return _hessian(i, j); }
66 g_type&
hessian(
int i,
int j)
final override { assert(i < t_dims && j < t_dims);
return _hessian(i, j); }
77 memcpy(b_,
_b.data(), t_dims *
sizeof(g_type));
82 const g_type&
b(
int i)
const final override { assert(i < t_dims);
return _b(i); }
84 g_type&
b(
int i)
final override { assert(i < t_dims);
return _b(i); }
86 g_type*
bData() final
override {
return _b.data(); }
95 Eigen::Matrix<g_type, t_dims, 1>&
b() {
return _b; }
96 const Eigen::Matrix<g_type, t_dims, 1>&
b()
const {
return _b; }
99 const HessianBlockType&
A()
const {
return _hessian; }
117 Eigen::Matrix<g_type, t_dims, 1>
_b;
121 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
void clearQuadraticForm() final override
Zeros the b vector, clearing the accumulated quadratic form gradient.
HessianBlockType _hessian
Mapped Hessian block for this vertex.
sint04 copyB(g_type *b_) const final override
Copies the b vector into the provided array.
const EstimateType & estimate() const
return the current estimate of the vertex
EstimateType _estimate
Current estimate for this vertex.
g_type & b(int i) final override
Returns a mutable reference to the i-th element of the b vector.
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
const g_type & b(int i) const final override
Returns a const reference to the i-th element of the b vector.
HessianBlockType & A()
return the hessian block associated with the vertex
const g_type & hessian(int i, int j) const final override
Returns a const reference to the Hessian element at (i,j).
g_type & hessian(int i, int j) final override
Returns a mutable reference to the Hessian element at (i,j).
g_type solveDirect(g_type lambda=0.0) final override
Solves the local linear system H*dx = b directly and applies the update.
Eigen::Matrix< g_type, t_dims, 1 > _b
Right-hand side (gradient) vector of the quadratic form.
Eigen::Matrix< g_type, t_dims, 1 > & b()
return right hand side b of the constructed linear system
sint04 dimension() const final override
Returns the minimal dimension of this vertex.
void mapHessianMemory(g_type *d) final override
Maps the Hessian block to an external memory buffer.
virtual void discardTop() final override
Discards the top of the backup stack without restoring.
g_type * bData() final override
Returns a mutable pointer to the raw b vector data.
virtual int stackSize() const final override
Returns the number of entries on the backup stack.
g_type * hessianData() final override
Returns a mutable pointer to the raw Hessian data.
BaseVertex()
Default constructor.
virtual void push() final override
Pushes the current estimate onto the backup stack.
BackupStackType _backup
Stack for backing up and restoring estimates.
g_type hessianDeterminant() const final override
Returns the determinant of the Hessian block.
virtual void pop() final override
Restores the estimate from the top of the backup stack and removes it.
The equivelent of std::vector but with a bit more control.
A general case Vertex for optimization.
void oplus(const g_type *v)
Update the position of the node from the parameters in v.
The primary namespace for the NDEVR SDK.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.