Himmelblau.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Two-dimensional, real-valued Himmelblau function.
5  *
6  * Multi-modal benchmark function.
7  *
8  *
9  *
10  * \author -
11  * \date -
12  *
13  *
14  * \par Copyright 1995-2017 Shark Development Team
15  *
16  * <BR><HR>
17  * This file is part of Shark.
18  * <http://shark-ml.org/>
19  *
20  * Shark is free software: you can redistribute it and/or modify
21  * it under the terms of the GNU Lesser General Public License as published
22  * by the Free Software Foundation, either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * Shark is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU Lesser General Public License
31  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
32  *
33  */
34 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_HIMMELBLAU_H
35 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARK_HIMMELBLAU_H
36 
38 #include <shark/Core/Random.h>
39 
40 namespace shark {
41 /**
42 * \brief Multi-modal two-dimensional continuous Himmelblau benchmark function.
43 *
44 * Implements Himmelblau's real-valued, multi-modal benchmark function. The
45 * function is limited to two dimensions. Please see:
46 * http://en.wikipedia.org/wiki/Himmelblau%27s_function
47 * for further information.
48 */
50  /**
51  * \brief Constructs an instance of the function.
52  */
55  }
56 
57  /// \brief From INameable: return the class name.
58  std::string name() const
59  { return "Himmelblau"; }
60 
61  std::size_t numberOfVariables()const{
62  return 2;
63  }
64 
66  RealVector x(numberOfVariables());
67 
68  for (std::size_t i = 0; i < x.size(); i++) {
69  x(i) = random::uni(*mep_rng, -3,3);
70  }
71  return x;
72  }
73 
74  /**
75  * \brief Evaluates the function for the supplied search point.
76  * \throws shark::Exception if the size of p does not equal 2.
77  */
78  double eval( const SearchPointType & p ) const {
79  SIZE_CHECK(p.size() == 2);
80 
82 
83  return(
84  sqr( sqr( p( 0 ) ) + p( 1 ) - 11 ) +
85  sqr( p( 0 ) + sqr( p( 1 ) ) - 7 )
86  );
87  }
88 };
89 
90 }
91 
92 #endif