42 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_ROSENBROCK_H 43 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_ROSENBROCK_H 65 Rosenbrock(std::size_t dimensions=23,
double initialSpread = 1.0)
66 :m_numberOfVariables(dimensions), m_initialSpread(initialSpread) {
74 {
return "Rosenbrock"; }
77 return m_numberOfVariables;
91 for (std::size_t i = 0; i < x.size(); i++) {
102 for( std::size_t i = 0; i < p.size()-1; i++ ) {
103 sum += 100*
sqr( p(i+1) -
sqr( p( i ) ) ) +
sqr( 1. - p( i ) );
110 double result =
eval(p);
111 size_t size = p.size();
112 derivative.resize(size);
113 derivative(0) = 2*( p(0) - 1 ) - 400 * ( p(1) -
sqr( p(0) ) ) * p(0);
114 derivative(size-1) = 200 * ( p(size - 1) -
sqr( p( size - 2 ) ) ) ;
115 for(
size_t i=1; i != size-1; ++i){
116 derivative( i ) = 2 * ( p(i) - 1 ) - 400 * (p(i+1) -
sqr( p(i) ) ) * p( i )+200 * ( p( i )-
sqr( p(i-1) ) );
123 double result =
eval(p);
124 size_t size = p.size();
126 derivative.
hessian.resize(size,size);
129 derivative.
gradient(0) = 2*( p(0) - 1 ) - 400 * ( p(1) -
sqr( p(0) ) ) * p(0);
130 derivative.
gradient(size-1) = 200 * ( p(size - 1) -
sqr( p( size - 2 ) ) ) ;
132 derivative.
hessian(0,0) = 2 - 400* (p(1) - 3*
sqr(p(0))) ;
133 derivative.
hessian(0,1) = -400 * p(0) ;
135 derivative.
hessian(size-1,size-1) = 200;
136 derivative.
hessian(size-1,size-2) = -400 * p( size - 2 );
138 for(
size_t i=1; i != size-1; ++i){
139 derivative.
gradient( i ) = 2 * ( p(i) - 1 ) - 400 * (p(i+1) -
sqr( p(i) ) ) * p( i )+200 * ( p( i )-
sqr( p(i-1) ) );
141 derivative.
hessian(i,i) = 202 - 400 * ( p(i+1) - 3 *
sqr(p(i)));
142 derivative.
hessian(i,i+1) = - 400 * ( p(i) );
143 derivative.
hessian(i,i-1) = - 400 * ( p(i-1) );
150 std::size_t m_numberOfVariables;
151 double m_initialSpread;