unimodal.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include "linear_regression.h"
  3. struct TGreedyParams {
  4. double LowerBound = 0;
  5. double UpperBound = 0;
  6. size_t StepsCount = 0;
  7. double Point(const size_t step) const;
  8. };
  9. struct TOptimizationParams {
  10. TGreedyParams ModeParams;
  11. TGreedyParams NormalizerParams;
  12. double OptimizationShrinkage = 1e-2;
  13. double RegressionShrinkage = 1e-5;
  14. size_t IterationsCount = 1000;
  15. TOptimizationParams() = default;
  16. static TOptimizationParams Default(const TVector<double>& values) {
  17. TOptimizationParams optimizationParams;
  18. optimizationParams.ModeParams.LowerBound = 0;
  19. optimizationParams.ModeParams.UpperBound = values.size();
  20. optimizationParams.ModeParams.StepsCount = values.size() + 1;
  21. optimizationParams.NormalizerParams.LowerBound = 0.5;
  22. optimizationParams.NormalizerParams.UpperBound = values.size() * 2;
  23. optimizationParams.NormalizerParams.StepsCount = values.size() * 2 + 1;
  24. return optimizationParams;
  25. }
  26. static TOptimizationParams Default(const TVector<double>& values, const TVector<double>& arguments) {
  27. Y_ASSERT(values.size() == arguments.size());
  28. TOptimizationParams optimizationParams;
  29. optimizationParams.ModeParams.LowerBound = *MinElement(arguments.begin(), arguments.end());
  30. optimizationParams.ModeParams.UpperBound = *MaxElement(arguments.begin(), arguments.end());
  31. optimizationParams.ModeParams.StepsCount = arguments.size() + 1;
  32. optimizationParams.NormalizerParams.UpperBound = optimizationParams.ModeParams.UpperBound - optimizationParams.ModeParams.LowerBound;
  33. optimizationParams.NormalizerParams.StepsCount = arguments.size() * 2 + 1;
  34. optimizationParams.NormalizerParams.LowerBound = optimizationParams.NormalizerParams.UpperBound / optimizationParams.NormalizerParams.StepsCount;
  35. return optimizationParams;
  36. }
  37. };
  38. double MakeUnimodal(TVector<double>& values, const TOptimizationParams& optimizationParams);
  39. double MakeUnimodal(TVector<double>& values);
  40. double MakeUnimodal(TVector<double>& values, const TVector<double>& arguments, const TOptimizationParams& optimizationParams);
  41. double MakeUnimodal(TVector<double>& values, const TVector<double>& arguments);