ParameterizedFunction.h 3.4 KB

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