25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

solver.h 1.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // LolRemez - Remez algorithm implementation
  3. //
  4. // Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // This program is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #pragma once
  13. //
  14. // The remez_solver class
  15. // ----------------------
  16. //
  17. #include <cstdio>
  18. #include "expression.h"
  19. class remez_solver
  20. {
  21. public:
  22. remez_solver(int order, int decimals);
  23. ~remez_solver();
  24. void run(lol::real a, lol::real b,
  25. char const *func, char const *weight = nullptr);
  26. private:
  27. void remez_init();
  28. void remez_step();
  29. void find_zeroes();
  30. void find_extrema();
  31. void worker_thread();
  32. void print_poly();
  33. lol::real eval_estimate(lol::real const &x);
  34. lol::real eval_func(lol::real const &x);
  35. lol::real eval_weight(lol::real const &x);
  36. lol::real eval_error(lol::real const &x);
  37. private:
  38. /* User-defined parameters */
  39. expression m_func, m_weight;
  40. int m_order, m_decimals;
  41. bool m_has_weight;
  42. /* Solver state */
  43. lol::polynomial<lol::real> m_estimate;
  44. lol::array<lol::real> m_zeroes;
  45. lol::array<lol::real> m_control;
  46. lol::real m_k1, m_k2, m_epsilon, m_error;
  47. struct point
  48. {
  49. lol::real x, err;
  50. };
  51. lol::array<point, point, point> m_zeroes_state;
  52. lol::array<point, point, point> m_extrema_state;
  53. /* Threading information */
  54. lol::array<lol::thread *> m_workers;
  55. lol::queue<int> m_questions, m_answers;
  56. };