DownhillSimplexOptimizer.h 5.4 KB

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