| 1 | /*! |
|---|
| 2 | \file |
|---|
| 3 | \brief Robust Bayesian auto-regression model |
|---|
| 4 | \author Jan Sindelar. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef ROBUST_H |
|---|
| 8 | #define ROBUST_H |
|---|
| 9 | |
|---|
| 10 | #include <stat/exp_family.h> |
|---|
| 11 | #include <limits> |
|---|
| 12 | |
|---|
| 13 | using namespace bdm; |
|---|
| 14 | using namespace std; |
|---|
| 15 | |
|---|
| 16 | #include <vector> |
|---|
| 17 | |
|---|
| 18 | public const max_range = numeric_limits<double>::max( )/10e-5.0; |
|---|
| 19 | |
|---|
| 20 | class polyhedron; |
|---|
| 21 | class vertex; |
|---|
| 22 | |
|---|
| 23 | class polyhedron |
|---|
| 24 | { |
|---|
| 25 | vector<&polyhedron> parents; |
|---|
| 26 | |
|---|
| 27 | vector<&polyhedron> children; |
|---|
| 28 | |
|---|
| 29 | vector<&vertex> vertices; |
|---|
| 30 | |
|---|
| 31 | vector<&polyhedron> positivechildren; |
|---|
| 32 | |
|---|
| 33 | vector<&polyhedron> negativechildren; |
|---|
| 34 | |
|---|
| 35 | vector<&polyhedron> neutralchildren; |
|---|
| 36 | |
|---|
| 37 | vector<vector<&vertex>> triangulations; |
|---|
| 38 | |
|---|
| 39 | int multiplicity = 1; |
|---|
| 40 | |
|---|
| 41 | public: |
|---|
| 42 | |
|---|
| 43 | vector<int> kids_rel_addresses; |
|---|
| 44 | |
|---|
| 45 | polyhedron() |
|---|
| 46 | { |
|---|
| 47 | parents = new vector<&polyhedron>(); |
|---|
| 48 | children = new vector<&polyhedron>(); |
|---|
| 49 | vertices = new vector<&vertex>(); |
|---|
| 50 | |
|---|
| 51 | positivechildren = new vector(&polyhedron)(); |
|---|
| 52 | negativechildren = new vector(&polyhedron)(); |
|---|
| 53 | neutralchildren = new vector(&polyhedron)(); |
|---|
| 54 | |
|---|
| 55 | triangulations = new vector<vector<&vertex>>(); |
|---|
| 56 | |
|---|
| 57 | kids_rel_addresses = new vector<int>(); |
|---|
| 58 | |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | void RaiseMultiplicity() |
|---|
| 63 | { |
|---|
| 64 | multiplicity++; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | void LowerMultiplicity() |
|---|
| 68 | { |
|---|
| 69 | multiplicity--; |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | }; |
|---|
| 74 | |
|---|
| 75 | class vertex : polyhedron |
|---|
| 76 | { |
|---|
| 77 | vector<double> coordinates; |
|---|
| 78 | |
|---|
| 79 | public: |
|---|
| 80 | |
|---|
| 81 | vertex(); |
|---|
| 82 | |
|---|
| 83 | vertex(vector<double> coordinates) |
|---|
| 84 | { |
|---|
| 85 | this.coordinates = coordinates; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | void push_coordinate(double coordinate) |
|---|
| 89 | { |
|---|
| 90 | coordinates.push_back(coordinate); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | vector<double> get_coordinates() |
|---|
| 94 | { |
|---|
| 95 | return this.coordinates(); |
|---|
| 96 | } |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | class toprow : polyhedron |
|---|
| 100 | { |
|---|
| 101 | vector<double> condition; |
|---|
| 102 | |
|---|
| 103 | public: |
|---|
| 104 | |
|---|
| 105 | toprow(); |
|---|
| 106 | |
|---|
| 107 | toprow(double condition) |
|---|
| 108 | { |
|---|
| 109 | this.condition = condition; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density |
|---|
| 118 | class emlig : public eEF{ |
|---|
| 119 | |
|---|
| 120 | vector<vector<&polyhedron>> statistic; |
|---|
| 121 | |
|---|
| 122 | public: |
|---|
| 123 | |
|---|
| 124 | emlig(int number_of_parameters) |
|---|
| 125 | { |
|---|
| 126 | create_statistic(int number_of_parameters); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | emlig(vector<vector<&polyhedron>> statistic) |
|---|
| 130 | { |
|---|
| 131 | this.statistic = statistic; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | protected: |
|---|
| 137 | |
|---|
| 138 | create_statistic(int number_of parameters) |
|---|
| 139 | { |
|---|
| 140 | vector<double> origin_coord = new vector<double>(); |
|---|
| 141 | |
|---|
| 142 | origin = new vertex(origin_coord); |
|---|
| 143 | |
|---|
| 144 | origin.vertices.push_back(origin); |
|---|
| 145 | |
|---|
| 146 | vector<&polyhedron> origin_vec = new vector(&polyhedron)(1,); |
|---|
| 147 | |
|---|
| 148 | statistic.push_back(origin_vec); |
|---|
| 149 | |
|---|
| 150 | for(int i=0;i++;i<number_of_parameters) |
|---|
| 151 | { |
|---|
| 152 | vertex new_point1 = new vertex(origin.get_coordinates().push_back(max_range)); |
|---|
| 153 | vertex new_point2 = new vertex(origin.get_coordinates().push_back(-max_range)); |
|---|
| 154 | |
|---|
| 155 | vector(vector(&polyhedron)) new_statistic1 = new vector(vector(&polyhedron)); |
|---|
| 156 | vector(vector(&polyhedron)) new_statistic2 = new vector(vector(&polyhedron)); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | for(int j=0;j++;j<statistic.size()) |
|---|
| 160 | { |
|---|
| 161 | vector<&polyhedron>::iterator horiz_ref = statistic[j].begin(); |
|---|
| 162 | |
|---|
| 163 | int element_number = 0; |
|---|
| 164 | |
|---|
| 165 | do |
|---|
| 166 | { |
|---|
| 167 | if(!horiz_ref.parents.empty()) |
|---|
| 168 | { |
|---|
| 169 | vector<&polyhedron>::iterator end_ref = horiz_ref.parents.end(); |
|---|
| 170 | |
|---|
| 171 | vector<&polyhedron>::iterator parent_ref = horiz_ref.parents.begin(); |
|---|
| 172 | |
|---|
| 173 | do |
|---|
| 174 | { |
|---|
| 175 | parent_ref.kids_rel_addresses.push_back(element_number); |
|---|
| 176 | |
|---|
| 177 | parent_ref++; |
|---|
| 178 | } |
|---|
| 179 | while(parent_ref!=end_ref) |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | toprow current_copy1 = new toprow(new vector<int>(i+2,0)); |
|---|
| 183 | toprow current_copy2 = new toprow(new vector<int>(i+2,0)); |
|---|
| 184 | |
|---|
| 185 | vector<&vertex>::iterator vert_ref = horiz_ref.vertices.begin(); |
|---|
| 186 | |
|---|
| 187 | do |
|---|
| 188 | { |
|---|
| 189 | current_copy1.vertices.push_back(vert_ref); |
|---|
| 190 | current_copy2.vertices.push_back(vert_ref); |
|---|
| 191 | |
|---|
| 192 | vert_ref++; |
|---|
| 193 | } |
|---|
| 194 | while(!vert_ref!=horiz_ref.vertices.end()) |
|---|
| 195 | |
|---|
| 196 | current_copy1.vertices.push_back(new_point1); |
|---|
| 197 | current_copy2.vertices.push_back(new_point2); |
|---|
| 198 | |
|---|
| 199 | current_copy1.triangulations.push_back(current_copy1.vertices); |
|---|
| 200 | current_copy2.triangulations.push_back(current_copy2.vertices); |
|---|
| 201 | |
|---|
| 202 | vector<int>::iterator kid_ref = horiz_ref.kids_rel_addresses.begin(); |
|---|
| 203 | |
|---|
| 204 | if(!horiz_ref.kids_rel_addresses.empty()) |
|---|
| 205 | { |
|---|
| 206 | do |
|---|
| 207 | { |
|---|
| 208 | current_copy1.children.push_back(new_statistic1[i,kid_ref]); |
|---|
| 209 | current_copy2.children.push_back(new_statistic2[i,kid_ref]); |
|---|
| 210 | |
|---|
| 211 | new_statistic1[i,kid_ref].parents.push_back(current_copy1); |
|---|
| 212 | new_statistic2[i,kid_ref].parents.push_back(current_copy2); |
|---|
| 213 | |
|---|
| 214 | kid_ref++; |
|---|
| 215 | |
|---|
| 216 | } |
|---|
| 217 | while(kid_ref!=horiz_ref.kids_rel_addresses.end()) |
|---|
| 218 | |
|---|
| 219 | horiz_ref.kids_rel_addresses.clear(); |
|---|
| 220 | } |
|---|
| 221 | else |
|---|
| 222 | { |
|---|
| 223 | current_copy1.children.push_back(new_point1); |
|---|
| 224 | current_copy2.childern.push_back(new_point2); |
|---|
| 225 | |
|---|
| 226 | new_point1.parents.push_back(current_copy1); |
|---|
| 227 | new_point2.parents.push_back(current_copy2); |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | current_copy1.children.push_back(horiz_ref); |
|---|
| 231 | current_copy2.children.push_back(horiz_ref); |
|---|
| 232 | |
|---|
| 233 | new_statistic1[i+1].push_back(current_copy1); |
|---|
| 234 | new_statistic2[i+1].push_back(current_copy2); |
|---|
| 235 | |
|---|
| 236 | element_number++; |
|---|
| 237 | } |
|---|
| 238 | while(statistic[j].end() != horiz_ptr++) |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | } |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | }; |
|---|
| 248 | |
|---|
| 249 | //! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density |
|---|
| 250 | class RARX : public BMEF{ |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | #endif //TRAGE_H |
|---|