/* -*- mona-c++ -*-
* Copyright (c) Leipzig, Madrid 2004 - 2008
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program 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 2 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// $Id: goal.hh,v 1.10 2005/06/08 16:10:55 gerddie Exp $
/**
\author: Gert Wollny < wollny at cbs mpg de >
*/
#ifndef __goal_hh
#define __goal_hh
#include <libmona/defines.hh>
#include <libmona/monaPlugIns.hh>
#include <libmona/plugin_handler.hh>
#include <libmona/factory.hh>
#include <vector>
#include <valarray>
MONA_NAMESPACE_BEGIN
/**
The gradient free goal function for optimisation.
*/
class CGoal {
public:
typedef std::valarray<double> vector;
/**
Initialise the goal with a starting position and a search range
\param pos
\param range
*/
CGoal(CGoal::vector& pos, const CGoal::vector& min, const CGoal::vector& max);
virtual ~CGoal();
/**
\param x possible solution
\returns value of target function at (transformed) x
*/
double operator()(const CGoal::vector& x) const;
/** \returns number of unknowns */
size_t size()const;
/** Set the current solution of the optimisation problem
\param pos in search space
*/
void set_position(const CGoal::vector& pos);
const CGoal::vector& get_position() const;
size_t get_evaluations()const;
const CGoal::vector& get_range() const;
const CGoal::vector& get_min() const;
const CGoal::vector& get_max() const;
private:
/**
This function has to be implemented in order to make actual use of the
goal.
*/
virtual double do_evaluate(const CGoal::vector& x) const = 0;
virtual void do_set_position(const CGoal::vector& x);
// this mutable is dirty ...
mutable size_t _M_evaluations;
/* this is convinience, that adds dirt to the interface */
CGoal::vector& _M_pos;
CGoal::vector _M_min;
CGoal::vector _M_max;
CGoal::vector _M_range;
};
class FGradientFreeOptimiserBase {
public:
virtual ~FGradientFreeOptimiserBase();
virtual void prepare(CGoal& goal) = 0;
virtual bool operator () (CGoal& goal, double epsilon, size_t max_eval) = 0;
private:
};
class CGFOptimiserFactory : public TFactory< FGradientFreeOptimiserBase>
{
public:
CGFOptimiserFactory(char const * const name);
static std::string const get_plugin_searchpattern();
};
class CGoalFactory : public TFactory<CGoal>
{
public:
CGoalFactory(char const * const name);
static std::string const get_plugin_searchpattern();
};
typedef TPluginHandler<CGFOptimiserFactory> CGFOptimiserPluginHandler;
typedef TPluginHandler<CGoalFactory> CGoalPluginHandler;
MONA_NAMESPACE_END
#endif
/*
$Log: goal.hh,v $
Revision 1.10 2005/06/08 16:10:55 gerddie
playing around
Revision 1.9 2005/05/24 14:13:35 gerddie
save the work on symmetric registration
Revision 1.8 2005/05/23 17:10:15 gerddie
ssdsym test cought some errors
Revision 1.7 2005/05/23 14:33:14 gerddie
slight changes in the factory infrastructure
Revision 1.6 2005/05/20 10:44:33 gerddie
rigidreggoal compiles
Revision 1.5 2005/05/19 13:08:48 gerddie
some tweaking in genetic optimisation
Revision 1.4 2005/05/19 07:55:37 gerddie
change goal vector handling to valarray
Revision 1.3 2005/05/12 13:23:19 gerddie
supprt function to get range
Revision 1.2 2005/05/12 09:25:15 gerddie
make the gradfree optimiser a plugin based entity
Revision 1.1 2005/05/11 22:58:32 gerddie
add seperate goal file
*/