CostFunction_ndim_2ndOrder.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. // CostFunction_ndim_2ndOrder.h: interface of a test CostFunction class.
  4. //
  5. // Written By: Matthias Wacker
  6. //
  7. // f(x) = 0.5 * x^T * A * x + b^T * x + c
  8. //
  9. //////////////////////////////////////////////////////////////////////
  10. #ifndef _COSTFUNCTION_NDIM_2NDORDER_H_
  11. #define _COSTFUNCTION_NDIM_2NDORDER_H_
  12. #include "core/optimization/blackbox/CostFunction.h"
  13. namespace OPTIMIZATION
  14. {
  15. class CostFunction_ndim_2ndOrder : public CostFunction
  16. {
  17. public:
  18. typedef CostFunction SuperClass;
  19. typedef SuperClass::matrix_type matrix_type;
  20. /*!
  21. default constructor
  22. */
  23. CostFunction_ndim_2ndOrder();
  24. /*!
  25. Constructor.
  26. \param dim of parameter space
  27. */
  28. CostFunction_ndim_2ndOrder(unsigned int dim);
  29. /*!
  30. Copy constructor
  31. \param func the function to copy
  32. */
  33. CostFunction_ndim_2ndOrder(const CostFunction_ndim_2ndOrder &func);
  34. /*!
  35. = operator
  36. */
  37. CostFunction_ndim_2ndOrder &operator=(const CostFunction_ndim_2ndOrder & func);
  38. /*!
  39. Destructor.
  40. */
  41. ~CostFunction_ndim_2ndOrder();
  42. /*!
  43. initializations
  44. */
  45. void init();
  46. /*!
  47. set A, b, and c
  48. \param A
  49. \param b
  50. \param c
  51. \return 0 in case of success.
  52. */
  53. int setAbc(const matrix_type & A,const matrix_type &b, double c);
  54. /*!
  55. evaluate the costfunction
  56. \param parameter to evaluate at
  57. */
  58. double evaluate(const matrix_type & parameter);
  59. /*!
  60. get the analytic Gradient
  61. */
  62. const matrix_type getAnalyticGradient(const matrix_type &parameter);
  63. protected:
  64. /*!
  65. the matrix A of
  66. f(x) = 0.5 * x^T * A * x + b^T * x + c
  67. */
  68. matrix_type m_A;
  69. /*!
  70. the vector b^T of
  71. f(x) = 0.5 * x^T * A * x + b^T * x + c
  72. */
  73. matrix_type m_bt;
  74. /*
  75. the value c of
  76. f(x) = 0.5 * x^T * A * x + b^T * x + c
  77. */
  78. double m_c;
  79. }; //class
  80. }//namespace
  81. #endif