aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/linear_regression/unimodal.h
blob: 2cb3c531dfefba85ed41ef8ea357304c166b0afc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once 
 
#include "linear_regression.h" 
 
struct TGreedyParams { 
    double LowerBound = 0; 
    double UpperBound = 0; 
    size_t StepsCount = 0; 
 
    double Point(const size_t step) const; 
}; 
 
struct TOptimizationParams { 
    TGreedyParams ModeParams; 
    TGreedyParams NormalizerParams; 
 
    double OptimizationShrinkage = 1e-2; 
    double RegressionShrinkage = 1e-5; 
 
    size_t IterationsCount = 1000; 
 
    TOptimizationParams() = default;
 
    static TOptimizationParams Default(const TVector<double>& values) {
        TOptimizationParams optimizationParams; 
 
        optimizationParams.ModeParams.LowerBound = 0; 
        optimizationParams.ModeParams.UpperBound = values.size(); 
        optimizationParams.ModeParams.StepsCount = values.size() + 1; 
 
        optimizationParams.NormalizerParams.LowerBound = 0.5; 
        optimizationParams.NormalizerParams.UpperBound = values.size() * 2; 
        optimizationParams.NormalizerParams.StepsCount = values.size() * 2 + 1; 
 
        return optimizationParams; 
    } 
 
    static TOptimizationParams Default(const TVector<double>& values, const TVector<double>& arguments) {
        Y_ASSERT(values.size() == arguments.size()); 
 
        TOptimizationParams optimizationParams; 
 
        optimizationParams.ModeParams.LowerBound = *MinElement(arguments.begin(), arguments.end()); 
        optimizationParams.ModeParams.UpperBound = *MaxElement(arguments.begin(), arguments.end()); 
        optimizationParams.ModeParams.StepsCount = arguments.size() + 1; 
 
        optimizationParams.NormalizerParams.UpperBound = optimizationParams.ModeParams.UpperBound - optimizationParams.ModeParams.LowerBound; 
        optimizationParams.NormalizerParams.StepsCount = arguments.size() * 2 + 1; 
        optimizationParams.NormalizerParams.LowerBound = optimizationParams.NormalizerParams.UpperBound / optimizationParams.NormalizerParams.StepsCount; 
 
        return optimizationParams; 
    } 
}; 
 
double MakeUnimodal(TVector<double>& values, const TOptimizationParams& optimizationParams);
double MakeUnimodal(TVector<double>& values);
 
double MakeUnimodal(TVector<double>& values, const TVector<double>& arguments, const TOptimizationParams& optimizationParams);
double MakeUnimodal(TVector<double>& values, const TVector<double>& arguments);