PFAbsExp.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @file PFAbsExp.h
  3. * @author Erik Rodner
  4. * @brief Parameterized Function: absolute value and exponential operation -- pow(fabs(x), exponent) (Interface + Implementation)
  5. * @date 01/04/2012
  6. */
  7. #ifndef _NICE_PFABSEXPINCLUDE
  8. #define _NICE_PFABSEXPINCLUDE
  9. #include <math.h>
  10. #include "ParameterizedFunction.h"
  11. namespace NICE {
  12. /**
  13. * @class PFAbsExp
  14. * @brief Parameterized Function: absolute value and exponential operation -- pow(fabs(x), exponent)
  15. * @author Erik Rodner
  16. */
  17. class PFAbsExp : public ParameterizedFunction
  18. {
  19. protected:
  20. double upperBound;
  21. double lowerBound;
  22. public:
  23. /** simple constructor, we only have one parameter */
  24. PFAbsExp( double exponent = 1.0,
  25. double lB = -std::numeric_limits<double>::max(),
  26. double uB = std::numeric_limits<double>::max() ) :
  27. ParameterizedFunction(1)
  28. {
  29. m_parameters[0] = exponent;
  30. upperBound = uB;
  31. lowerBound = lB;
  32. };
  33. ~PFAbsExp(){};
  34. double f ( uint index, double x ) const {
  35. /* std::cerr << "upperBound: " << upperBound << std::endl;
  36. std::cerr << "lowerBound: " << lowerBound << std::endl;
  37. std::cerr << "m_parameters: " << m_parameters << std::endl; */
  38. return pow(fabs(x),m_parameters[0]);
  39. }
  40. bool isOrderPreserving() const { return true; };
  41. Vector getParameterUpperBounds() const { return Vector(1, upperBound); };
  42. Vector getParameterLowerBounds() const { return Vector(1, lowerBound); };
  43. void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
  44. void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
  45. /** Persistent interface */
  46. virtual void restore ( std::istream & is, int format = 0 )
  47. {
  48. if (is.good())
  49. {
  50. is.precision (std::numeric_limits<double>::digits10 + 1);
  51. std::string tmp;
  52. is >> tmp;
  53. is >> upperBound;
  54. is >> tmp;
  55. is >> lowerBound;
  56. }
  57. ParameterizedFunction::restore(is);
  58. };
  59. virtual void store ( std::ostream & os, int format = 0 ) const
  60. {
  61. if (os.good())
  62. {
  63. os.precision (std::numeric_limits<double>::digits10 + 1);
  64. os << "upperBound: " << std::endl << upperBound << std::endl;
  65. os << "lowerBound: " << std::endl << lowerBound << std::endl;
  66. }
  67. ParameterizedFunction::store(os);
  68. };
  69. virtual void clear () {};
  70. virtual std::string sayYourName() const {return "absexp";};
  71. };
  72. }
  73. #endif