PFWeightedDim.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file PFWeightedDim.h
  3. * @brief Parameterized Function: weights for each dimension (Interface + Implementation)
  4. * @author Erik Rodner
  5. */
  6. #ifndef _NICE_PFWEIGHTEDDIMINCLUDE
  7. #define _NICE_PFWEIGHTEDDIMINCLUDE
  8. #include <math.h>
  9. #include "ParameterizedFunction.h"
  10. namespace NICE {
  11. /**
  12. * @class PFWeightedDim
  13. * @brief Parameterized Function: weights for each dimension
  14. * @author Erik Rodner
  15. */
  16. class PFWeightedDim : public ParameterizedFunction
  17. {
  18. protected:
  19. double upperBound;
  20. double lowerBound;
  21. uint dimension;
  22. public:
  23. PFWeightedDim( uint dimension,
  24. double lB = -std::numeric_limits<double>::max(),
  25. double uB = std::numeric_limits<double>::max() ) :
  26. ParameterizedFunction(dimension)
  27. {
  28. this->dimension = dimension;
  29. upperBound = uB;
  30. lowerBound = lB;
  31. if ( uB < 1.0 )
  32. m_parameters.set(uB);
  33. else
  34. m_parameters.set(1.0);
  35. };
  36. ~PFWeightedDim(){};
  37. double f ( uint index, double x ) const { return m_parameters[index] * m_parameters[index] * x; }
  38. bool isOrderPreserving() const { return true; };
  39. Vector getParameterUpperBounds() const { return Vector(m_parameters.size(), upperBound); };
  40. Vector getParameterLowerBounds() const { return Vector(m_parameters.size(), lowerBound); };
  41. void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
  42. void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
  43. /** Persistent interface */
  44. virtual void restore ( std::istream & is, int format = 0 )
  45. {
  46. if (is.good())
  47. {
  48. is.precision (std::numeric_limits<double>::digits10 + 1);
  49. std::string tmp;
  50. is >> tmp;
  51. is >> upperBound;
  52. is >> tmp;
  53. is >> lowerBound;
  54. is >> tmp;
  55. is >> dimension;
  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. os << "dimension: " << std::endl << dimension << std::endl;
  67. }
  68. ParameterizedFunction::store(os);
  69. };
  70. virtual void clear () {};
  71. virtual std::string sayYourName() const {return "weightedDim";};
  72. };
  73. }
  74. #endif