BFGSOptimizer.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //////////////////////////////////////////////////////////////////////
  2. //
  3. // NewtonMethodOptimizer.cpp: Implementation of the NewtonMethodOptimizer
  4. // Optimizer class.
  5. //
  6. // Written by Matthias Wacker
  7. //
  8. //////////////////////////////////////////////////////////////////////
  9. #include "optimization/BFGSOptimizer.h"
  10. using namespace OPTIMIZATION;
  11. BFGSOptimizer::BFGSOptimizer(OptLogBase *loger) : SuperClass(loger)
  12. {
  13. }
  14. BFGSOptimizer::BFGSOptimizer( const BFGSOptimizer &opt) : SuperClass(opt)
  15. {
  16. }
  17. BFGSOptimizer::~BFGSOptimizer()
  18. {
  19. }
  20. void BFGSOptimizer::init()
  21. {
  22. SuperClass::init();
  23. }
  24. BFGSOptimizer & BFGSOptimizer::operator=(const BFGSOptimizer &opt)
  25. {
  26. /*
  27. avoid self-copy
  28. */
  29. if(this != &opt)
  30. {
  31. /*
  32. =operator of SuperClass
  33. */
  34. SuperClass::operator=(opt);
  35. }
  36. return *this;
  37. }
  38. void BFGSOptimizer::updateIterationMatrix()
  39. {
  40. matrix_type pk = m_parameters - m_oldParams;
  41. matrix_type rk = m_gradient - m_oldGradient;
  42. matrix_type rkt= rk.transpose();
  43. matrix_type pkt= pk.transpose();
  44. m_IterationMatrix = m_IterationMatrix
  45. + (rk * rkt) * (1.0/ (rkt * pk)(0,0))
  46. - (m_IterationMatrix * pk * pkt * m_IterationMatrix) * (1.0/ (pkt * m_IterationMatrix * pk)(0,0));
  47. }