TrustRegionBase.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - liboptimization - An optimization/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. /*****************************************************************************/
  7. #ifndef _TRUSTREGIONBASE_OPTIMIZATION_H
  8. #define _TRUSTREGIONBASE_OPTIMIZATION_H
  9. #include <iostream>
  10. #include <core/basics/NonCopyable.h>
  11. #include <core/optimization/gradientBased/OptimizationProblemFirst.h>
  12. namespace NICE {
  13. /**
  14. * Base class for trust region algorithms.
  15. * Mostly for common configuration parameters.
  16. * Notation as in Ferid Bajramovic: Kernel-basierte Objektverfolgung,
  17. * Master's thesis (Diplomarbeit),
  18. * Computer Science Department, University Passau
  19. *
  20. * \ingroup optimization_algorithms
  21. */
  22. class TrustRegionBase {
  23. public:
  24. TrustRegionBase(double typicalGradientNorm = 0.1)
  25. : eta1(0.05), eta2(0.9), alpha1(2.5), alpha2(0.25),
  26. deltaMin(1E-5), epsilonM(std::numeric_limits<double>::epsilon()),
  27. //epsilonR(0.05),
  28. epsilonR(1E-5),
  29. epsilonG(epsilonR * typicalGradientNorm),
  30. epsilonDelta(2.0 * epsilonM), epsilonRho(2.0 * epsilonM),
  31. maxIterations(10000000) {
  32. }
  33. virtual ~TrustRegionBase();
  34. /**
  35. * Specify a relative gradient threshold stopping condition by
  36. * setting \f$\epsilon_{g}\f$ via \f$\epsilon_{r}\f$.
  37. * @param _epsilonR Fraction of \c _typicalGradient to be used as threshold
  38. * \f$\epsilon_{g}\f$.
  39. * @param _typicalGradient A typical value for the gradient norm,
  40. * e.g. the current gradient norm.
  41. */
  42. inline void setEpsilonR(double _epsilonR, double _typicalGradient) {
  43. // make sure that the threshold is positive
  44. if (_typicalGradient < 1e-300) {
  45. _typicalGradient = 1e-300;
  46. }
  47. epsilonR = _epsilonR;
  48. setEpsilonG(_epsilonR * _typicalGradient);
  49. }
  50. /**
  51. * Specify an absolute gradient threshold stopping condition by
  52. * setting \f$\epsilon_{g}\f$.
  53. * @param _epsilonG Threshold
  54. */
  55. inline void setEpsilonG(double _epsilonG) {
  56. epsilonG = _epsilonG;
  57. }
  58. /**
  59. * Set the maximum number of iterations (stopping condition).
  60. * @param _maxIterations
  61. */
  62. inline void setMaxIterations(unsigned int _maxIterations) {
  63. maxIterations = _maxIterations;
  64. }
  65. /**
  66. * Set the minimum size of the trust region radius (stopping condition).
  67. * @param _deltaMin
  68. */
  69. inline void setDeltaMin(double _deltaMin) {
  70. deltaMin = _deltaMin;
  71. }
  72. /**
  73. * Set the parameter eta1.
  74. * @param _eta1
  75. */
  76. inline void setEta1(double _eta1 = 0.05) {
  77. eta1 = _eta1;
  78. }
  79. /**
  80. * Set the parameter eta2.
  81. * @param _eta2
  82. */
  83. inline void setEta2(double _eta2 = 0.9) {
  84. eta2 = _eta2;
  85. }
  86. /**
  87. * Set the parameter alpha1
  88. * @param _alpha1
  89. */
  90. inline void setAlpha1(double _alpha1 = 2.5) {
  91. alpha1 = _alpha1;
  92. }
  93. /**
  94. * Set the parameter alpha2
  95. * @param _alpha2
  96. */
  97. inline void setAlpha2(double _alpha2 = 2.5) {
  98. alpha2 = _alpha2;
  99. }
  100. protected:
  101. //! \f$\eta_1\f$
  102. double eta1;
  103. //! \f$\eta_2\f$
  104. double eta2;
  105. //! \f$\mu_1\f$
  106. double alpha1;
  107. //! \f$\mu_2\f$
  108. double alpha2;
  109. // //! \f$\Delta\f$
  110. // double delta;
  111. //! \f$\Delta_{\min}\f$
  112. double deltaMin;
  113. //! \f$\epsilon_{M}\f$
  114. double epsilonM;
  115. //! \f$\epsilon_{r}\f$
  116. double epsilonR;
  117. //! \f$\epsilon_{g}\f$: threshold on gradient norm (stopping condition)
  118. double epsilonG;
  119. //! \f$\epsilon_{\Delta}\f$
  120. double epsilonDelta;
  121. //! \f$\epsilon_{\rho}\f$
  122. double epsilonRho;
  123. //! maximum number of iterations
  124. int maxIterations;
  125. /**
  126. * Check if the change by step \c step is numerically minimal
  127. * (relative to the current \c position in parameter space).
  128. */
  129. bool changeIsMinimal(const Vector& step,
  130. const Vector& position);
  131. };
  132. }; // namespace NICE
  133. #endif /* _TRUSTREGIONBASE_OPTIMIZATION_H */