18 MT_THROW(
"SolverFunctionT::getHessian() is not implemented");
33 for (
size_t i = 0; i < numBlocks; ++i) {
40 if (totalRows >
static_cast<size_t>(jacobian.rows()) || parameters.size() != jacobian.cols()) {
41 jacobian.resize(totalRows, parameters.size());
42 residual.resize(totalRows);
50 actualRows = totalRows;
53 for (
size_t i = 0; i < numBlocks; ++i) {
59 size_t blockActualRows = 0;
61 auto jacBlock = jacobian.block(position, 0, blockSize, parameters.size());
62 auto resBlock = residual.segment(position, blockSize);
66 position += blockSize;
80 const size_t numParams = parameters.size();
88 for (
size_t i = 0; i < numBlocks; ++i) {
94 size_t blockActualRows = 0;
96 tJacobian_.resizeAndSetZero(blockSize, numParams);
99 auto jacBlock =
tJacobian_.mat().block(0, 0, blockSize, numParams);
100 auto resBlock =
tResidual_.vec().segment(0, blockSize);
105 if (blockActualRows == 0) {
113 jtj.template selfadjointView<Eigen::Lower>().rankUpdate(JtBlock);
116 jtr.noalias() += JtBlock *
tResidual_.vec().segment(0, blockActualRows);
142 return getJtJR(parameters, hess, grad);
160 std::unordered_map<std::string,
MatrixX<T>>& history,
162 size_t maxIterations_) {
166 (void)maxIterations_;
Abstract base class for optimization objective functions.
double getJacobian(const VectorX< T > ¶meters, MatrixX< T > &jacobian, VectorX< T > &residual, size_t &actualRows)
Computes the Jacobian matrix for least squares problems.
size_t getActualParameters() const
Returns the number of parameters currently enabled for optimization.
size_t getNumParameters() const
Returns the total number of parameters in the optimization problem.
virtual double computeJacobianBlock(const VectorX< T > ¶meters, size_t blockIndex, Eigen::Ref< MatrixX< T > > jacobianBlock, Eigen::Ref< VectorX< T > > residualBlock, size_t &actualRows)=0
Computes a specific Jacobian block.
virtual double getSolverDerivatives(const VectorX< T > ¶meters, MatrixX< T > &hess, VectorX< T > &grad)
Computes derivatives needed by the solver.
virtual double getJtJR_Sparse(const VectorX< T > ¶meters, SparseMatrix< T > &jtj, VectorX< T > &jtr)
Computes sparse JᵀJ and JᵀR for large-scale problems.
size_t actualParameters_
Number of parameters currently enabled for optimization.
ResizeableMatrix< T > tResidual_
virtual void initializeJacobianComputation(const VectorX< T > ¶meters)=0
Initializes Jacobian computation for the given parameters.
virtual void getHessian(const VectorX< T > ¶meters, MatrixX< T > &hessian)
Computes the Hessian matrix of second derivatives.
size_t numParameters_
Total number of parameters in the optimization problem.
virtual double getJtJR(const VectorX< T > ¶meters, MatrixX< T > &jtj, VectorX< T > &jtr)
Computes JᵀJ and JᵀR for Gauss-Newton optimization.
virtual void setEnabledParameters(const ParameterSet ¶meterSet)
Specifies which parameters should be optimized.
virtual size_t getJacobianBlockCount() const =0
Returns the number of Jacobian blocks available.
virtual void storeHistory(std::unordered_map< std::string, MatrixX< T > > &history, size_t iteration, size_t maxIterations_)
Records solver state for debugging and analysis.
virtual void finalizeJacobianComputation()
Optional cleanup after all Jacobian blocks have been computed.
ResizeableMatrix< T > tJacobian_
Pre-allocated temporary storage for block-wise JtJ computation.
virtual size_t getJacobianBlockSize(size_t blockIndex) const =0
Returns the maximum number of rows for a specific Jacobian block.
#define MT_THROW(...)
Throws a std::runtime_error with a formatted message.
constexpr size_t padToSimdAlignment(size_t size)
Pads a row count to be a multiple of kJacobianRowAlignment for SIMD alignment.
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Eigen::SparseMatrix< T > SparseMatrix
Column-major sparse matrix.
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.