57 if (parameterHistory.rows() != gsl::narrow_cast<Eigen::Index>(
numParameters_) ||
58 parameterHistory.cols() != gsl::narrow_cast<Eigen::Index>(maxIterations_)) {
61 if (errorHistory.rows() != gsl::narrow_cast<Eigen::Index>(maxIterations_) ||
62 errorHistory.cols() != 1) {
63 errorHistory.resize(maxIterations_, 1);
65 if (iterationCount.rows() != 1 || iterationCount.cols() != 1) {
66 iterationCount.resize(1, 1);
69 parameterHistory.setZero();
70 errorHistory.setZero();
71 iterationCount.setZero();
82 "error and lastError_ should be of the same type");
97 bool converged =
false;
99 threshold_ * std::numeric_limits<float>::epsilon()) {
113 if (
iteration_ >= minIterations_ && converged) {
123 iterationCount(0, 0) = gsl::narrow_cast<float>(
iteration_);
152 return minIterations_;
157 return maxIterations_;
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
Abstract base class for optimization objective functions.
Base class for numerical optimization solvers.
bool newParameterPattern_
Flag indicating parameter structure has changed.
virtual void setOptions(const SolverOptions &options)
Updates solver configuration with new options.
virtual void doIteration()=0
Performs a single iteration of the optimization algorithm.
void setParameters(const Eigen::VectorX< T > ¶ms)
Sets the current parameter values without solving.
std::unordered_map< std::string, Eigen::MatrixX< T > > iterationHistory_
Recorded data from optimization process.
size_t getMaxIterations() const
Returns the maximum number of iterations before terminating.
const ParameterSet & getActiveParameters() const
Returns the current set of enabled parameters.
double lastError_
Previous iteration's objective function value.
ParameterSet activeParameters_
Bitset indicating which parameters are enabled for optimization.
size_t iteration_
Current iteration count.
Eigen::VectorX< T > parameters_
Current parameter values.
bool verbose_
Whether to output detailed progress information.
size_t getMinIterations() const
Returns the minimum number of iterations before checking convergence.
bool storeHistory
Whether to record optimization progress for analysis.
double error_
Current objective function value.
const std::unordered_map< std::string, Eigen::MatrixX< T > > & getHistory() const
Returns the history of the solver's iterations.
void setStoreHistory(bool b)
Controls whether to store iteration history for debugging and analysis.
virtual void initializeSolver()=0
Initializes solver state before optimization begins.
double solve(Eigen::VectorX< T > ¶ms)
Solves the optimization problem.
std::vector< double > errorHistory_
History of objective function values over the iterations.
size_t numParameters_
Total number of parameters in the optimization problem.
SolverFunctionT< T > * solverFunction_
Function to be optimized.
virtual void setEnabledParameters(const ParameterSet ¶meters)
Specifies which parameters should be optimized.
SolverT(const SolverOptions &options, SolverFunctionT< T > *solver)
Constructor with solver options and function to optimize.
int actualParameters_
Number of parameters currently enabled for optimization.
#define MT_LOGI_IF(condition,...)
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Profiling macros that dispatch to one of three backends, selected at compile time:
#define MT_PROFILE_FUNCTION()
Common options for numerical optimization solvers.
size_t minIterations
Minimum number of iterations before checking convergence criteria.
bool verbose
Enable detailed logging during optimization.
size_t maxIterations
Maximum number of iterations before terminating.
float threshold
Convergence threshold for relative error change.