PFMKL.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file PFMKL.h
  3. * @brief Parameterized Function: weights for Multiple Kernel Learning approach (Interface + Implementation)
  4. * @author Alexander Freytag
  5. */
  6. #ifndef _NICE_PFMULTIPLEKERNELLEARNINGINCLUDE
  7. #define _NICE_PFMULTIPLEKERNELLEARNINGINCLUDE
  8. #include <math.h>
  9. #include "ParameterizedFunction.h"
  10. namespace NICE {
  11. /**
  12. * @class PFMKL
  13. * @brief Parameterized Function: weights for Multiple Kernel Learning approach
  14. * @author Alexander Freytag
  15. */
  16. class PFMKL : public ParameterizedFunction
  17. {
  18. protected:
  19. double upperBound;
  20. double lowerBound;
  21. std::set<int> steps;
  22. public:
  23. PFMKL( const std::set<int> & _steps,
  24. double lB = -std::numeric_limits<double>::max(),
  25. double uB = std::numeric_limits<double>::max() ) :
  26. ParameterizedFunction(_steps.size()+1)
  27. {
  28. upperBound = uB;
  29. lowerBound = std::max( lB, 0.0 );
  30. if ( uB < 1.0 )
  31. m_parameters.set(uB);
  32. else
  33. m_parameters.set(1.0);
  34. steps = _steps;
  35. };
  36. ~PFMKL(){};
  37. double f ( uint index, double x ) const
  38. {
  39. int dummyCnt ( 0 );
  40. for (std::set<int>::const_iterator it = steps.begin(); it != steps.end(); it++, dummyCnt++)
  41. {
  42. if ( index < *it)
  43. return x * m_parameters[dummyCnt];
  44. }
  45. //default value, should never be reached
  46. return 0.0;
  47. }
  48. bool isOrderPreserving() const { return true; };
  49. Vector getParameterUpperBounds() const { return Vector(m_parameters.size(), upperBound); };
  50. Vector getParameterLowerBounds() const { return Vector(m_parameters.size(), lowerBound); };
  51. void setParameterLowerBounds(const NICE::Vector & _newLowerBounds) { if (_newLowerBounds.size() > 0) lowerBound = _newLowerBounds(0);};
  52. void setParameterUpperBounds(const NICE::Vector & _newUpperBounds) { if (_newUpperBounds.size() > 0) upperBound = _newUpperBounds(0);};
  53. /** Persistent interface */
  54. virtual void restore ( std::istream & is, int format = 0 )
  55. {
  56. if (is.good())
  57. {
  58. is.precision (std::numeric_limits<double>::digits10 + 1);
  59. std::string tmp;
  60. is >> tmp;
  61. is >> upperBound;
  62. is >> tmp;
  63. is >> lowerBound;
  64. }
  65. ParameterizedFunction::restore(is);
  66. };
  67. virtual void store ( std::ostream & os, int format = 0 ) const
  68. {
  69. if (os.good())
  70. {
  71. os.precision (std::numeric_limits<double>::digits10 + 1);
  72. os << "upperBound: " << std::endl << upperBound << std::endl;
  73. os << "lowerBound: " << std::endl << lowerBound << std::endl;
  74. }
  75. ParameterizedFunction::store(os);
  76. };
  77. virtual void clear () {};
  78. virtual std::string sayYourName() const {return "MKL weighting";};
  79. };
  80. }
  81. #endif