24 for (
size_t i = 0; i <
n; ++i) {
27 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
28 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
30 fitting->getFittingFunction()->applyTies();
43 for (
size_t i = 0; i <
n; ++i) {
46 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
47 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
49 fitting->getFittingFunction()->applyTies();
51 std::vector<double> der(
n);
53 for (
size_t i = 0; i <
n; ++i) {
54 gsl_vector_set(g, i, der[i]);
67 for (
size_t i = 0; i <
n; ++i) {
70 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
71 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
73 fitting->getFittingFunction()->applyTies();
75 std::vector<double> der(
n);
77 for (
size_t i = 0; i <
n; ++i) {
78 gsl_vector_set(g, i, der[i]);
84 : m_gslSolver(nullptr), m_x(nullptr), m_stopGradient(1e-3), m_stepSize(0.1), m_tolerance(0.0001) {
94 : m_gslSolver(nullptr), m_x(nullptr), m_stopGradient(1e-3), m_stepSize(stepSize), m_tolerance(
tolerance) {
112 gsl_vector_free(
m_x);
134 m_x = gsl_vector_alloc(nParams);
135 for (
size_t i = 0; i < nParams; ++i) {
148 throw std::runtime_error(
"Minimizer " + this->
name() +
" was not initialized.");
150 int status = gsl_multimin_fdfminimizer_iterate(
m_gslSolver);
156 if (status != GSL_CONTINUE) {
169 throw std::invalid_argument(
"Gradient norm must be a positive number");
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
std::string m_errorString
Error string.
virtual std::string name() const =0
Get name of minimizer.
A wrapper around the GSL functions implementing a minimizer using derivatives.
void setStopGradient(const double value)
Set maximum value of the gradient at which iterations can stop.
static void fundfun(const gsl_vector *x, void *params, double *f, gsl_vector *g)
Used by the GSL.
void initialize(API::ICostFunction_sptr function, size_t maxIterations=0) override
Initialize minimizer, i.e. pass a function to minimize.
gsl_multimin_function_fdf m_gslMultiminContainer
GSL container.
double m_stopGradient
the norm of the gradient at which iterations stop
bool iterate(size_t) override
Do one iteration.
static void dfun(const gsl_vector *x, void *params, gsl_vector *g)
Used by the GSL.
~DerivMinimizer() override
Destructor.
DerivMinimizer()
Constructor.
static double fun(const gsl_vector *x, void *params)
Used by the GSL.
gsl_multimin_fdfminimizer * m_gslSolver
pointer to the GSL solver doing the work
double m_tolerance
Tolerance.
void initGSLMMin()
simply init the values for the gsl minimizer
virtual const gsl_multimin_fdfminimizer_type * getGSLMinimizerType()=0
Return a concrete type to initialize m_gslSolver with.
double costFunctionVal() override
Return current value of the cost function.
API::ICostFunction_sptr m_costFunction
Function to minimize.
gsl_vector * m_x
GSL vector with function parameters.
double m_stepSize
First trial step size.
const std::string SUCCESS
Reported when a minimizer has fully converged.
std::shared_ptr< ICostFunction > ICostFunction_sptr
define a shared pointer to a cost function