random_search.h 909 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef IGL_RANDOM_SEARCH_H
  2. #define IGL_RANDOM_SEARCH_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. #include <functional>
  6. namespace igl
  7. {
  8. // Solve the problem:
  9. //
  10. // minimize f(x)
  11. // subject to lb ≤ x ≤ ub
  12. //
  13. // by uniform random search.
  14. //
  15. // Inputs:
  16. // f function to minimize
  17. // LB #X vector of finite lower bounds
  18. // UB #X vector of finite upper bounds
  19. // iters number of iterations
  20. // Outputs:
  21. // X #X optimal parameter vector
  22. // Returns f(X)
  23. //
  24. template <
  25. typename Scalar,
  26. typename DerivedX,
  27. typename DerivedLB,
  28. typename DerivedUB>
  29. IGL_INLINE Scalar random_search(
  30. const std::function< Scalar (DerivedX &) > f,
  31. const Eigen::MatrixBase<DerivedLB> & LB,
  32. const Eigen::MatrixBase<DerivedUB> & UB,
  33. const int iters,
  34. DerivedX & X);
  35. }
  36. #ifndef IGL_STATIC_LIBRARY
  37. # include "random_search.cpp"
  38. #endif
  39. #endif