ParameterizedFunction.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file ParameterizedFunction.h
  3. * @brief Simple parameterized multi-dimensional function (Interface)
  4. * @author Erik Rodner, Alexander Freytag
  5. * @date 01/04/2012
  6. */
  7. #ifndef _NICE_PARAMETERIZEDFUNCTIONINCLUDE
  8. #define _NICE_PARAMETERIZEDFUNCTIONINCLUDE
  9. // STL includes
  10. #include <vector>
  11. #include <limits>
  12. // NICE-core includes
  13. #include <core/basics/Persistent.h>
  14. //
  15. #include <core/vector/VectorT.h>
  16. #include <core/vector/SparseVectorT.h>
  17. namespace NICE {
  18. /** @class ParameterizedFunction
  19. * @brief
  20. * simple parameterized multi-dimensional function
  21. *
  22. * @description
  23. * current requirements:
  24. * (1) f(0) = 0
  25. * (2) f is monotonically increasing
  26. *
  27. * @author Erik Rodner, Alexander Freytag
  28. */
  29. class ParameterizedFunction : public NICE::Persistent
  30. {
  31. protected:
  32. /** parameters of the function */
  33. NICE::Vector m_parameters;
  34. public:
  35. /**
  36. * @brief contructor taking the dimension of the parameter vector, initializes
  37. * the member variable
  38. *
  39. * @param dimension dimension of the parameter vector
  40. */
  41. ParameterizedFunction ( uint dimension );
  42. /** empty destructor */
  43. virtual ~ParameterizedFunction () {};
  44. /**
  45. * @brief Function evaluation
  46. *
  47. * @param index component of the vector
  48. * @param x function argument
  49. *
  50. * @return function value, which depends on the stored parameters
  51. */
  52. virtual double f ( uint index, double x ) const = 0;
  53. /**
  54. * @brief Tell whether this function is order-preserving in the sense that
  55. * a permutation of function values is invariant with respect to the parameter value.
  56. * Therefore, the function is either monotonically increasing or decreasing.
  57. *
  58. * @return boolean flag =true iff the function is order preserving
  59. */
  60. virtual bool isOrderPreserving () const = 0;
  61. /**
  62. * @brief get the lower bound for each parameter
  63. *
  64. * @return vector with lower bounds
  65. */
  66. virtual NICE::Vector getParameterLowerBounds() const = 0;
  67. /**
  68. * @brief set the lower bounds for each parameter
  69. *
  70. * @return vector with upper bounds
  71. */
  72. virtual void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) = 0;
  73. /**
  74. * @brief get the upper bounds for each parameter
  75. *
  76. * @return vector with upper bounds
  77. */
  78. virtual NICE::Vector getParameterUpperBounds() const = 0;
  79. /**
  80. * @brief set the upper bounds for each parameter
  81. *
  82. * @return vector with upper bounds
  83. */
  84. virtual void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) = 0;
  85. /**
  86. * @brief read-only access of the parameters
  87. *
  88. * @return const-reference to the stored parameter vector
  89. */
  90. const NICE::Vector & parameters() const { return m_parameters; }
  91. /**
  92. * @brief read-and-write access to the parameters
  93. *
  94. * @return reference to the stored parameter vector
  95. */
  96. Vector & parameters() { return m_parameters; }
  97. /**
  98. * @brief apply function to a data matrix ( feature vectors stored in rows )
  99. *
  100. * @param dataMatrix input matrix, e.g. featureMatrix[0][1..d] is the d-dimensional feature vector of example 0
  101. */
  102. void applyFunctionToDataMatrix ( std::vector< std::vector< double > > & dataMatrix ) const;
  103. /** Persistent interface */
  104. virtual void restore ( std::istream & is, int format = 0 );
  105. virtual void store ( std::ostream & os, int format = 0 ) const;
  106. virtual void clear () {};
  107. virtual std::string sayYourName() const = 0;
  108. };
  109. }
  110. #endif