CostFunction_ndim_2ndOrder.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. class CostFunction_ndim_2ndOrder : public CostFunction
  14. {
  15. public:
  16. typedef CostFunction SuperClass;
  17. typedef SuperClass::matrix_type matrix_type;
  18. /*!
  19. default constructor
  20. */
  21. CostFunction_ndim_2ndOrder();
  22. /*!
  23. Constructor.
  24. \param dim of parameter space
  25. */
  26. CostFunction_ndim_2ndOrder(unsigned int dim);
  27. /*!
  28. Copy constructor
  29. \param func the function to copy
  30. */
  31. CostFunction_ndim_2ndOrder(const CostFunction_ndim_2ndOrder &func);
  32. /*!
  33. = operator
  34. */
  35. CostFunction_ndim_2ndOrder &operator=(const CostFunction_ndim_2ndOrder & func);
  36. /*!
  37. Destructor.
  38. */
  39. ~CostFunction_ndim_2ndOrder();
  40. /*!
  41. initializations
  42. */
  43. void init();
  44. /*!
  45. set A, b, and c
  46. \param A
  47. \param b
  48. \param c
  49. \return 0 in case of success.
  50. */
  51. int setAbc(const matrix_type & A,const matrix_type &b, double c);
  52. /*!
  53. evaluate the costfunction
  54. \param parameter to evaluate at
  55. */
  56. double evaluate(const matrix_type & parameter);
  57. /*!
  58. get the analytic Gradient
  59. */
  60. const matrix_type getAnalyticGradient(const matrix_type &parameter);
  61. protected:
  62. /*!
  63. the matrix A of
  64. f(x) = 0.5 * x^T * A * x + b^T * x + c
  65. */
  66. matrix_type m_A;
  67. /*!
  68. the vector b^T of
  69. f(x) = 0.5 * x^T * A * x + b^T * x + c
  70. */
  71. matrix_type m_bt;
  72. /*
  73. the value c of
  74. f(x) = 0.5 * x^T * A * x + b^T * x + c
  75. */
  76. double m_c;
  77. };
  78. #endif