PFExp.h 2.3 KB

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