|
31 | 31 | #include "propts.h" |
32 | 32 | #include "structs.h" |
33 | 33 |
|
| 34 | +namespace prlearn { |
| 35 | + |
| 36 | + class MLearning { |
| 37 | + public: |
| 38 | + MLearning(); |
| 39 | + MLearning(const MLearning& other); |
| 40 | + MLearning& operator=(const MLearning& other) = default; |
| 41 | + |
| 42 | + MLearning(MLearning&&) = default; |
| 43 | + MLearning& operator=(MLearning&&) = default; |
| 44 | + |
| 45 | + void addSample(size_t dimen, // dimensions |
| 46 | + const double* f_var, const double* t_var, // doubles |
| 47 | + size_t label, // edge chosen, edge taken |
| 48 | + size_t dest, double value, // cost |
| 49 | + const std::vector<MLearning>& clouds, // other points |
| 50 | + bool minimization, const double delta, |
| 51 | + const propts_t& options |
| 52 | + ); |
| 53 | + |
| 54 | + void update(const std::vector<MLearning>& clouds, bool minimization); |
| 55 | + |
| 56 | + std::pair<double, double> lookup(size_t label, const double* f_var, size_t dimen) const; |
| 57 | + |
| 58 | + void print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map, const std::vector<MLearning>& clouds) const; |
34 | 59 |
|
35 | | -class MLearning { |
36 | | -public: |
37 | | - MLearning(); |
38 | | - MLearning(const MLearning& other); |
39 | | - MLearning& operator = (const MLearning& other) = default; |
40 | | - |
41 | | - MLearning(MLearning&&) = default; |
42 | | - MLearning& operator = (MLearning&&) = default; |
43 | | - |
44 | | - void addSample( size_t dimen, // dimensions |
45 | | - const double* f_var, const double* t_var, // doubles |
46 | | - size_t label,// edge chosen, edge taken |
47 | | - size_t dest, double value, // cost |
48 | | - const std::vector<MLearning>& clouds, // other points |
49 | | - bool minimization, const double delta, |
50 | | - const propts_t& options |
51 | | - ); |
52 | | - |
53 | | - void update(const std::vector<MLearning>& clouds, bool minimization); |
54 | | - |
55 | | - std::pair<double,double> lookup(size_t label, const double* f_var, size_t dimen) const; |
56 | | - |
57 | | - void print(std::ostream& s, size_t tabs, std::map<size_t, size_t>& edge_map, const std::vector<MLearning>& clouds) const; |
58 | | - |
59 | 60 | protected: |
60 | | - |
61 | | - std::unique_ptr<size_t[]> findIntersection(const double* point) const; |
62 | | - |
| 61 | + |
| 62 | + std::unique_ptr<size_t[] > findIntersection(const double* point) const; |
| 63 | + |
63 | 64 | struct interesect_t { |
64 | 65 | size_t _size = 0; |
65 | 66 | size_t _cloud = std::numeric_limits<size_t>::max(); |
66 | | - std::unique_ptr<size_t[]> _nodes = nullptr; |
67 | | - std::unique_ptr<std::pair<qvar_t,qvar_t>[]> _variance = nullptr; |
68 | | - std::unique_ptr<std::pair<qvar_t,qvar_t>[]> _old = nullptr; |
| 67 | + std::unique_ptr<size_t[] > _nodes = nullptr; |
| 68 | + std::unique_ptr<std::pair<qvar_t, qvar_t>[] > _variance = nullptr; |
| 69 | + std::unique_ptr<std::pair<qvar_t, qvar_t>[] > _old = nullptr; |
69 | 70 |
|
70 | 71 | interesect_t() = default; |
71 | 72 | interesect_t(interesect_t&&) = default; |
72 | 73 | interesect_t& operator=(interesect_t&&) = default; |
73 | 74 | interesect_t(const interesect_t& other, size_t dimen); |
74 | 75 | bool operator<(const interesect_t& other) const; |
75 | | - bool operator != (const interesect_t& other) const; |
| 76 | + bool operator!=(const interesect_t& other) const; |
76 | 77 | }; |
77 | | - |
| 78 | + |
78 | 79 | struct data_t { |
79 | 80 | avg_t _lmid, _hmid, _mid; |
80 | 81 | splitfilter_t _splitfilter; |
81 | 82 | }; |
82 | | - |
| 83 | + |
83 | 84 | struct node_t { |
84 | 85 | simple_split_t _split; |
85 | 86 | qvar_t _q; |
86 | 87 | qvar_t _old; |
87 | 88 | size_t _parent; |
88 | | - std::vector<interesect_t> _samples; |
89 | | - std::unique_ptr<data_t[]> _data = nullptr; |
| 89 | + std::vector<interesect_t> _samples; |
| 90 | + std::unique_ptr<data_t[] > _data = nullptr; |
90 | 91 | node_t() = default; |
91 | 92 | node_t(const node_t& other, size_t dimen); |
92 | 93 | node_t(node_t&& other) noexcept = default; |
93 | | - node_t& operator=(node_t&& other) noexcept = default; |
94 | | - |
| 94 | + node_t& operator=(node_t&& other) noexcept = default; |
| 95 | + |
95 | 96 | size_t find_node(const std::vector<node_t>& nodes, const double * point, const size_t id) const; |
96 | 97 | void update(size_t id, bool minimize, const std::vector<MLearning>& clouds, std::vector<node_t>& nodes, size_t dimen, bool allowSplit, const double delta, const propts_t& options); |
97 | | - std::pair<qvar_t,qvar_t> aggregate_samples(const std::vector<MLearning>& clouds, size_t dimen, bool minimize, std::pair<qvar_t,qvar_t>* tmpq, double discount); |
| 98 | + std::pair<qvar_t, qvar_t> aggregate_samples(const std::vector<MLearning>& clouds, size_t dimen, bool minimize, std::pair<qvar_t, qvar_t>* tmpq, double discount); |
98 | 99 | void print(std::ostream& s, size_t tabs, const std::vector<node_t>& nodes) const; |
99 | 100 | void tighten_samples(const std::vector<MLearning>& clouds, size_t cloud); |
100 | 101 | void add_sample(size_t dest, const double* f_var, const double* point, double value, size_t dimen, const std::vector<MLearning>& clouds); |
101 | 102 | static void update_parents(std::vector<node_t>& nodes, size_t next, bool minimize); |
102 | 103 | }; |
103 | | - |
| 104 | + |
104 | 105 | size_t _dimen = 0; |
105 | 106 | std::vector<el_t> _mapping; |
106 | 107 | std::vector<node_t> _nodes; |
107 | | -}; |
108 | | - |
| 108 | + }; |
| 109 | +} |
109 | 110 | #endif /* MLEARNING_H */ |
110 | 111 |
|
0 commit comments