11 #ifndef PRIMATOLOGIST_OPTIMIZATION_WOLFE_D_H 12 #define PRIMATOLOGIST_OPTIMIZATION_WOLFE_D_H 105 template <
typename O>
111 template <
typename O>
117 template <
typename O>
123 template <
typename O>
129 template <
typename O>
135 template <
typename O>
145 template <
typename O>
151 template <
typename O>
157 template <
typename O>
164 template <
typename O>
171 template <
typename O>
178 template <
typename O>
184 template <
typename O>
190 template <
typename O>
196 template <
typename O>
206 template <
typename O>
212 std::cout << std::string(80,
'-') << std::endl;
213 std::cout << std::setw(7) <<
"Search " 214 << std::setw(4) <<
"i " 215 << std::setw(15) <<
"f" 216 << std::setw(15) <<
"a" 218 std::cout << std::string(80,
'-') << std::endl;
223 std::cout << std::setw(7) <<
"W" 226 << std::setw(15) << std::setprecision(5) << 0.;
234 << std::string(
maximize() ?
"an ascent" :
"a descent" )
235 << std::string(
" direction." ) << std::endl;
240 std::cout << std::endl;
245 float a_min = 0., a_max;
246 bool a_max_set =
false;
261 std::cout << std::setw(7) <<
"W" 264 << std::setw(15) << std::setprecision(5) << a
270 a = ( a_max - a_min ) / 2. + a_min;
276 std::cout << std::setw(7) <<
"W" 279 << std::setw(15) << std::setprecision(5) << a
286 a = ( a_max - a_min ) / 2. + a_min;
294 std::cout << std::setw(7) <<
"W" 297 << std::setw(15) << std::setprecision(5) << a
307 std::cout <<
"Maximum number of iterations reached." << std::endl;
316 template <
typename O>
327 template <
typename O>
337 template <
typename O>
343 return current_scalarprod <= righthand;
345 return current_scalarprod >= righthand;
348 template <
typename O>
353 return std::abs(current_scalarprod) <= std::abs(righthand);
356 template <
typename O>
367 #endif // PRIMATOLOGIST_OPTIMIZATION_WOLFE_D_H int _max_it
maximum number of iterations
void setMaximize(bool maximize=false)
void setPosition(const Vector &x=Vector())
WolfeLineSearch(const Objective &f=Objective(), const Vector &x=Vector(), const Vector &p=Vector())
bool wolfe2s(float a) const
strong 2nd Wolfe condition
const T & at(const carto::VolumeRef< T > &vol, long px, long py, long pz, long pt, const Point4dl &fullsize, const Point4dl &binf)
float _current_value
f(x + a.p)
MatrixBase< T > transpose(const MatrixBase< T > &)
Matrix transposition.
void setSearchDirection(const Vector &p=Vector())
WolfeLineSearch< O > & operator=(const WolfeLineSearch< O > &other)
void setVerbose(int v=carto::verbose)
bool wolfe2(float a) const
select condition based on _strong
bool checkDirection()
Compute f(x) and <p, g(x)>.
void setMaxIterations(int n=- 1)
const Vector & searchDirection() const
Matrix class implementing matrix operations.
bool wolfe2w(float a) const
weak 2nd Wolfe condition
const Objective & objectiveFunction() const
float _previous_value
f(x)
void setStrongWolfe(bool strong=false)
void setObjectiveFunction(const Objective &f)
void setC1(float c1=1E-4)
bool wolfe1(float a) const
Armijo (= Wolfe 1st) condition.
int maxIterations() const
Objective _f
objectiveFunction
int _verbose
verbosity level
Once an ascent direction is given, this class performs a line search that respects wolfe conditions...
bool _maximize
maximize or minimize
float _previous_scalarprod
<p, g(x)>
const Vector & position() const