DownhillSimplexOptimizer.h 5.6 KB

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