-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinearLearner.h
112 lines (88 loc) · 2.61 KB
/
LinearLearner.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// Created by Khurram Javed on 2024-02-18.
//
#ifndef TRUEONLINETDLAMBDATEST_LINEARLEARNER_H
#define TRUEONLINETDLAMBDATEST_LINEARLEARNER_H
#include <vector>
#include <random>
class Math {
public:
static float DotProduct(std::vector<float> &a, std::vector<float> &b);
};
class LinearLearner {
protected:
float gamma;
std::vector<float> weights;
public:
LinearLearner();
std::vector<float> GetWeights();
void SetGamma(float gamma);
virtual std::vector<float> GetStepSizePerPixel();
};
class SwiftTDReorganized : public LinearLearner {
private:
int counter;
std::vector<float> h;
std::vector<float> h_old;
std::vector<float> h_temp;
std::vector<float> z_delta;
std::vector<float> delta_w_i;
std::vector<float> z_bar;
std::vector<float> p;
std::vector<float> z;
std::vector<float> feature_counter;
std::vector<float> alpha_cache;
float log_eta;
float log_eps;
float v_delta;
float beta_normalizer;
float meta_step_size;
float lambda;
float v_old;
float v;
float eta;
float eps;
public:
std::vector<float> betas;
float unbounded_rate_of_learning;
float actual_rate_of_learning;
SwiftTDReorganized(int num_features, float lambda, float initial_alpha, float gamma, float eps, float max_step_size,
float step_size_decay, float meta_step_size);
float Step(std::vector<float> &features_indices, float reward);
std::vector<float> GetStepSizePerPixel() override;
};
class SwiftTDReorganizedCache : public LinearLearner {
private:
int counter;
std::vector<float> h;
std::vector<float> h_old;
std::vector<float> h_temp;
std::vector<float> z_delta;
std::vector<float> delta_w_i;
std::vector<float> z_bar;
std::vector<float> p;
std::vector<float> z;
std::vector<float> feature_counter;
std::vector<float> alpha_cache;
float log_eta;
float log_eps;
float v_delta;
float beta_normalizer;
float meta_step_size;
float lambda;
float v_old;
float v;
float eta;
std::vector<int> active_indices;
float eps;
public:
std::vector<float> betas;
float unbounded_rate_of_learning;
float actual_rate_of_learning;
SwiftTDReorganizedCache(int num_features, float lambda, float initial_alpha, float gamma, float eps,
float max_step_size,
float step_size_decay, float meta_step_size);
float Step(std::vector<int> &features_indices, float reward);
std::vector<float> GetStepSizePerPixel() override;
};
#endif //TRUEONLINETDLAMBDATEST_LINEARLEARNER_H