minimizer.hh
Go to the documentation of this file.
/* -*- mia-c++ -*-
*
* This file is part of MIA - a toolbox for medical image analysis
* Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
*
* MIA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MIA; if not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef mia_core_minimizer_hh
#define mia_core_minimizer_hh
#include <memory>
#include <vector>
#include <mia/core/factory.hh>
#include <mia/core/handler.hh>
#include <mia/core/vector.hh>
NS_MIA_BEGIN
class EXPORT_CORE CMinimizer : public CProductBase
{
public:
typedef CMinimizer plugin_data;
typedef CMinimizer plugin_type;
typedef std::shared_ptr<CMinimizer> Pointer;
enum EMinimizerResult {failure,
success
};
static const char *const type_descr;
static const char *const data_descr;
class Problem : public CPropertyFlagHolder
{
public:
virtual ~Problem();
double f(size_t n, const double *x);
void df(size_t n, const double *x, double *g);
double fdf(size_t n, const double *x, double *g);
double f(const std::vector<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 CDoubleVector& x);
void df(const CDoubleVector& x, CDoubleVector& g);
double fdf(const CDoubleVector& x, CDoubleVector& g);
size_t size() const;
private:
virtual double do_f(const CDoubleVector& x) = 0;
virtual void do_df(const CDoubleVector& x, CDoubleVector& g) = 0;
virtual double do_fdf(const CDoubleVector& x, CDoubleVector& g) = 0;
virtual size_t do_size() const = 0;
};
typedef std::shared_ptr<Problem> PProblem;
CMinimizer();
void set_problem(PProblem x);
virtual ~CMinimizer();
int run(CDoubleVector& x);
protected:
Problem *get_problem_pointer();
size_t size() const;
Problem& get_problem();
private:
virtual void do_set_problem();
virtual int do_run(CDoubleVector& x) = 0;
PProblem m_problem;
};
typedef CMinimizer::Pointer PMinimizer;
typedef TFactory<CMinimizer> CMinimizerPlugin;
typedef THandlerSingleton<TFactoryPluginHandler<CMinimizerPlugin>> CMinimizerPluginHandler;
FACTORY_TRAIT(CMinimizerPluginHandler);
inline CMinimizer::Problem& CMinimizer::get_problem()
{
return *m_problem;
}
inline
PMinimizer produce_minimizer(const std::string& descr)
{
return CMinimizerPluginHandler::instance().produce(descr);
}
NS_MIA_END
#endif
CMinimizer::Problem
Base class for all optimization problems that can be run by CMinimizer.
Definition minimizer.hh:82
CMinimizer::Problem::~Problem
virtual ~Problem()
CMinimizer::Problem::fdf
double fdf(size_t n, const double *x, double *g)
CMinimizer::Problem::fdf
double fdf(const CDoubleVector &x, CDoubleVector &g)
CMinimizer::Problem::df
void df(size_t n, const double *x, double *g)
CMinimizer::Problem::df
void df(const CDoubleVector &x, CDoubleVector &g)
CMinimizer::Problem::f
double f(const CDoubleVector &x)
CMinimizer::Problem::size
size_t size() const
CMinimizer::Problem::f
double f(size_t n, const double *x)
CMinimizer::Problem::df
void df(const std::vector< double > &x, std::vector< double > &g)
CMinimizer::Problem::fdf
double fdf(const std::vector< double > &x, std::vector< double > &g)
CMinimizer::Problem::f
double f(const std::vector< double > &x)
CMinimizer::size
size_t size() const
CMinimizer::PProblem
std::shared_ptr< Problem > PProblem
pointer type for the optimization problem
Definition minimizer.hh:180
CMinimizer::plugin_type
CMinimizer plugin_type
plug-in searchpath typedef helper
Definition minimizer.hh:49
CMinimizer::data_descr
static const char *const data_descr
plug-in searchpath helper
Definition minimizer.hh:63
CMinimizer::plugin_data
CMinimizer plugin_data
plug-in searchpath typedef helper
Definition minimizer.hh:47
CMinimizer::type_descr
static const char *const type_descr
plug-in searchpath helper
Definition minimizer.hh:60
CMinimizer::EMinimizerResult
EMinimizerResult
enum to describe whether optimization succeeded
Definition minimizer.hh:55
CMinimizer::failure
@ failure
Definition minimizer.hh:55
CMinimizer::success
@ success
Definition minimizer.hh:56
CMinimizer::set_problem
void set_problem(PProblem x)
CMinimizer::get_problem_pointer
Problem * get_problem_pointer()
CMinimizer::Pointer
std::shared_ptr< CMinimizer > Pointer
Pointer type of this minimizer.
Definition minimizer.hh:52
CMinimizer::CMinimizer
CMinimizer()
CMinimizer::~CMinimizer
virtual ~CMinimizer()
CMinimizer::run
int run(CDoubleVector &x)
CMinimizer::get_problem
Problem & get_problem()
Definition minimizer.hh:232
CProductBase
The base class for all plug-in created object.
Definition product_base.hh:41
CPropertyFlagHolder
This class holds a set of properties.
Definition property_flags.hh:42
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition factory.hh:51
THandlerSingleton
the singleton that a plug-in handler really is
Definition handler.hh:159
THandlerSingleton< TFactoryPluginHandler< CMinimizerPlugin > >::instance
static const TFactoryPluginHandler< CMinimizerPlugin > & instance()
vector.hh
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition defines.hh:33
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition defines.hh:101
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition defines.hh:36
factory.hh
CDoubleVector
TCArrayWrapper< double > CDoubleVector
Definition core/vector.hh:266
FACTORY_TRAIT
#define FACTORY_TRAIT(F)
Definition factory_trait.hh:69
handler.hh
PMinimizer
CMinimizer::Pointer PMinimizer
Pointer type for the CMinimizer class.
Definition minimizer.hh:221
produce_minimizer
PMinimizer produce_minimizer(const std::string &descr)
Definition minimizer.hh:238
CMinimizerPlugin
TFactory< CMinimizer > CMinimizerPlugin
Base class for the CMinimizer creator plugins.
Definition minimizer.hh:224
CMinimizerPluginHandler
THandlerSingleton< TFactoryPluginHandler< CMinimizerPlugin > > CMinimizerPluginHandler
The minimizer plugin handler.
Definition minimizer.hh:227