Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
mia
core
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-2013 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
31
NS_MIA_BEGIN
32
33
42
class
EXPORT_CORE
CMinimizer
:
public
CProductBase
{
43
public
:
44
46
typedef
CMinimizer
plugin_data
;
48
typedef
CMinimizer
plugin_type
;
49
51
typedef
std::shared_ptr<CMinimizer>
Pointer
;
52
54
enum
EMinimizerResult
{
failure
,
55
success
56
};
57
59
static
const
char
*
const
type_descr
;
60
62
static
const
char
*
const
data_descr
;
63
80
class
Problem
:
public
CPropertyFlagHolder
{
81
public
:
82
virtual
~
Problem
();
83
91
double
f(
size_t
n,
const
double
*x);
92
102
void
df(
size_t
n,
const
double
*x,
double
*g);
111
double
fdf(
size_t
n,
const
double
*x,
double
*g);
112
120
double
f(
const
std::vector<double>& x);
121
129
void
df(
const
std::vector<double>& x, std::vector<double>& g);
130
138
double
fdf(
const
std::vector<double>& x, std::vector<double>& g);
139
147
double
f(
const
CDoubleVector
& x);
148
156
void
df(
const
CDoubleVector
& x,
CDoubleVector
& g);
157
165
double
fdf(
const
CDoubleVector
& x,
CDoubleVector
& g);
166
167
169
size_t
size()
const
;
170
private
:
171
virtual
double
do_f(
const
CDoubleVector
& x) = 0;
172
virtual
void
do_df(
const
CDoubleVector
& x,
CDoubleVector
& g) = 0;
173
virtual
double
do_fdf(
const
CDoubleVector
& x,
CDoubleVector
& g) = 0;
174
virtual
size_t
do_size()
const
= 0;
175
};
176
178
typedef
std::shared_ptr<Problem>
PProblem
;
179
183
CMinimizer
();
184
189
void
set_problem(
PProblem
x);
190
191
192
virtual
~
CMinimizer
();
193
194
200
int
run(
CDoubleVector
& x);
201
202
protected
:
204
Problem
*get_problem_pointer();
205
207
size_t
size()
const
;
208
210
Problem
& get_problem();
211
private
:
212
virtual
void
do_set_problem();
213
virtual
int
do_run(
CDoubleVector
& x) = 0;
214
215
PProblem
m_problem;
216
};
217
219
typedef
CMinimizer::Pointer
PMinimizer
;
220
222
typedef
TFactory<CMinimizer>
CMinimizerPlugin
;
223
225
typedef
THandlerSingleton<TFactoryPluginHandler<CMinimizerPlugin>
>
CMinimizerPluginHandler
;
226
228
FACTORY_TRAIT
(
CMinimizerPluginHandler
);
229
230
inline
CMinimizer::Problem
&
CMinimizer::get_problem
()
231
{
232
return
*m_problem;
233
}
234
235
inline
236
PMinimizer
produce_minimizer
(
const
std::string& descr)
237
{
238
return
CMinimizerPluginHandler::instance
().produce(descr);
239
}
240
241
242
NS_MIA_END
243
244
#endif
Generated on Tue Oct 15 2013 13:56:37 by
1.8.4