[go: up one dir, main page]

Menu

[r811]: / libmona / libmona / goal.cc  Maximize  Restore  History

Download this file

185 lines (142 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
** Copyrigh (C) 2004 MPI of Human Cognitive and Brain Sciences
**
** 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.cc,v 1.10 2005/06/08 16:10:55 gerddie Exp $
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <libmona/goal.hh>
#include <libmona/monaHelprs.hh>
#include <libmona/plugin_handler.cxx>
#include <stdexcept>
#include <cassert>
MONA_NAMESPACE_BEGIN
CGoal::CGoal(CGoal::vector& pos, const CGoal::vector& min, const CGoal::vector& max):
_M_evaluations(0),
_M_pos(pos),
_M_min(min),
_M_max(max),
_M_range(max - min)
{
}
CGoal::~CGoal()
{
}
const CGoal::vector& CGoal::get_position() const
{
return _M_pos;
}
void CGoal::set_position(const CGoal::vector& pos)
{
_M_pos = pos;
do_set_position(pos);
}
size_t CGoal::size()const
{
if (_M_pos.size() != _M_range.size())
throw std::invalid_argument("CGoal::CGoal: pos.size() != range.size()");
return _M_pos.size();
}
double boundary_penalty(double x)
{
if (x < 3)
return expf(x);
else
return expf(3.0) + x - 3.0;
}
double CGoal::operator()(const CGoal::vector& x) const
{
assert(x.size() == _M_pos.size());
++_M_evaluations;
double result = do_evaluate(x);
// penalize unenforced boundary condition
for (size_t i = 0; i < x.size(); ++i) {
if (x[i] < _M_min[i]) {
result += boundary_penalty(_M_min[i] - x[i]);
break;
}
if (x[i] > _M_max[i]) {
result += boundary_penalty(x[i] - _M_max[i]);
break;
}
}
return result;
}
size_t CGoal::get_evaluations()const
{
return _M_evaluations;
}
const CGoal::vector& CGoal::get_range() const
{
return _M_range;
}
const CGoal::vector& CGoal::get_min() const
{
return _M_min;
}
const CGoal::vector& CGoal::get_max() const
{
return _M_max;
}
void CGoal::do_set_position(const CGoal::vector& pos)
{
}
FGradientFreeOptimiserBase::~FGradientFreeOptimiserBase()
{
}
CGFOptimiserFactory::CGFOptimiserFactory(char const * const name):
TFactory< FGradientFreeOptimiserBase>(name, "gfoptimiser","vscalar")
{
}
std::string const CGFOptimiserFactory::get_plugin_searchpattern()
{
return ".*_gf_optimiser.so";
}
CGoalFactory::CGoalFactory(char const * const name):
TFactory<CGoal>(name, "gfgoal","vscalar")
{
}
std::string const CGoalFactory::get_plugin_searchpattern()
{
return ".*_gf_goal.so";
}
template class TPluginHandler<CGFOptimiserFactory>;
template class TPluginHandler<CGoalFactory>;
MONA_NAMESPACE_END
/*
$Log: goal.cc,v $
Revision 1.10 2005/06/08 16:10:55 gerddie
playing around
Revision 1.9 2005/05/24 14:13:34 gerddie
save the work on symmetric registration
Revision 1.8 2005/05/23 17:10:09 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:14:58 gerddie
Add a function to get the goal 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
*/