DownhillSimplexOptimizer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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(double alpha, double beta, 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. /// Returns the status of rankcheck
  78. /// @retval true, if rankcheck is enabled
  79. /// @retval false, if rankcheck is disabled
  80. ///
  81. bool getRankCheckStatus();
  82. ///
  83. /// Do internal initializations
  84. ///
  85. void init();
  86. protected:
  87. ///
  88. /// start optimization
  89. ///
  90. virtual int optimize();
  91. private:
  92. ///
  93. /// Initialize the whole simplex, for that, numOfParameters+1 points a needed.
  94. /// (You might want to detemine these points by a random search before)
  95. /// @param simplex : Matrix containing numOfParameters+1 points
  96. /// that are numOfParameters-dimensional
  97. /// @return bool : indicating if attempt was successfull
  98. /// (might not, if dimensions don't match)
  99. ///
  100. bool setWholeSimplex(const matrix_type &simplex);
  101. ///
  102. /// internal bool to store if simplex is initialized
  103. ///
  104. bool m_simplexInitialized;
  105. ///
  106. /// internal bool to offer a break in all internal functions
  107. ///
  108. bool m_abort;
  109. ///
  110. /// internal parameter to control the transformations of the simplex
  111. ///
  112. double m_alpha;
  113. ///
  114. /// internal parameter to control the transformations of the simplex
  115. ///
  116. double m_gamma;
  117. ///
  118. /// internal parameter to control the transformations of the simplex
  119. ///
  120. double m_beta;
  121. ///
  122. ///This method does the optimization itself.
  123. /// It is called by optimize and returns the index of the "final"
  124. /// vertice matrix that is the lowest / highest point found.
  125. ///
  126. int amoeba();
  127. ///
  128. /// This method does the extrapolation of highest vertice through the
  129. /// simplex by the factor fac. It is called by amoeba()
  130. ///
  131. double amotry(matrix_type& psum,int ihi, double fac);
  132. ///
  133. /// Matrix containing the vertices of the simplex
  134. ///
  135. matrix_type m_vertices;
  136. ///
  137. /// Matrix(1dim) containing the function values corresponding to
  138. /// vertices
  139. ///
  140. matrix_type m_y;
  141. ///
  142. /// Rang deficiency threshold
  143. ///
  144. float m_rankdeficiencythresh;
  145. ///
  146. /// Rank check status: if false, a rank check is disabled (default)
  147. ///
  148. bool m_rankcheckenabled;
  149. };
  150. ///
  151. /// Check Rank of a matrix_type where singular values lower than numZero
  152. /// are treated as zero. The computation is done by singular value
  153. /// decomposition. Returns the numerical rank
  154. /// of the matrix
  155. ///
  156. /// @param A matrix to compute rank of..
  157. /// @param numZero threshold to decide for numerical zero
  158. /// @return (numerical) rank of A
  159. ///
  160. unsigned int getRank(const optimization::matrix_type& A, double numZero);
  161. #endif