DownhillSimplexOptimizer.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. ///
  2. ///
  3. /// @file: DownhillSimplexOptimizer.h: interface of the downhill Simplex Optimier
  4. /// @author: Matthias Wacker, Esther Platzer, Alexander Freytag
  5. /// @date: 27-09-2012 (last updated)
  6. ///
  7. ///
  8. #ifndef _DOWNHILL_SIMPLEX_OPTIMIZER_H_
  9. #define _DOWNHILL_SIMPLEX_OPTIMIZER_H_
  10. #include <cmath>
  11. #include "core/optimization/blackbox/SimpleOptimizer.h"
  12. namespace OPTIMIZATION {
  13. ///
  14. /// @class DownhillSimplexOptimizer
  15. ///
  16. /// HowToUse:
  17. ///
  18. /// * use setWholeSimplex to initialize the whole simplex OR use setParameters()
  19. /// * use setParameters() to specify one point of the simplex (currently not implemented)
  20. /// the init call will then generate random disturbations to
  21. /// generate a full rank simplex
  22. /// * use setDownhillParams() to use others than the default to "move"
  23. /// the simplex
  24. /// * call init() for setting up everything and evaluate your function on your initial simplex
  25. /// * call optimize() to run the actual optimization
  26. ///
  27. ///
  28. /// Implemented Abort criteria:
  29. ///
  30. /// * maximum number of iterations (currently deactivated)
  31. /// * time limit exceeded (default: deactivated)
  32. /// * parameter bounds
  33. /// * function value tolerance (default: 1e-6)
  34. /// * parameter tolerance
  35. ///
  36. /// Additional return reason:
  37. /// - none
  38. ///
  39. class DownhillSimplexOptimizer : public SimpleOptimizer
  40. {
  41. public:
  42. typedef SimpleOptimizer SuperClass;
  43. typedef SuperClass::matrix_type matrix_type;
  44. ///
  45. /// Constructor
  46. /// @param loger : OptLogBase * to existing log class or NULL
  47. ///
  48. DownhillSimplexOptimizer(OptLogBase *loger=NULL);
  49. ///
  50. /// CopyConstructor
  51. /// @param opt : DownhillSimplexOptimizer to copy
  52. ///
  53. DownhillSimplexOptimizer(const DownhillSimplexOptimizer &opt);
  54. ///
  55. ///
  56. ///
  57. ~DownhillSimplexOptimizer();
  58. ///
  59. /// set downhill specific parameters
  60. /// @param alpha
  61. /// @param beta
  62. /// @param gamma
  63. ///
  64. void setDownhillParams(const double alpha, const double beta, const double gamma);
  65. ///
  66. /// Sets the rank deficiency threshold
  67. /// @param rankdeficiencythresh rank deficiency threshold (DEFAULT= 0.01)
  68. ///
  69. void setRankDeficiencyThresh(float rankdeficiencythresh);
  70. ///
  71. /// Enable or disable the rank check
  72. /// @param status give the status for a rank check
  73. ///
  74. void setRankCheckStatus(bool status);
  75. /**
  76. * @brief get the downhill simplex parameter alpha, needed for the reflection
  77. * @date 27-09-2012
  78. * @author Alexander Freytag
  79. */
  80. double getDownhillParameterAlpha() const;
  81. /**
  82. * @brief get the downhill simplex parameter alpha, needed for the contraction
  83. * @date 27-09-2012
  84. * @author Alexander Freytag
  85. */
  86. double getDownhillParameterBeta() const;
  87. /**
  88. * @brief get the downhill simplex parameter alpha, needed for the expansion
  89. * @date 27-09-2012
  90. * @author Alexander Freytag
  91. */
  92. double getDownhillParameterGamma() const;
  93. ///
  94. /// Returns the status of rankcheck
  95. /// @retval true, if rankcheck is enabled
  96. /// @retval false, if rankcheck is disabled
  97. ///
  98. bool getRankCheckStatus();
  99. ///
  100. /// Do internal initializations
  101. ///
  102. void init();
  103. protected:
  104. ///
  105. /// start optimization
  106. ///
  107. virtual int optimize();
  108. private:
  109. ///
  110. /// Initialize the whole simplex, for that, numOfParameters+1 points a needed.
  111. /// (You might want to detemine these points by a random search before)
  112. /// @param simplex : Matrix containing numOfParameters+1 points
  113. /// that are numOfParameters-dimensional
  114. /// @return bool : indicating if attempt was successfull
  115. /// (might not, if dimensions don't match)
  116. ///
  117. bool setWholeSimplex(const matrix_type &simplex);
  118. ///
  119. /// internal bool to store if simplex is initialized
  120. ///
  121. bool m_simplexInitialized;
  122. ///
  123. /// internal bool to offer a break in all internal functions
  124. ///
  125. bool m_abort;
  126. ///
  127. /// internal parameter to control the transformations of the simplex
  128. ///
  129. double m_alpha;
  130. ///
  131. /// internal parameter to control the transformations of the simplex
  132. ///
  133. double m_gamma;
  134. ///
  135. /// internal parameter to control the transformations of the simplex
  136. ///
  137. double m_beta;
  138. ///
  139. /// This method does the optimization itself.
  140. /// It is called by optimize and returns the index of the "final"
  141. /// vertice matrix that is the lowest / highest point found (int).
  142. ///
  143. int amoeba();
  144. ///
  145. /// This method does the extrapolation of highest vertice through the
  146. /// simplex by the factor fac. It is called by amoeba()
  147. ///
  148. double amotry(matrix_type& psum,int ihi, double fac);
  149. ///
  150. /// Matrix containing the vertices of the simplex
  151. ///
  152. matrix_type m_vertices;
  153. ///
  154. /// Matrix(1dim) containing the function values corresponding to
  155. /// vertices
  156. ///
  157. matrix_type m_y;
  158. ///
  159. /// Rang deficiency threshold
  160. ///
  161. float m_rankdeficiencythresh;
  162. ///
  163. /// Rank check status: if false, a rank check is disabled (default)
  164. ///
  165. bool m_rankcheckenabled;
  166. }; //class
  167. // ///
  168. // /// Check Rank of a matrix_type where singular values lower than numZero
  169. // /// are treated as zero. The computation is done by singular value
  170. // /// decomposition. Returns the numerical rank
  171. // /// of the matrix
  172. // ///
  173. // /// @param A matrix to compute rank of..
  174. // /// @param numZero threshold to decide for numerical zero
  175. // /// @return (numerical) rank of A
  176. // ///
  177. // unsigned int getRank(const optimization::matrix_type& A, double numZero);
  178. } // namespace
  179. #endif