My Project
minimizer.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 mia_core_minimizer_hh
22#define mia_core_minimizer_hh
23
24#include <memory>
25#include <vector>
26
27#include <mia/core/factory.hh>
28#include <mia/core/handler.hh>
29#include <mia/core/vector.hh>
30
32
33
43{
44public:
45
50
52 typedef std::shared_ptr<CMinimizer> Pointer;
53
55 enum EMinimizerResult {failure,
56 success
57 };
58
60 static const char *const type_descr;
61
63 static const char *const data_descr;
64
82 {
83 public:
84 virtual ~Problem();
85
93 double f(size_t n, const double *x);
94
104 void df(size_t n, const double *x, double *g);
113 double fdf(size_t n, const double *x, double *g);
114
122 double f(const std::vector<double>& x);
123
131 void df(const std::vector<double>& x, std::vector<double>& g);
132
140 double fdf(const std::vector<double>& x, std::vector<double>& g);
141
149 double f(const CDoubleVector& x);
150
158 void df(const CDoubleVector& x, CDoubleVector& g);
159
167 double fdf(const CDoubleVector& x, CDoubleVector& g);
168
169
171 size_t size() const;
172 private:
173 virtual double do_f(const CDoubleVector& x) = 0;
174 virtual void do_df(const CDoubleVector& x, CDoubleVector& g) = 0;
175 virtual double do_fdf(const CDoubleVector& x, CDoubleVector& g) = 0;
176 virtual size_t do_size() const = 0;
177 };
178
180 typedef std::shared_ptr<Problem> PProblem;
181
186
192
193
194 virtual ~CMinimizer();
195
196
203
204protected:
207
209 size_t size() const;
210
212 Problem& get_problem();
213private:
214 virtual void do_set_problem();
215 virtual int do_run(CDoubleVector& x) = 0;
216
217 PProblem m_problem;
218};
219
222
225
228
231
233{
234 return *m_problem;
235}
236
237inline
238PMinimizer produce_minimizer(const std::string& descr)
239{
240 return CMinimizerPluginHandler::instance().produce(descr);
241}
242
243
245
246#endif
Base class for all optimization problems that can be run by CMinimizer.
Definition: minimizer.hh:82
double fdf(size_t n, const double *x, double *g)
double fdf(const CDoubleVector &x, CDoubleVector &g)
void df(size_t n, const double *x, double *g)
void df(const CDoubleVector &x, CDoubleVector &g)
double f(const CDoubleVector &x)
size_t size() const
double f(size_t n, const double *x)
void df(const std::vector< double > &x, std::vector< double > &g)
double fdf(const std::vector< double > &x, std::vector< double > &g)
double f(const std::vector< double > &x)
A class for generalized minimization problems.
Definition: minimizer.hh:43
size_t size() const
std::shared_ptr< Problem > PProblem
pointer type for the optimization problem
Definition: minimizer.hh:180
CMinimizer plugin_type
plug-in searchpath typedef helper
Definition: minimizer.hh:49
static const char *const data_descr
plug-in searchpath helper
Definition: minimizer.hh:63
CMinimizer plugin_data
plug-in searchpath typedef helper
Definition: minimizer.hh:47
static const char *const type_descr
plug-in searchpath helper
Definition: minimizer.hh:60
EMinimizerResult
enum to describe whether optimization succeeded
Definition: minimizer.hh:55
void set_problem(PProblem x)
Problem * get_problem_pointer()
std::shared_ptr< CMinimizer > Pointer
Pointer type of this minimizer.
Definition: minimizer.hh:52
virtual ~CMinimizer()
int run(CDoubleVector &x)
Problem & get_problem()
Definition: minimizer.hh:232
The base class for all plug-in created object.
Definition: product_base.hh:41
This class holds a set of properties.
A wrapper around the c-array to provide an STL like interface for iterators.
Definition: core/vector.hh:78
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:51
the singleton that a plug-in handler really is
Definition: handler.hh:159
static const T & instance()
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CMinimizer::Pointer PMinimizer
Pointer type for the CMinimizer class.
Definition: minimizer.hh:221
PMinimizer produce_minimizer(const std::string &descr)
Definition: minimizer.hh:238
TFactory< CMinimizer > CMinimizerPlugin
Base class for the CMinimizer creator plugins.
Definition: minimizer.hh:224
FACTORY_TRAIT(CMinimizerPluginHandler)
Trait to make the minimizer definition parsable on the command line.
THandlerSingleton< TFactoryPluginHandler< CMinimizerPlugin > > CMinimizerPluginHandler
The minimizer plugin handler.
Definition: minimizer.hh:227