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 
35 public:
40  class Problem {
41  public:
45  Problem(size_t n_params);
46 
52  static double f(const gsl_vector * x, void * params);
53 
59  static void df(const gsl_vector * x, void * params, gsl_vector * g);
60 
66  static void fdf(const gsl_vector * x, void * params, double * f, gsl_vector * g);
67 
68  operator gsl_multimin_function_fdf*();
69 
70  size_t size() const;
71  private:
72  virtual double do_f(const Vector& x) = 0;
73  virtual void do_df(const Vector& x, Vector& g) = 0;
74  virtual double do_fdf(const Vector& x, Vector& g) = 0;
75  gsl_multimin_function_fdf m_func;
76  };
77  typedef std::shared_ptr<Problem> PProblem;
78 
84  CFDFMinimizer(PProblem p, const gsl_multimin_fdfminimizer_type *ot);
85 
86 
87  ~CFDFMinimizer();
88 
92  void set_g_tol(double tol);
93 
97  void set_stop_eps(double tol);
98 
104  int run(Vector& x);
105 
106 private:
107  struct CFDFMinimizerImpl *impl;
108 };
109 
110 
115 public:
121  class Problem {
122  public:
126  Problem(size_t n_params);
127 
134  static double f(const gsl_vector * x, void * params);
135 
136  operator gsl_multimin_function*();
137 
138  size_t size() const;
139  private:
140  virtual double do_f(const Vector& x) = 0;
141  gsl_multimin_function m_func;
142  };
143  typedef std::shared_ptr<Problem> PProblem;
144 
150  CFMinimizer(PProblem p, const gsl_multimin_fminimizer_type *ot);
151 
152  ~CFMinimizer();
153 
159  int run(Vector& x);
160 private:
161  struct CFMinimizerImpl *impl;
162 };
163 
164 }
165 
166 #endif
std::shared_ptr< Problem > PProblem
std::shared_ptr< Problem > PProblem
Definition: gsl_multimin.hh:77
#define EXPORT_GSL
Definition: gsl_defines.hh:38