ILSConjugateGradients.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file ILSConjugateGradients.h
  3. * @author Erik Rodner
  4. * @date 12/21/2011
  5. */
  6. #ifndef _NICE_ILSConjugateGradients_INCLUDE
  7. #define _NICE_ILSConjugateGradients_INCLUDE
  8. #include "core/vector/VectorT.h"
  9. #include "GenericMatrix.h"
  10. #include "IterativeLinearSolver.h"
  11. namespace NICE {
  12. /** @class ILSConjugateGradients
  13. * Iteratively solving linear equation systems with the conjugate gradients method
  14. *
  15. * @author Erik Rodner
  16. */
  17. class ILSConjugateGradients : public IterativeLinearSolver
  18. {
  19. protected:
  20. bool verbose;
  21. uint maxIterations;
  22. double minDelta;
  23. double minResidual;
  24. bool useFlexibleVersion;
  25. bool timeAnalysis;
  26. Vector jacobiPreconditioner;
  27. public:
  28. /**
  29. * @brief constructor
  30. *
  31. * @param verbose output the residual and some debug information for each iteration
  32. * @param maxIterations maximum number of iterations
  33. * @param minDelta minimum difference between two solutions x_t and x_{t+1}
  34. * @param useFlexibleVersion use the Polak-Ribiere formula instead of the Fletcher–Reeves formula (we did not see any benefit from it)
  35. */
  36. ILSConjugateGradients( bool verbose = false, uint maxIterations = 10000, double minDelta = 1e-7, double minResidual = 1e-20, bool useFlexibleVersion = false);
  37. /** simple destructor */
  38. virtual ~ILSConjugateGradients();
  39. /**
  40. * @brief set a vector of diagonal elements for the jacobi preconditioner
  41. *
  42. * @param jacobiPreconditioner
  43. */
  44. void setJacobiPreconditioner ( const Vector & jacobiPreconditioner );
  45. /**
  46. * @brief Solve the linear System A*x = b, where A is indirectly presented
  47. * by the GenericMatrix gm
  48. *
  49. * @param gm GenericMatrix providing matrix-vector multiplications
  50. * @param b Vector on the right hand side of the system
  51. * @param x initial and final estimate
  52. *
  53. * @return method specific status information
  54. */
  55. int solveLin ( const GenericMatrix & gm, const Vector & b, Vector & x );
  56. /**
  57. * @brief switch to detailed time analysis
  58. *
  59. * @param timeAnalysis
  60. */
  61. void setTimeAnalysis( bool timeAnalysis = true );
  62. /**
  63. * @brief Enable or disable output
  64. *
  65. * @param _verbose
  66. */
  67. void setVerbose( const bool & _verbose );
  68. };
  69. }
  70. #endif