-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShift.h
61 lines (49 loc) · 1.87 KB
/
Shift.h
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
#ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_ShiftedObjectiveFunction_H
#define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_ShiftedObjectiveFunction_H
#include <shark/ObjectiveFunctions/AbstractObjectiveFunction.h>
#include <shark/LinAlg/rotations.h>
namespace shark {namespace benchmarks{
/// \brief Rotates an objective function using a randomly initialized rotation.
///
/// Most benchmark functions are axis aligned because it is assumed that the algorithm
/// is rotation invariant. However this does not mean that all its aspects are the same.
/// Especially linear algebra routines might take longer when the problem is not
/// axis aligned. This function creates a random rotation function and
/// applies it to the given input points to make it no longer axis aligned.
/// \ingroup benchmarks
struct ShiftedObjectiveFunction : public SingleObjectiveFunction {
ShiftedObjectiveFunction(SingleObjectiveFunction* objective)
:m_objective(objective){
if(m_objective->canProposeStartingPoint())
m_features |= CAN_PROPOSE_STARTING_POINT;
}
/// \brief From INameable: return the class name.
std::string name() const
{ return "Shifted"+m_objective->name(); }
std::size_t numberOfVariables()const{
return m_objective->numberOfVariables();
}
void init(){
m_shift = blas::repeat(1.0, m_objective->numberOfVariables());
m_objective->init();
}
bool hasScalableDimensionality()const{
return m_objective->hasScalableDimensionality();
}
void setNumberOfVariables( std::size_t numberOfVariables ){
m_objective->setNumberOfVariables(numberOfVariables);
}
SearchPointType proposeStartingPoint() const {
RealVector y = m_objective->proposeStartingPoint();
return y+m_shift;
}
double eval( SearchPointType const& p ) const {
m_evaluationCounter++;
return m_objective->eval(p - m_shift);
}
private:
SingleObjectiveFunction* m_objective;
RealVector m_shift;
};
}}
#endif