AdaptiveDirectionRandomSearchOptimizer.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. // AdaptiveDirectionRandomSearchOptimizer.h: interface of the ADRS optimizer.
  4. //
  5. /////////////////////////////////////////////////////////////////////////
  6. #ifndef _ADAPTIVE_DIRECTION_RANDOM_SEARCH_OPTIMIZER_
  7. #define _ADAPTIVE_DIRECTION_RANDOM_SEARCH_OPTIMIZER_
  8. #include "core/optimization/blackbox/SimpleOptimizer.h"
  9. #include "core/optimization/blackbox/Definitions_core_opt.h"
  10. namespace OPTIMIZATION
  11. {
  12. ///
  13. /// Class AdaptiveDirectionRandomSearchOptimizer
  14. ///
  15. /// HowToUse:
  16. ///
  17. /// * specify in the constructor call the num of points that are optimized in a "simultanious" way
  18. /// * to use others than the default parameters use the setControlSeqParams call which changes the
  19. /// parameters that are responsible for a "scale down" of b_k by b_fac if there was no function
  20. /// decrease for b_times times
  21. /// * to use others than the default parameters use the setRecallParams call wich changes the
  22. /// parameters that are responsible for the balance between a new random direction an the old
  23. /// successfull iteration directions
  24. /// * use the setLowerParameterBounds and the setUpperParameterBounds to specify the area to generate
  25. /// random start points in (THIS IS NESSECARY!)
  26. /// * to use a function value threshold for the random start points' values to be below - use the
  27. /// setInitFunctionValueThresh call
  28. /// * call init()
  29. /// * call optimize()
  30. ///
  31. /// Implemented Abort criteria:
  32. ///
  33. /// * maximum number of iterations
  34. /// * parameter tolerance
  35. /// * time limit
  36. ///
  37. ///
  38. class AdaptiveDirectionRandomSearchOptimizer : public SimpleOptimizer
  39. {
  40. public:
  41. typedef SimpleOptimizer SuperClass;
  42. typedef OPTIMIZATION::matrix_type matrix_type;
  43. ///
  44. /// Constructor.
  45. /// @param numOfPoints: Number of Points to optimize
  46. /// @param loger : OptLogBase * to existing log class
  47. ///
  48. AdaptiveDirectionRandomSearchOptimizer(unsigned int numOfPoints, OptLogBase *loger=NULL);
  49. ///
  50. /// Copy constructor
  51. /// @param opt .. optimizer to copy
  52. ///
  53. AdaptiveDirectionRandomSearchOptimizer( const AdaptiveDirectionRandomSearchOptimizer &opt);
  54. ///
  55. /// operator =
  56. ///
  57. AdaptiveDirectionRandomSearchOptimizer & operator=(const AdaptiveDirectionRandomSearchOptimizer &opt);
  58. ///
  59. ///
  60. /// Destructor.
  61. ///
  62. ~AdaptiveDirectionRandomSearchOptimizer();
  63. ///
  64. /// enumeration for the return reasons of an optimizer,
  65. /// has all elements of the SuperClass optimizer
  66. ///
  67. ///
  68. /// @brief Do internal initializations
  69. ///
  70. void init();
  71. ///
  72. /// @brief start the optmization
  73. ///
  74. int optimize();
  75. ///
  76. /// @brief set the parameters for the control sequence
  77. ///
  78. /// @param b0 > 0
  79. /// @param bfac: 0 < bfac < 1
  80. /// @param bThresTimesNotDecreased
  81. ///
  82. /// \return true in case of success
  83. ///
  84. bool setControlSeqParams(double b0, double bfac, unsigned int bThresTimesNotDecreased, double bBreak);
  85. ///
  86. /// @brief Enables advanced initialization of random start points. If activated, start points will be randomly distributed according to the upper and lower bound vectors.
  87. ///
  88. /// @param enable if true, advanced initialization will be enabled
  89. /// @param lowerBound matrix containing lower bounds for random initialization (must be nx1 with n= number of Parameters)
  90. /// @param upperBound matrix containing upper bounds for random initialization (must be nx1 with n= number of Parameters)
  91. ///
  92. void activateAdvancedInit(bool enable, matrix_type& lowerBounds, matrix_type& upperBounds);
  93. ///
  94. /// @brief set recall parameters that control the incluence of prior iterations on the actual one. This is the key idea of the adaptive direction approach
  95. ///
  96. /// The update formula for the iteration scheme is
  97. ///
  98. /// $$
  99. /// d_k = c_0 * d_{k-1} + c_1 \triangle x_{k-1}
  100. /// $$
  101. /// with
  102. /// if( $\delta_{k-1} == 1$)
  103. /// {
  104. /// $ c_0 = c0s,\enskip c_1 = c_1s $
  105. /// and
  106. /// $0 < c0s < 1;\enskip c1s >0 ;\enskip c0s + c1s > 1 $
  107. /// }
  108. /// else
  109. /// {
  110. /// $ c_0 = c0f,\enskip c_1 = c_1f $
  111. /// and
  112. /// $0 < c0f < 1;\enskip c1f < 0 ;\enskip | c0s + c1s | < 1 $
  113. /// }
  114. /// and
  115. /// \|d_k\| < D * b_k
  116. ///
  117. /// @param c0s
  118. /// @param c1s
  119. /// @param c0f
  120. /// @param c1f
  121. /// @param D
  122. ///
  123. /// \return true in case of success
  124. ///
  125. bool setRecallParams(double c0s, double c1s, double c0f, double c1f, double D);
  126. ///
  127. /// @brief set Number of Points
  128. /// @param num number of points
  129. ///
  130. inline void setNumberOfPoints(unsigned int num){m_numberOfParallelPoints = num;};
  131. ///
  132. /// @brief set a threshold for the initial points
  133. /// @param active is the threshold active?
  134. /// @param threshold .. the threshold to be below (above in case of maximization)
  135. ///
  136. inline void setInitFunctionValueThresh(bool active, double threshold){m_initFuncThreshActive = active;m_initFuncTresh = threshold;};
  137. private:
  138. ///
  139. /// number of parallel point optimizations
  140. ///
  141. unsigned int m_numberOfParallelPoints;
  142. ///
  143. /// matrix of the whole parameter set
  144. ///
  145. matrix_type m_Parameters;
  146. ///
  147. /// matrix of costfunction Values
  148. ///
  149. matrix_type m_CurrentCostFunctionValues;
  150. ///
  151. /// generate new points
  152. ///
  153. matrix_type generatePoints();
  154. ///
  155. /// generate new points
  156. ///
  157. matrix_type generatePoint();
  158. ///
  159. /// @brief accept a new point or reject it
  160. /// @param newValue : new objective function value
  161. /// @param oldValue : old objective function value
  162. ///
  163. ///
  164. void acceptPoints(matrix_type oldValues, matrix_type newValues);
  165. bool *m_pointsAccepted;
  166. ///
  167. /// control sequence parameter b0
  168. ///
  169. double m_b0;
  170. ///
  171. /// control sequence parameter bfac
  172. ///
  173. double m_bfac;
  174. ///
  175. /// control sequence parameter bk
  176. ///
  177. double *m_bk;
  178. ///
  179. /// control sequence multiplikation trigger threshold
  180. ///
  181. unsigned int m_bThresTimesNotDecreased;
  182. ///
  183. /// control sequence parameter bBreak
  184. ///
  185. double m_bBreak;
  186. ///
  187. /// backup point
  188. ///
  189. matrix_type m_backupPoint;
  190. ///
  191. /// backup point Value
  192. ///
  193. double m_backupPointValue;
  194. ///
  195. /// backup point in use?
  196. ///
  197. bool m_backupActive;
  198. ///
  199. /// direction parameter c0s
  200. ///
  201. double m_c0s;
  202. ///
  203. /// direction parameter c1s
  204. ///
  205. double m_c1s;
  206. ///
  207. /// direction parameter c0f
  208. ///
  209. double m_c0f;
  210. ///
  211. /// direction parameter c1f
  212. ///
  213. double m_c1f;
  214. ///
  215. /// recall limit
  216. ///
  217. double m_D;
  218. ///
  219. /// is the initial function value threshold active
  220. ///
  221. bool m_initFuncThreshActive;
  222. ///
  223. /// the initial function value threshold active
  224. ///
  225. double m_initFuncTresh;
  226. ///
  227. /// enables advanced initialization
  228. bool m_advancedInit;
  229. ///
  230. /// lower bounds for advanced initialization
  231. ///
  232. matrix_type m_advancedinitLowerBounds;
  233. ///
  234. /// upper bounds for advanced initialization
  235. matrix_type m_advancedinitUpperBounds;
  236. };//class
  237. } //namespace
  238. #endif