22 for (
size_t i = 0; i <
n; ++i) {
25 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
26 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
28 fitting->getFittingFunction()->applyTies();
41 for (
size_t i = 0; i <
n; ++i) {
44 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
45 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
47 fitting->getFittingFunction()->applyTies();
49 std::vector<double> der(
n);
51 for (
size_t i = 0; i <
n; ++i) {
52 gsl_vector_set(g, i, der[i]);
65 for (
size_t i = 0; i <
n; ++i) {
68 std::shared_ptr<CostFunctions::CostFuncFitting> fitting =
69 std::dynamic_pointer_cast<CostFunctions::CostFuncFitting>(minimizer.
m_costFunction);
71 fitting->getFittingFunction()->applyTies();
73 std::vector<double> der(
n);
75 for (
size_t i = 0; i <
n; ++i) {
76 gsl_vector_set(g, i, der[i]);
82 : m_gslSolver(nullptr), m_x(nullptr), m_stopGradient(1e-3), m_stepSize(0.1), m_tolerance(0.0001) {
92 : m_gslSolver(nullptr), m_x(nullptr), m_stopGradient(1e-3), m_stepSize(stepSize), m_tolerance(
tolerance) {
110 gsl_vector_free(
m_x);
132 m_x = gsl_vector_alloc(nParams);
133 for (
size_t i = 0; i < nParams; ++i) {
146 throw std::runtime_error(
"Minimizer " + this->
name() +
" was not initialized.");
148 int status = gsl_multimin_fdfminimizer_iterate(
m_gslSolver);
154 if (status != GSL_CONTINUE) {
167 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.
std::shared_ptr< ICostFunction > ICostFunction_sptr
define a shared pointer to a cost function