RotatedErrorFunction.h
Go to the documentation of this file.
1/*!
2 *
3 *
4 * \brief Implements a wrapper over an m_objective function which just rotates its inputs
5 *
6 *
7 * \author O.Voss
8 * \date 2010-2014
9 *
10 *
11 * \par Copyright 1995-2017 Shark Development Team
12 *
13 * <BR><HR>
14 * This file is part of Shark.
15 * <https://shark-ml.github.io/Shark/>
16 *
17 * Shark is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Lesser General Public License as published
19 * by the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * Shark is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29 *
30 */
31#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_ROTATEDOBJECTIVEFUNCTION_H
32#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_ROTATEDOBJECTIVEFUNCTION_H
33
36
37namespace shark {namespace benchmarks{
38/// \brief Rotates an objective function using a randomly initialized rotation.
39///
40/// Most benchmark functions are axis aligned because it is assumed that the algorithm
41/// is rotation invariant. However this does not mean that all its aspects are the same.
42/// Especially linear algebra routines might take longer when the problem is not
43/// axis aligned. This function creates a random rotation function and
44/// applies it to the given input points to make it no longer axis aligned.
45/// \ingroup benchmarks
48 :m_objective(objective){
49 if(m_objective->canProposeStartingPoint())
51 if(m_objective->hasFirstDerivative())
53 }
54
55 /// \brief From INameable: return the class name.
56 std::string name() const
57 { return "RotatedObjectiveFunction<"+m_objective->name()+">"; }
58
59 std::size_t numberOfVariables()const{
60 return m_objective->numberOfVariables();
61 }
62
63 void init(){
65 m_objective->setRng(mep_rng);
66 m_objective->init();
67 }
68
70 return m_objective->hasScalableDimensionality();
71 }
72
76
78 RealVector y = m_objective->proposeStartingPoint();
79
80 return prod(trans(m_rotation),y);
81 }
82
83 double eval( SearchPointType const& p ) const {
85 RealVector x = prod(m_rotation,p);
86 return m_objective->eval(x);
87 }
88
90 RealVector x = prod(m_rotation,p);
91 double value = m_objective->evalDerivative(x,derivative);
92 derivative = prod(trans(m_rotation),derivative);
93 return value;
94 }
95private:
96 SingleObjectiveFunction* m_objective;
97 RealMatrix m_rotation;
98};
99
100}}
101
102#endif