[976] | 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> |
---|
[1171] | 11 | #include <limits> |
---|
[1172] | 12 | #include <vector> |
---|
| 13 | #include <algorithm> |
---|
[976] | 14 | |
---|
| 15 | using namespace bdm; |
---|
| 16 | using namespace std; |
---|
| 17 | |
---|
[1172] | 18 | const double max_range = numeric_limits<double>::max()/10e-5; |
---|
[1171] | 19 | |
---|
| 20 | class polyhedron; |
---|
| 21 | class vertex; |
---|
| 22 | |
---|
[1172] | 23 | /// A class describing a single polyhedron of the split complex. From a collection of such classes a Hasse diagram |
---|
| 24 | /// of the structure in the exponent of a Laplace-Inverse-Gamma density will be created. |
---|
[1171] | 25 | class polyhedron |
---|
[976] | 26 | { |
---|
[1172] | 27 | /// A property having a value of 1 usually, with higher value only if the polyhedron arises as a coincidence of |
---|
| 28 | /// more than just the necessary number of conditions. For example if a newly created line passes through an already |
---|
| 29 | /// existing point, the points multiplicity will rise by 1. |
---|
| 30 | int multiplicity; |
---|
[976] | 31 | |
---|
[1172] | 32 | public: |
---|
| 33 | /// A list of polyhedrons parents within the Hasse diagram. |
---|
| 34 | vector<polyhedron*> parents; |
---|
[1171] | 35 | |
---|
[1172] | 36 | /// A list of polyhedrons children withing the Hasse diagram. |
---|
| 37 | vector<polyhedron*> children; |
---|
[1171] | 38 | |
---|
[1172] | 39 | /// All the vertices of the given polyhedron |
---|
| 40 | vector<vertex*> vertices; |
---|
[1171] | 41 | |
---|
[1172] | 42 | /// A list used for storing children that lie in the positive region related to a certain condition |
---|
| 43 | vector<polyhedron*> positivechildren; |
---|
[1171] | 44 | |
---|
[1172] | 45 | /// A list used for storing children that lie in the negative region related to a certain condition |
---|
| 46 | vector<polyhedron*> negativechildren; |
---|
[1171] | 47 | |
---|
[1172] | 48 | /// Children intersecting the condition |
---|
| 49 | vector<polyhedron*> neutralchildren; |
---|
[1171] | 50 | |
---|
[1172] | 51 | /// List of triangulation polyhedrons of the polyhedron given by their relative vertices. |
---|
| 52 | vector<vector<vertex*>> triangulations; |
---|
[1171] | 53 | |
---|
[1172] | 54 | /// A list of relative addresses serving for Hasse diagram construction. |
---|
[1171] | 55 | vector<int> kids_rel_addresses; |
---|
| 56 | |
---|
[1172] | 57 | /// Default constructor |
---|
[1171] | 58 | polyhedron() |
---|
| 59 | { |
---|
[1172] | 60 | multiplicity = 1; |
---|
[1171] | 61 | } |
---|
| 62 | |
---|
[1172] | 63 | /// Setter for raising multiplicity |
---|
[1171] | 64 | void RaiseMultiplicity() |
---|
| 65 | { |
---|
| 66 | multiplicity++; |
---|
| 67 | } |
---|
| 68 | |
---|
[1172] | 69 | /// Setter for lowering multiplicity |
---|
[1171] | 70 | void LowerMultiplicity() |
---|
| 71 | { |
---|
| 72 | multiplicity--; |
---|
| 73 | } |
---|
| 74 | |
---|
[1172] | 75 | /// An obligatory operator, when the class is used within a C++ STL structure like a vector |
---|
| 76 | int operator==(polyhedron polyhedron2) |
---|
| 77 | { |
---|
| 78 | return true; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | /// An obligatory operator, when the class is used within a C++ STL structure like a vector |
---|
| 82 | int operator<(polyhedron polyhedron2) |
---|
| 83 | { |
---|
| 84 | return false; |
---|
| 85 | } |
---|
[976] | 86 | }; |
---|
| 87 | |
---|
[1172] | 88 | /// A |
---|
| 89 | class vertex : public polyhedron |
---|
[976] | 90 | { |
---|
[1171] | 91 | vector<double> coordinates; |
---|
[976] | 92 | |
---|
| 93 | public: |
---|
[1171] | 94 | |
---|
| 95 | vertex(); |
---|
| 96 | |
---|
| 97 | vertex(vector<double> coordinates) |
---|
| 98 | { |
---|
[1172] | 99 | this->coordinates = coordinates; |
---|
[1171] | 100 | } |
---|
| 101 | |
---|
| 102 | void push_coordinate(double coordinate) |
---|
| 103 | { |
---|
| 104 | coordinates.push_back(coordinate); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | vector<double> get_coordinates() |
---|
| 108 | { |
---|
[1172] | 109 | vector<double> returned_vec; |
---|
| 110 | |
---|
| 111 | copy(this->coordinates.begin(),this->coordinates.end(),returned_vec.begin()); |
---|
| 112 | |
---|
| 113 | return returned_vec; |
---|
[1171] | 114 | } |
---|
[1172] | 115 | }; |
---|
[976] | 116 | |
---|
[1172] | 117 | class toprow : public polyhedron |
---|
[1171] | 118 | { |
---|
| 119 | vector<double> condition; |
---|
[976] | 120 | |
---|
| 121 | public: |
---|
| 122 | |
---|
[1171] | 123 | toprow(); |
---|
[976] | 124 | |
---|
[1172] | 125 | toprow(vector<double> condition) |
---|
[1171] | 126 | { |
---|
[1172] | 127 | this->condition = condition; |
---|
[1171] | 128 | } |
---|
| 129 | |
---|
[1172] | 130 | }; |
---|
[1171] | 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
[976] | 135 | //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density |
---|
[1172] | 136 | class emlig : public eEF |
---|
| 137 | { |
---|
[976] | 138 | |
---|
[1172] | 139 | vector<vector<polyhedron*>> statistic; |
---|
[1171] | 140 | |
---|
| 141 | public: |
---|
[976] | 142 | |
---|
[1171] | 143 | emlig(int number_of_parameters) |
---|
| 144 | { |
---|
[1172] | 145 | create_statistic(number_of_parameters); |
---|
[1171] | 146 | } |
---|
| 147 | |
---|
[1172] | 148 | emlig(vector<vector<polyhedron*>> statistic) |
---|
[1171] | 149 | { |
---|
[1172] | 150 | this->statistic = statistic; |
---|
[1171] | 151 | } |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | protected: |
---|
| 156 | |
---|
[1172] | 157 | void create_statistic(int number_of_parameters) |
---|
[1171] | 158 | { |
---|
[1172] | 159 | vector<double> origin_coord; |
---|
[1171] | 160 | |
---|
[1172] | 161 | vertex *origin = new vertex(origin_coord); |
---|
[1171] | 162 | |
---|
[1172] | 163 | origin->vertices.push_back(origin); |
---|
[1171] | 164 | |
---|
[1172] | 165 | vector<polyhedron*> origin_vec; |
---|
[1171] | 166 | |
---|
[1172] | 167 | origin_vec.push_back(origin); |
---|
| 168 | |
---|
[1171] | 169 | statistic.push_back(origin_vec); |
---|
| 170 | |
---|
[1172] | 171 | for(int i=0;i<number_of_parameters;i++) |
---|
[1171] | 172 | { |
---|
[1172] | 173 | vector<double> origin_coord1 = origin->get_coordinates(); |
---|
| 174 | vector<double> origin_coord2 = origin->get_coordinates(); |
---|
[1171] | 175 | |
---|
[1172] | 176 | origin->push_coordinate(0); |
---|
[1171] | 177 | |
---|
[1172] | 178 | origin_coord1.push_back(max_range); |
---|
| 179 | origin_coord2.push_back(-max_range); |
---|
| 180 | |
---|
| 181 | vertex *new_point1 = new vertex(origin_coord1); |
---|
| 182 | vertex *new_point2 = new vertex(origin_coord2); |
---|
| 183 | |
---|
| 184 | vector<vector<polyhedron*>> new_statistic1; |
---|
| 185 | vector<vector<polyhedron*>> new_statistic2; |
---|
| 186 | |
---|
[1171] | 187 | |
---|
[1172] | 188 | for(int j=0;j<statistic.size();j++) |
---|
[1171] | 189 | { |
---|
| 190 | int element_number = 0; |
---|
| 191 | |
---|
[1172] | 192 | for(vector<polyhedron*>::iterator horiz_ref = statistic[j].begin();horiz_ref<statistic[j].end();horiz_ref++) |
---|
[1171] | 193 | { |
---|
[1172] | 194 | if(!(*horiz_ref)->parents.empty()) |
---|
[1171] | 195 | { |
---|
[1172] | 196 | for(vector<polyhedron*>::iterator parent_ref = (*horiz_ref)->parents.begin();parent_ref < (*horiz_ref)->parents.end();parent_ref++) |
---|
[1171] | 197 | { |
---|
[1172] | 198 | (*parent_ref)->kids_rel_addresses.push_back(element_number); |
---|
| 199 | } |
---|
[1171] | 200 | } |
---|
| 201 | |
---|
[1172] | 202 | vector<double> vec1(i+2,0); |
---|
| 203 | vector<double> vec2(i+2,0); |
---|
[1171] | 204 | |
---|
[1172] | 205 | toprow *current_copy1 = new toprow(vec1); |
---|
| 206 | toprow *current_copy2 = new toprow(vec2); |
---|
[1171] | 207 | |
---|
[1172] | 208 | for(vector<vertex*>::iterator vert_ref = (*horiz_ref)->vertices.begin();vert_ref<(*horiz_ref)->vertices.end();vert_ref++) |
---|
[1171] | 209 | { |
---|
[1172] | 210 | current_copy1->vertices.push_back(*vert_ref); |
---|
| 211 | current_copy2->vertices.push_back(*vert_ref); |
---|
[1171] | 212 | } |
---|
[1172] | 213 | |
---|
[1171] | 214 | |
---|
[1172] | 215 | current_copy1->vertices.push_back(new_point1); |
---|
| 216 | current_copy2->vertices.push_back(new_point2); |
---|
[1171] | 217 | |
---|
[1172] | 218 | current_copy1->triangulations.push_back(current_copy1->vertices); |
---|
| 219 | current_copy2->triangulations.push_back(current_copy2->vertices); |
---|
[1171] | 220 | |
---|
[1172] | 221 | |
---|
[1171] | 222 | |
---|
[1172] | 223 | if(!(*horiz_ref)->kids_rel_addresses.empty()) |
---|
[1171] | 224 | { |
---|
[1172] | 225 | for(vector<int>::iterator kid_ref = (*horiz_ref)->kids_rel_addresses.begin();kid_ref<(*horiz_ref)->kids_rel_addresses.end();kid_ref++) |
---|
[1171] | 226 | { |
---|
[1172] | 227 | current_copy1->children.push_back(new_statistic1[i][(*kid_ref)]); |
---|
| 228 | current_copy2->children.push_back(new_statistic2[i][(*kid_ref)]); |
---|
[1171] | 229 | |
---|
[1172] | 230 | new_statistic1[i][(*kid_ref)]->parents.push_back(current_copy1); |
---|
| 231 | new_statistic2[i][(*kid_ref)]->parents.push_back(current_copy2); |
---|
| 232 | } |
---|
[1171] | 233 | |
---|
[1172] | 234 | (*horiz_ref)->kids_rel_addresses.clear(); |
---|
[1171] | 235 | } |
---|
| 236 | else |
---|
| 237 | { |
---|
[1172] | 238 | current_copy1->children.push_back(new_point1); |
---|
| 239 | current_copy2->children.push_back(new_point2); |
---|
[1171] | 240 | |
---|
[1172] | 241 | new_point1->parents.push_back(current_copy1); |
---|
| 242 | new_point2->parents.push_back(current_copy2); |
---|
[1171] | 243 | } |
---|
| 244 | |
---|
[1172] | 245 | current_copy1->children.push_back(*horiz_ref); |
---|
| 246 | current_copy2->children.push_back(*horiz_ref); |
---|
[1171] | 247 | |
---|
| 248 | new_statistic1[i+1].push_back(current_copy1); |
---|
| 249 | new_statistic2[i+1].push_back(current_copy2); |
---|
| 250 | |
---|
| 251 | element_number++; |
---|
[1172] | 252 | } |
---|
[1171] | 253 | } |
---|
| 254 | |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | |
---|
[976] | 259 | |
---|
[1171] | 260 | |
---|
[976] | 261 | }; |
---|
| 262 | |
---|
| 263 | //! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density |
---|
| 264 | class RARX : public BMEF{ |
---|
| 265 | }; |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | #endif //TRAGE_H |
---|