My Project
gsl_multimin.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef GSLPP_MULTIMIN_HH
22 #define GSLPP_MULTIMIN_HH
23 
24 #include <memory>
25 #include <mia/core/gsl_vector.hh>
26 #include <gsl/gsl_multimin.h>
27 #include <mia/core/gsl_defines.hh>
28 
29 namespace gsl
30 {
31 
36 {
37 public:
42  class Problem
43  {
44  public:
48  Problem(size_t n_params);
49 
55  static double f(const gsl_vector *x, void *params);
56 
62  static void df(const gsl_vector *x, void *params, gsl_vector *g);
63 
69  static void fdf(const gsl_vector *x, void *params, double *f, gsl_vector *g);
70 
71  operator gsl_multimin_function_fdf *();
72 
73  size_t size() const;
74  private:
75  virtual double do_f(const Vector& x) = 0;
76  virtual void do_df(const Vector& x, Vector& g) = 0;
77  virtual double do_fdf(const Vector& x, Vector& g) = 0;
78  gsl_multimin_function_fdf m_func;
79  };
80  typedef std::shared_ptr<Problem> PProblem;
81 
87  CFDFMinimizer(PProblem p, const gsl_multimin_fdfminimizer_type *ot);
88 
89 
91 
95  void set_g_tol(double tol);
96 
100  void set_stop_eps(double tol);
101 
107  int run(Vector& x);
108 
109 private:
110  struct CFDFMinimizerImpl *impl;
111 };
112 
113 
118 {
119 public:
125  class Problem
126  {
127  public:
131  Problem(size_t n_params);
132 
139  static double f(const gsl_vector *x, void *params);
140 
141  operator gsl_multimin_function *();
142 
143  size_t size() const;
144  private:
145  virtual double do_f(const Vector& x) = 0;
146  gsl_multimin_function m_func;
147  };
148  typedef std::shared_ptr<Problem> PProblem;
149 
155  CFMinimizer(PProblem p, const gsl_multimin_fminimizer_type *ot);
156 
158 
164  int run(Vector& x);
165 private:
166  struct CFMinimizerImpl *impl;
167 };
168 
169 }
170 
171 #endif
Problem(size_t n_params)
static void df(const gsl_vector *x, void *params, gsl_vector *g)
static void fdf(const gsl_vector *x, void *params, double *f, gsl_vector *g)
static double f(const gsl_vector *x, void *params)
CFDFMinimizer(PProblem p, const gsl_multimin_fdfminimizer_type *ot)
void set_stop_eps(double tol)
int run(Vector &x)
std::shared_ptr< Problem > PProblem
Definition: gsl_multimin.hh:80
void set_g_tol(double tol)
Problem(size_t n_params)
static double f(const gsl_vector *x, void *params)
CFMinimizer(PProblem p, const gsl_multimin_fminimizer_type *ot)
int run(Vector &x)
std::shared_ptr< Problem > PProblem
#define EXPORT_GSL
Definition: gsl_defines.hh:38