AdaptiveDirectionRandomSearchOptimizer.h 6.8 KB

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