[1270] | 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 | |
---|
[1273] | 10 | //#include <stat/exp_family.h> |
---|
| 11 | #include <itpp/itbase.h> |
---|
| 12 | #include <map> |
---|
[1270] | 13 | #include <limits> |
---|
| 14 | #include <vector> |
---|
| 15 | #include <list> |
---|
| 16 | #include <set> |
---|
| 17 | #include <algorithm> |
---|
| 18 | |
---|
[1273] | 19 | //using namespace bdm; |
---|
[1270] | 20 | using namespace std; |
---|
| 21 | using namespace itpp; |
---|
| 22 | |
---|
[1301] | 23 | const double max_range = 100;//numeric_limits<double>::max()/10e-10; |
---|
[1270] | 24 | |
---|
[1301] | 25 | /// An enumeration of possible actions performed on the polyhedrons. We can merge them or split them. |
---|
[1270] | 26 | enum actions {MERGE, SPLIT}; |
---|
| 27 | |
---|
[1301] | 28 | // Forward declaration of polyhedron, vertex and emlig |
---|
[1270] | 29 | class polyhedron; |
---|
| 30 | class vertex; |
---|
[1301] | 31 | class emlig; |
---|
[1270] | 32 | |
---|
| 33 | /* |
---|
| 34 | class t_simplex |
---|
| 35 | { |
---|
| 36 | public: |
---|
| 37 | set<vertex*> minima; |
---|
| 38 | |
---|
| 39 | set<vertex*> simplex; |
---|
| 40 | |
---|
| 41 | t_simplex(vertex* origin_vertex) |
---|
| 42 | { |
---|
| 43 | simplex.insert(origin_vertex); |
---|
| 44 | minima.insert(origin_vertex); |
---|
| 45 | } |
---|
| 46 | };*/ |
---|
| 47 | |
---|
[1301] | 48 | /// A class representing a single condition that can be added to the emlig. A condition represents data entries in a statistical model. |
---|
[1300] | 49 | class condition |
---|
| 50 | { |
---|
| 51 | public: |
---|
[1301] | 52 | /// Value of the condition representing the data |
---|
[1300] | 53 | vec value; |
---|
[1270] | 54 | |
---|
[1301] | 55 | /// Mulitplicity of the given condition may represent multiple occurences of same data entry. |
---|
[1300] | 56 | int multiplicity; |
---|
[1299] | 57 | |
---|
[1301] | 58 | /// Default constructor of condition class takes the value of data entry and creates a condition with multiplicity 1 (first occurence of the data). |
---|
[1300] | 59 | condition(vec value) |
---|
| 60 | { |
---|
| 61 | this->value = value; |
---|
| 62 | multiplicity = 1; |
---|
| 63 | } |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | |
---|
[1270] | 67 | /// A class describing a single polyhedron of the split complex. From a collection of such classes a Hasse diagram |
---|
| 68 | /// of the structure in the exponent of a Laplace-Inverse-Gamma density will be created. |
---|
| 69 | class polyhedron |
---|
| 70 | { |
---|
| 71 | /// A property having a value of 1 usually, with higher value only if the polyhedron arises as a coincidence of |
---|
| 72 | /// more than just the necessary number of conditions. For example if a newly created line passes through an already |
---|
| 73 | /// existing point, the points multiplicity will rise by 1. |
---|
| 74 | int multiplicity; |
---|
| 75 | |
---|
[1301] | 76 | /// A property representing the position of the polyhedron related to current condition with relation to which we |
---|
| 77 | /// are splitting the parameter space (new data has arrived). This property is setup within a classification procedure and |
---|
| 78 | /// is only valid while the new condition is being added. It has to be reset when new condition is added and new classification |
---|
| 79 | /// has to be performed. |
---|
[1270] | 80 | int split_state; |
---|
| 81 | |
---|
[1301] | 82 | /// A property representing the position of the polyhedron related to current condition with relation to which we |
---|
| 83 | /// are merging the parameter space (data is being deleted usually due to a moving window model which is more adaptive and |
---|
| 84 | /// steps in for the forgetting in a classical Gaussian AR model). This property is setup within a classification procedure and |
---|
| 85 | /// is only valid while the new condition is being removed. It has to be reset when new condition is removed and new classification |
---|
| 86 | /// has to be performed. |
---|
[1270] | 87 | int merge_state; |
---|
| 88 | |
---|
[1299] | 89 | |
---|
[1270] | 90 | |
---|
| 91 | public: |
---|
[1301] | 92 | /// A pointer to the multi-Laplace inverse gamma distribution this polyhedron belongs to. |
---|
[1270] | 93 | emlig* my_emlig; |
---|
| 94 | |
---|
| 95 | /// A list of polyhedrons parents within the Hasse diagram. |
---|
| 96 | list<polyhedron*> parents; |
---|
| 97 | |
---|
| 98 | /// A list of polyhedrons children withing the Hasse diagram. |
---|
| 99 | list<polyhedron*> children; |
---|
| 100 | |
---|
| 101 | /// All the vertices of the given polyhedron |
---|
| 102 | set<vertex*> vertices; |
---|
| 103 | |
---|
[1301] | 104 | /// The conditions that gave birth to the polyhedron. If some of them is removed, the polyhedron ceases to exist. |
---|
[1300] | 105 | set<condition*> parentconditions; |
---|
| 106 | |
---|
[1270] | 107 | /// A list used for storing children that lie in the positive region related to a certain condition |
---|
| 108 | list<polyhedron*> positivechildren; |
---|
| 109 | |
---|
| 110 | /// A list used for storing children that lie in the negative region related to a certain condition |
---|
| 111 | list<polyhedron*> negativechildren; |
---|
| 112 | |
---|
| 113 | /// Children intersecting the condition |
---|
| 114 | list<polyhedron*> neutralchildren; |
---|
| 115 | |
---|
[1301] | 116 | /// A set of grandchildren of the polyhedron that when new condition is added lie exactly on the condition hyperplane. These grandchildren |
---|
| 117 | /// behave differently from other grandchildren, when the polyhedron is split. New grandchild is not necessarily created on the crossection of |
---|
| 118 | /// the polyhedron and new condition. |
---|
[1299] | 119 | set<polyhedron*> totallyneutralgrandchildren; |
---|
[1270] | 120 | |
---|
[1301] | 121 | /// A set of children of the polyhedron that when new condition is added lie exactly on the condition hyperplane. These children |
---|
| 122 | /// behave differently from other children, when the polyhedron is split. New child is not necessarily created on the crossection of |
---|
| 123 | /// the polyhedron and new condition. |
---|
[1299] | 124 | set<polyhedron*> totallyneutralchildren; |
---|
[1270] | 125 | |
---|
[1301] | 126 | /// Reverse relation to the totallyneutralgrandchildren set is needed for merging of already existing polyhedrons to keep |
---|
| 127 | /// totallyneutralgrandchildren list up to date. |
---|
[1299] | 128 | set<polyhedron*> grandparents; |
---|
| 129 | |
---|
[1301] | 130 | /// Vertices of the polyhedron classified as positive related to an added condition. When the polyhderon is split by the new condition, |
---|
| 131 | /// these vertices will belong to the positive part of the splitted polyhedron. |
---|
[1270] | 132 | set<vertex*> positiveneutralvertices; |
---|
| 133 | |
---|
[1301] | 134 | /// Vertices of the polyhedron classified as negative related to an added condition. When the polyhderon is split by the new condition, |
---|
| 135 | /// these vertices will belong to the negative part of the splitted polyhedron. |
---|
[1270] | 136 | set<vertex*> negativeneutralvertices; |
---|
| 137 | |
---|
[1301] | 138 | /// A bool specifying if the polyhedron lies exactly on the newly added condition or not. |
---|
[1270] | 139 | bool totally_neutral; |
---|
| 140 | |
---|
[1301] | 141 | /// When two polyhedrons are merged, there always exists a child lying on the former border of the polyhedrons. This child manages the merge |
---|
| 142 | /// of the two polyhedrons. This property gives us the address of the mediator child. |
---|
[1299] | 143 | polyhedron* mergechild; |
---|
[1270] | 144 | |
---|
[1301] | 145 | /// If the polyhedron serves as a mergechild for two of its parents, we need to have the address of the parents to access them. This |
---|
| 146 | /// is the pointer to the positive parent being merged. |
---|
[1270] | 147 | polyhedron* positiveparent; |
---|
| 148 | |
---|
[1301] | 149 | /// If the polyhedron serves as a mergechild for two of its parents, we need to have the address of the parents to access them. This |
---|
| 150 | /// is the pointer to the negative parent being merged. |
---|
[1299] | 151 | polyhedron* negativeparent; |
---|
[1270] | 152 | |
---|
[1301] | 153 | /// Adressing withing the statistic. Next_poly is a pointer to the next polyhedron in the statistic on the same level (if this is a point, |
---|
| 154 | /// next_poly will be a point etc.). |
---|
[1270] | 155 | polyhedron* next_poly; |
---|
| 156 | |
---|
[1301] | 157 | /// Adressing withing the statistic. Prev_poly is a pointer to the previous polyhedron in the statistic on the same level (if this is a point, |
---|
| 158 | /// next_poly will be a point etc.). |
---|
[1270] | 159 | polyhedron* prev_poly; |
---|
| 160 | |
---|
[1301] | 161 | /// A property counting the number of messages obtained from children within a classification procedure of position of the polyhedron related |
---|
| 162 | /// an added/removed condition. If the message counter reaches the number of children, we know the polyhedrons' position has been fully classified. |
---|
[1270] | 163 | int message_counter; |
---|
| 164 | |
---|
| 165 | /// List of triangulation polyhedrons of the polyhedron given by their relative vertices. |
---|
| 166 | list<set<vertex*>> triangulation; |
---|
| 167 | |
---|
| 168 | /// A list of relative addresses serving for Hasse diagram construction. |
---|
| 169 | list<int> kids_rel_addresses; |
---|
| 170 | |
---|
| 171 | /// Default constructor |
---|
| 172 | polyhedron() |
---|
| 173 | { |
---|
| 174 | multiplicity = 1; |
---|
| 175 | |
---|
| 176 | message_counter = 0; |
---|
| 177 | |
---|
| 178 | totally_neutral = NULL; |
---|
[1300] | 179 | |
---|
| 180 | mergechild = NULL; |
---|
[1270] | 181 | } |
---|
| 182 | |
---|
| 183 | /// Setter for raising multiplicity |
---|
| 184 | void raise_multiplicity() |
---|
| 185 | { |
---|
| 186 | multiplicity++; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /// Setter for lowering multiplicity |
---|
| 190 | void lower_multiplicity() |
---|
| 191 | { |
---|
| 192 | multiplicity--; |
---|
| 193 | } |
---|
[1299] | 194 | |
---|
| 195 | int get_multiplicity() |
---|
| 196 | { |
---|
| 197 | return multiplicity; |
---|
| 198 | } |
---|
[1270] | 199 | |
---|
| 200 | /// An obligatory operator, when the class is used within a C++ STL structure like a vector |
---|
| 201 | int operator==(polyhedron polyhedron2) |
---|
| 202 | { |
---|
| 203 | return true; |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | /// An obligatory operator, when the class is used within a C++ STL structure like a vector |
---|
| 207 | int operator<(polyhedron polyhedron2) |
---|
| 208 | { |
---|
| 209 | return false; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | |
---|
[1301] | 213 | /// A setter of state of current polyhedron relative to the action specified in the argument. The three possible states of the |
---|
| 214 | /// polyhedron are -1 - NEGATIVE, 0 - NEUTRAL, 1 - POSITIVE. Neutral state means that either the state has been reset or the polyhedron is |
---|
| 215 | /// ready to be split/merged. |
---|
[1300] | 216 | int set_state(double state_indicator, actions action) |
---|
[1270] | 217 | { |
---|
| 218 | switch(action) |
---|
| 219 | { |
---|
| 220 | case MERGE: |
---|
[1300] | 221 | merge_state = (int)sign(state_indicator); |
---|
| 222 | return merge_state; |
---|
[1270] | 223 | case SPLIT: |
---|
| 224 | split_state = (int)sign(state_indicator); |
---|
[1300] | 225 | return split_state; |
---|
[1270] | 226 | } |
---|
| 227 | } |
---|
| 228 | |
---|
[1301] | 229 | /// A getter of state of current polyhedron relative to the action specified in the argument. The three possible states of the |
---|
| 230 | /// polyhedron are -1 - NEGATIVE, 0 - NEUTRAL, 1 - POSITIVE. Neutral state means that either the state has been reset or the polyhedron is |
---|
| 231 | /// ready to be split/merged. |
---|
[1270] | 232 | int get_state(actions action) |
---|
| 233 | { |
---|
| 234 | switch(action) |
---|
| 235 | { |
---|
| 236 | case MERGE: |
---|
| 237 | return merge_state; |
---|
| 238 | break; |
---|
| 239 | case SPLIT: |
---|
| 240 | return split_state; |
---|
| 241 | break; |
---|
| 242 | } |
---|
| 243 | } |
---|
| 244 | |
---|
[1301] | 245 | /// Method for obtaining the number of children of given polyhedron. |
---|
[1270] | 246 | int number_of_children() |
---|
| 247 | { |
---|
| 248 | return children.size(); |
---|
| 249 | } |
---|
| 250 | |
---|
[1301] | 251 | /// A method for triangulation of given polyhedron. |
---|
[1273] | 252 | void triangulate(bool should_integrate); |
---|
[1270] | 253 | }; |
---|
| 254 | |
---|
[1273] | 255 | |
---|
[1270] | 256 | /// A class for representing 0-dimensional polyhedron - a vertex. It will be located in the bottom row of the Hasse |
---|
| 257 | /// diagram representing a complex of polyhedrons. It has its coordinates in the parameter space. |
---|
| 258 | class vertex : public polyhedron |
---|
| 259 | { |
---|
| 260 | /// A dynamic array representing coordinates of the vertex |
---|
[1282] | 261 | vec coordinates; |
---|
[1270] | 262 | |
---|
| 263 | public: |
---|
[1301] | 264 | /// A property specifying the value of the density (ted nevim, jestli je to jakoby log nebo ne) above the vertex. |
---|
[1282] | 265 | double function_value; |
---|
[1270] | 266 | |
---|
| 267 | /// Default constructor |
---|
| 268 | vertex(); |
---|
| 269 | |
---|
| 270 | /// Constructor of a vertex from a set of coordinates |
---|
| 271 | vertex(vec coordinates) |
---|
| 272 | { |
---|
[1300] | 273 | this->coordinates = coordinates; |
---|
[1270] | 274 | |
---|
| 275 | vertices.insert(this); |
---|
| 276 | |
---|
| 277 | set<vertex*> vert_simplex; |
---|
| 278 | |
---|
| 279 | vert_simplex.insert(this); |
---|
| 280 | |
---|
| 281 | triangulation.push_back(vert_simplex); |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /// A method that widens the set of coordinates of given vertex. It is used when a complex in a parameter |
---|
| 285 | /// space of certain dimension is established, but the dimension is not known when the vertex is created. |
---|
| 286 | void push_coordinate(double coordinate) |
---|
| 287 | { |
---|
[1300] | 288 | coordinates = concat(coordinates,coordinate); |
---|
[1270] | 289 | } |
---|
| 290 | |
---|
| 291 | /// A method obtaining the set of coordinates of a vertex. These coordinates are not obtained as a pointer |
---|
| 292 | /// (not given by reference), but a new copy is created (they are given by value). |
---|
| 293 | vec get_coordinates() |
---|
[1300] | 294 | { |
---|
[1270] | 295 | return coordinates; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | }; |
---|
| 299 | |
---|
[1273] | 300 | |
---|
[1301] | 301 | /// A class representing a polyhedron in a top row of the complex. Such polyhedron has a condition that differen tiates |
---|
[1270] | 302 | /// it from polyhedrons in other rows. |
---|
| 303 | class toprow : public polyhedron |
---|
| 304 | { |
---|
| 305 | |
---|
| 306 | public: |
---|
| 307 | double probability; |
---|
| 308 | |
---|
[1282] | 309 | vertex* minimal_vertex; |
---|
| 310 | |
---|
[1270] | 311 | /// A condition used for determining the function of a Laplace-Inverse-Gamma density resulting from Bayesian estimation |
---|
[1300] | 312 | vec condition_sum; |
---|
[1270] | 313 | |
---|
| 314 | int condition_order; |
---|
| 315 | |
---|
| 316 | /// Default constructor |
---|
| 317 | toprow(){}; |
---|
| 318 | |
---|
| 319 | /// Constructor creating a toprow from the condition |
---|
[1300] | 320 | toprow(condition *condition, int condition_order) |
---|
[1270] | 321 | { |
---|
[1300] | 322 | this->condition_sum = condition->value; |
---|
[1270] | 323 | this->condition_order = condition_order; |
---|
| 324 | } |
---|
| 325 | |
---|
[1300] | 326 | toprow(vec condition_sum, int condition_order) |
---|
| 327 | { |
---|
[1301] | 328 | this->condition_sum = condition_sum; |
---|
| 329 | this->condition_order = condition_order; |
---|
[1300] | 330 | } |
---|
| 331 | |
---|
[1271] | 332 | double integrate_simplex(set<vertex*> simplex, char c); |
---|
| 333 | |
---|
[1270] | 334 | }; |
---|
| 335 | |
---|
[1273] | 336 | |
---|
[1270] | 337 | |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | class c_statistic |
---|
| 342 | { |
---|
[1272] | 343 | |
---|
| 344 | public: |
---|
[1270] | 345 | polyhedron* end_poly; |
---|
| 346 | polyhedron* start_poly; |
---|
| 347 | |
---|
| 348 | vector<polyhedron*> rows; |
---|
| 349 | |
---|
| 350 | vector<polyhedron*> row_ends; |
---|
| 351 | |
---|
| 352 | c_statistic() |
---|
| 353 | { |
---|
| 354 | end_poly = new polyhedron(); |
---|
| 355 | start_poly = new polyhedron(); |
---|
| 356 | }; |
---|
| 357 | |
---|
| 358 | void append_polyhedron(int row, polyhedron* appended_start, polyhedron* appended_end) |
---|
| 359 | { |
---|
| 360 | if(row>((int)rows.size())-1) |
---|
| 361 | { |
---|
| 362 | if(row>rows.size()) |
---|
| 363 | { |
---|
| 364 | throw new exception("You are trying to append a polyhedron whose children are not in the statistic yet!"); |
---|
| 365 | return; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | rows.push_back(end_poly); |
---|
| 369 | row_ends.push_back(end_poly); |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | // POSSIBLE FAILURE: the function is not checking if start and end are connected |
---|
| 373 | |
---|
| 374 | if(rows[row] != end_poly) |
---|
| 375 | { |
---|
| 376 | appended_start->prev_poly = row_ends[row]; |
---|
| 377 | row_ends[row]->next_poly = appended_start; |
---|
| 378 | |
---|
| 379 | } |
---|
| 380 | else if((row>0 && rows[row-1]!=end_poly)||row==0) |
---|
| 381 | { |
---|
| 382 | appended_start->prev_poly = start_poly; |
---|
| 383 | rows[row]= appended_start; |
---|
| 384 | } |
---|
| 385 | else |
---|
| 386 | { |
---|
| 387 | throw new exception("Wrong polyhedron insertion into statistic: missing intermediary polyhedron!"); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | appended_end->next_poly = end_poly; |
---|
| 391 | row_ends[row] = appended_end; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | void append_polyhedron(int row, polyhedron* appended_poly) |
---|
| 395 | { |
---|
| 396 | append_polyhedron(row,appended_poly,appended_poly); |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | void insert_polyhedron(int row, polyhedron* inserted_poly, polyhedron* following_poly) |
---|
| 400 | { |
---|
| 401 | if(following_poly != end_poly) |
---|
| 402 | { |
---|
| 403 | inserted_poly->next_poly = following_poly; |
---|
| 404 | inserted_poly->prev_poly = following_poly->prev_poly; |
---|
| 405 | |
---|
| 406 | if(following_poly->prev_poly == start_poly) |
---|
| 407 | { |
---|
| 408 | rows[row] = inserted_poly; |
---|
| 409 | } |
---|
| 410 | else |
---|
| 411 | { |
---|
| 412 | inserted_poly->prev_poly->next_poly = inserted_poly; |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | following_poly->prev_poly = inserted_poly; |
---|
| 416 | } |
---|
| 417 | else |
---|
| 418 | { |
---|
| 419 | this->append_polyhedron(row, inserted_poly); |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | void delete_polyhedron(int row, polyhedron* deleted_poly) |
---|
| 428 | { |
---|
| 429 | if(deleted_poly->prev_poly != start_poly) |
---|
| 430 | { |
---|
| 431 | deleted_poly->prev_poly->next_poly = deleted_poly->next_poly; |
---|
| 432 | } |
---|
| 433 | else |
---|
| 434 | { |
---|
| 435 | rows[row] = deleted_poly->next_poly; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | if(deleted_poly->next_poly!=end_poly) |
---|
| 439 | { |
---|
| 440 | deleted_poly->next_poly->prev_poly = deleted_poly->prev_poly; |
---|
| 441 | } |
---|
| 442 | else |
---|
| 443 | { |
---|
| 444 | row_ends[row] = deleted_poly->prev_poly; |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | |
---|
| 448 | |
---|
| 449 | deleted_poly->next_poly = NULL; |
---|
| 450 | deleted_poly->prev_poly = NULL; |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | int size() |
---|
| 454 | { |
---|
| 455 | return rows.size(); |
---|
| 456 | } |
---|
| 457 | |
---|
| 458 | polyhedron* get_end() |
---|
| 459 | { |
---|
| 460 | return end_poly; |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | polyhedron* get_start() |
---|
| 464 | { |
---|
| 465 | return start_poly; |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | int row_size(int row) |
---|
| 469 | { |
---|
| 470 | if(this->size()>row && row>=0) |
---|
| 471 | { |
---|
| 472 | int row_size = 0; |
---|
| 473 | |
---|
| 474 | for(polyhedron* row_poly = rows[row]; row_poly!=end_poly; row_poly=row_poly->next_poly) |
---|
| 475 | { |
---|
| 476 | row_size++; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | return row_size; |
---|
| 480 | } |
---|
| 481 | else |
---|
| 482 | { |
---|
| 483 | throw new exception("There is no row to obtain size from!"); |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | }; |
---|
| 487 | |
---|
[1273] | 488 | |
---|
[1267] | 489 | class my_ivec : public ivec |
---|
| 490 | { |
---|
| 491 | public: |
---|
| 492 | my_ivec():ivec(){}; |
---|
| 493 | |
---|
| 494 | my_ivec(ivec origin):ivec() |
---|
| 495 | { |
---|
| 496 | this->ins(0,origin); |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | bool operator>(const my_ivec &second) const |
---|
| 500 | { |
---|
[1280] | 501 | return max(*this)>max(second); |
---|
| 502 | |
---|
| 503 | /* |
---|
[1267] | 504 | int size1 = this->size(); |
---|
[1280] | 505 | int size2 = second.size(); |
---|
[1267] | 506 | |
---|
| 507 | int counter1 = 0; |
---|
| 508 | while(0==0) |
---|
| 509 | { |
---|
| 510 | if((*this)[counter1]==0) |
---|
| 511 | { |
---|
| 512 | size1--; |
---|
| 513 | } |
---|
| 514 | |
---|
| 515 | if((*this)[counter1]!=0) |
---|
| 516 | break; |
---|
| 517 | |
---|
| 518 | counter1++; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | int counter2 = 0; |
---|
| 522 | while(0==0) |
---|
| 523 | { |
---|
| 524 | if(second[counter2]==0) |
---|
| 525 | { |
---|
| 526 | size2--; |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | if(second[counter2]!=0) |
---|
| 530 | break; |
---|
| 531 | |
---|
| 532 | counter2++; |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | if(size1!=size2) |
---|
| 536 | { |
---|
| 537 | return size1>size2; |
---|
| 538 | } |
---|
| 539 | else |
---|
| 540 | { |
---|
| 541 | for(int i = 0;i<size1;i++) |
---|
| 542 | { |
---|
| 543 | if((*this)[counter1+i]!=second[counter2+i]) |
---|
| 544 | { |
---|
| 545 | return (*this)[counter1+i]>second[counter2+i]; |
---|
| 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | return false; |
---|
[1280] | 550 | }*/ |
---|
[1267] | 551 | } |
---|
| 552 | |
---|
| 553 | |
---|
| 554 | bool operator==(const my_ivec &second) const |
---|
| 555 | { |
---|
[1280] | 556 | return max(*this)==max(second); |
---|
| 557 | |
---|
| 558 | /* |
---|
[1267] | 559 | int size1 = this->size(); |
---|
[1280] | 560 | int size2 = second.size(); |
---|
[1267] | 561 | |
---|
| 562 | int counter = 0; |
---|
| 563 | while(0==0) |
---|
| 564 | { |
---|
| 565 | if((*this)[counter]==0) |
---|
| 566 | { |
---|
| 567 | size1--; |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | if((*this)[counter]!=0) |
---|
| 571 | break; |
---|
| 572 | |
---|
| 573 | counter++; |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | counter = 0; |
---|
| 577 | while(0==0) |
---|
| 578 | { |
---|
| 579 | if(second[counter]==0) |
---|
| 580 | { |
---|
| 581 | size2--; |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | if(second[counter]!=0) |
---|
| 585 | break; |
---|
| 586 | |
---|
| 587 | counter++; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | if(size1!=size2) |
---|
| 591 | { |
---|
| 592 | return false; |
---|
| 593 | } |
---|
| 594 | else |
---|
| 595 | { |
---|
| 596 | for(int i=0;i<size1;i++) |
---|
| 597 | { |
---|
| 598 | if((*this)[size()-1-i]!=second[second.size()-1-i]) |
---|
| 599 | { |
---|
| 600 | return false; |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | return true; |
---|
[1280] | 605 | }*/ |
---|
[1267] | 606 | } |
---|
| 607 | |
---|
| 608 | bool operator<(const my_ivec &second) const |
---|
| 609 | { |
---|
| 610 | return !(((*this)>second)||((*this)==second)); |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | bool operator!=(const my_ivec &second) const |
---|
| 614 | { |
---|
| 615 | return !((*this)==second); |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | bool operator<=(const my_ivec &second) const |
---|
| 619 | { |
---|
| 620 | return !((*this)>second); |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | bool operator>=(const my_ivec &second) const |
---|
| 624 | { |
---|
| 625 | return !((*this)<second); |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | my_ivec right(my_ivec original) |
---|
| 629 | { |
---|
| 630 | |
---|
| 631 | } |
---|
| 632 | }; |
---|
| 633 | |
---|
| 634 | |
---|
[1270] | 635 | |
---|
| 636 | |
---|
| 637 | |
---|
[1273] | 638 | |
---|
| 639 | |
---|
[1270] | 640 | //! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density |
---|
| 641 | class emlig // : eEF |
---|
| 642 | { |
---|
| 643 | |
---|
| 644 | /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result |
---|
| 645 | /// of data update from Bayesian estimation or set by the user if this emlig is a prior density |
---|
[1272] | 646 | |
---|
[1270] | 647 | |
---|
| 648 | vector<list<polyhedron*>> for_splitting; |
---|
| 649 | |
---|
| 650 | vector<list<polyhedron*>> for_merging; |
---|
| 651 | |
---|
| 652 | list<condition*> conditions; |
---|
| 653 | |
---|
| 654 | double normalization_factor; |
---|
| 655 | |
---|
[1282] | 656 | |
---|
| 657 | |
---|
[1300] | 658 | void alter_toprow_conditions(condition *condition, bool should_be_added) |
---|
[1270] | 659 | { |
---|
| 660 | for(polyhedron* horiz_ref = statistic.rows[statistic.size()-1];horiz_ref!=statistic.get_end();horiz_ref=horiz_ref->next_poly) |
---|
| 661 | { |
---|
| 662 | set<vertex*>::iterator vertex_ref = horiz_ref->vertices.begin(); |
---|
| 663 | |
---|
| 664 | do |
---|
| 665 | { |
---|
[1300] | 666 | vertex_ref++; |
---|
[1270] | 667 | } |
---|
[1300] | 668 | while((*vertex_ref)->parentconditions.find(condition)==(*vertex_ref)->parentconditions.end()); |
---|
[1270] | 669 | |
---|
[1300] | 670 | double product = (*vertex_ref)->get_coordinates()*condition->value; |
---|
| 671 | |
---|
[1301] | 672 | if(should_be_added) |
---|
[1270] | 673 | { |
---|
[1301] | 674 | ((toprow*) horiz_ref)->condition_order++; |
---|
| 675 | |
---|
| 676 | if(product>0) |
---|
| 677 | { |
---|
| 678 | ((toprow*) horiz_ref)->condition_sum += condition->value; |
---|
| 679 | } |
---|
| 680 | else |
---|
| 681 | { |
---|
| 682 | ((toprow*) horiz_ref)->condition_sum -= condition->value; |
---|
| 683 | } |
---|
[1270] | 684 | } |
---|
| 685 | else |
---|
[1301] | 686 | { |
---|
| 687 | ((toprow*) horiz_ref)->condition_order--; |
---|
| 688 | |
---|
| 689 | if(product<0) |
---|
| 690 | { |
---|
| 691 | ((toprow*) horiz_ref)->condition_sum += condition->value; |
---|
| 692 | } |
---|
| 693 | else |
---|
| 694 | { |
---|
| 695 | ((toprow*) horiz_ref)->condition_sum -= condition->value; |
---|
| 696 | } |
---|
[1270] | 697 | } |
---|
| 698 | } |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | |
---|
| 702 | |
---|
[1300] | 703 | void send_state_message(polyhedron* sender, condition *toadd, condition *toremove, int level) |
---|
[1270] | 704 | { |
---|
| 705 | |
---|
[1301] | 706 | bool shouldmerge = (toremove != NULL); |
---|
| 707 | bool shouldsplit = (toadd != NULL); |
---|
[1270] | 708 | |
---|
| 709 | if(shouldsplit||shouldmerge) |
---|
| 710 | { |
---|
| 711 | for(list<polyhedron*>::iterator parent_iterator = sender->parents.begin();parent_iterator!=sender->parents.end();parent_iterator++) |
---|
| 712 | { |
---|
| 713 | polyhedron* current_parent = *parent_iterator; |
---|
| 714 | |
---|
| 715 | current_parent->message_counter++; |
---|
| 716 | |
---|
[1300] | 717 | bool is_last = (current_parent->message_counter == current_parent->number_of_children()); |
---|
| 718 | bool is_first = (current_parent->message_counter == 1); |
---|
[1270] | 719 | |
---|
| 720 | if(shouldmerge) |
---|
| 721 | { |
---|
| 722 | int child_state = sender->get_state(MERGE); |
---|
| 723 | int parent_state = current_parent->get_state(MERGE); |
---|
| 724 | |
---|
[1300] | 725 | if(parent_state == 0||is_first) |
---|
[1270] | 726 | { |
---|
[1300] | 727 | parent_state = current_parent->set_state(child_state, MERGE); |
---|
| 728 | } |
---|
[1270] | 729 | |
---|
[1299] | 730 | if(child_state == 0) |
---|
[1270] | 731 | { |
---|
[1299] | 732 | if(current_parent->mergechild == NULL) |
---|
[1270] | 733 | { |
---|
[1299] | 734 | current_parent->mergechild = sender; |
---|
| 735 | } |
---|
| 736 | } |
---|
[1270] | 737 | |
---|
| 738 | if(is_last) |
---|
[1299] | 739 | { |
---|
[1301] | 740 | if(current_parent->mergechild != NULL) |
---|
[1270] | 741 | { |
---|
[1299] | 742 | if(current_parent->mergechild->get_multiplicity()==1) |
---|
[1270] | 743 | { |
---|
[1299] | 744 | if(parent_state > 0) |
---|
| 745 | { |
---|
| 746 | current_parent->mergechild->positiveparent = current_parent; |
---|
| 747 | } |
---|
[1270] | 748 | |
---|
[1299] | 749 | if(parent_state < 0) |
---|
| 750 | { |
---|
| 751 | current_parent->mergechild->negativeparent = current_parent; |
---|
| 752 | } |
---|
[1301] | 753 | } |
---|
| 754 | } |
---|
| 755 | else |
---|
| 756 | { |
---|
| 757 | if(parent_state == 1) |
---|
| 758 | { |
---|
| 759 | ((toprow*)current_parent)->condition_sum-=toremove->value; |
---|
| 760 | ((toprow*)current_parent)->condition_order--; |
---|
[1270] | 761 | } |
---|
[1301] | 762 | |
---|
| 763 | if(parent_state == -1) |
---|
| 764 | { |
---|
| 765 | ((toprow*)current_parent)->condition_sum+=toremove->value; |
---|
| 766 | ((toprow*)current_parent)->condition_order--; |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | //current_parent->set_state(0,MERGE); |
---|
[1270] | 770 | } |
---|
| 771 | |
---|
| 772 | if(parent_state == 0) |
---|
| 773 | { |
---|
[1301] | 774 | for_merging[level+1].push_back(current_parent); |
---|
| 775 | // current_parent->parentconditions.erase(toremove); |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | current_parent->mergechild = NULL; |
---|
| 779 | current_parent->message_counter = 0; |
---|
| 780 | |
---|
| 781 | if(level == number_of_parameters - 1) |
---|
[1300] | 782 | { |
---|
[1301] | 783 | toprow* cur_par_toprow = ((toprow*)current_parent); |
---|
| 784 | cur_par_toprow->probability = 0.0; |
---|
| 785 | |
---|
| 786 | for(list<set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) |
---|
| 787 | { |
---|
| 788 | cur_par_toprow->probability += cur_par_toprow->integrate_simplex(*t_ref,'C'); |
---|
| 789 | } |
---|
[1300] | 790 | } |
---|
[1299] | 791 | } |
---|
[1270] | 792 | } |
---|
| 793 | |
---|
| 794 | if(shouldsplit) |
---|
[1301] | 795 | { |
---|
| 796 | current_parent->totallyneutralgrandchildren.insert(sender->totallyneutralchildren.begin(),sender->totallyneutralchildren.end()); |
---|
| 797 | |
---|
| 798 | for(set<polyhedron*>::iterator tot_child_ref = sender->totallyneutralchildren.begin();tot_child_ref!=sender->totallyneutralchildren.end();tot_child_ref++) |
---|
[1270] | 799 | { |
---|
[1301] | 800 | (*tot_child_ref)->grandparents.insert(current_parent); |
---|
| 801 | } |
---|
[1270] | 802 | |
---|
[1301] | 803 | switch(sender->get_state(SPLIT)) |
---|
| 804 | { |
---|
| 805 | case 1: |
---|
| 806 | current_parent->positivechildren.push_back(sender); |
---|
| 807 | current_parent->positiveneutralvertices.insert(sender->vertices.begin(),sender->vertices.end()); |
---|
| 808 | break; |
---|
| 809 | case 0: |
---|
| 810 | current_parent->neutralchildren.push_back(sender); |
---|
| 811 | current_parent->positiveneutralvertices.insert(sender->positiveneutralvertices.begin(),sender->positiveneutralvertices.end()); |
---|
| 812 | current_parent->negativeneutralvertices.insert(sender->negativeneutralvertices.begin(),sender->negativeneutralvertices.end()); |
---|
| 813 | |
---|
| 814 | if(current_parent->totally_neutral == NULL) |
---|
[1299] | 815 | { |
---|
[1301] | 816 | current_parent->totally_neutral = sender->totally_neutral; |
---|
[1299] | 817 | } |
---|
[1301] | 818 | else |
---|
| 819 | { |
---|
| 820 | current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; |
---|
| 821 | } |
---|
[1299] | 822 | |
---|
[1301] | 823 | if(sender->totally_neutral) |
---|
[1270] | 824 | { |
---|
[1301] | 825 | current_parent->totallyneutralchildren.insert(sender); |
---|
| 826 | } |
---|
[1270] | 827 | |
---|
[1301] | 828 | break; |
---|
| 829 | case -1: |
---|
| 830 | current_parent->negativechildren.push_back(sender); |
---|
| 831 | current_parent->negativeneutralvertices.insert(sender->vertices.begin(),sender->vertices.end()); |
---|
| 832 | break; |
---|
| 833 | } |
---|
[1270] | 834 | |
---|
[1301] | 835 | if(is_last) |
---|
| 836 | { |
---|
| 837 | if((current_parent->negativechildren.size()>0&¤t_parent->positivechildren.size()>0)|| |
---|
| 838 | (current_parent->neutralchildren.size()>0&¤t_parent->totally_neutral==false)) |
---|
| 839 | { |
---|
[1270] | 840 | |
---|
[1301] | 841 | for_splitting[level+1].push_back(current_parent); |
---|
[1270] | 842 | |
---|
[1301] | 843 | current_parent->set_state(0, SPLIT); |
---|
| 844 | } |
---|
| 845 | else |
---|
| 846 | { |
---|
[1271] | 847 | |
---|
[1270] | 848 | |
---|
[1301] | 849 | if(current_parent->negativechildren.size()>0) |
---|
| 850 | { |
---|
| 851 | current_parent->set_state(-1, SPLIT); |
---|
[1270] | 852 | |
---|
[1301] | 853 | ((toprow*)current_parent)->condition_sum-=toadd->value; |
---|
[1271] | 854 | |
---|
| 855 | |
---|
[1301] | 856 | } |
---|
| 857 | else if(current_parent->positivechildren.size()>0) |
---|
| 858 | { |
---|
| 859 | current_parent->set_state(1, SPLIT); |
---|
[1270] | 860 | |
---|
[1301] | 861 | ((toprow*)current_parent)->condition_sum+=toadd->value; |
---|
| 862 | } |
---|
| 863 | else |
---|
| 864 | { |
---|
| 865 | current_parent->raise_multiplicity(); |
---|
| 866 | } |
---|
[1270] | 867 | |
---|
[1301] | 868 | ((toprow*)current_parent)->condition_order++; |
---|
[1271] | 869 | |
---|
[1301] | 870 | if(level == number_of_parameters - 1) |
---|
| 871 | { |
---|
| 872 | toprow* cur_par_toprow = ((toprow*)current_parent); |
---|
| 873 | cur_par_toprow->probability = 0.0; |
---|
| 874 | |
---|
| 875 | for(list<set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) |
---|
[1271] | 876 | { |
---|
[1301] | 877 | cur_par_toprow->probability += cur_par_toprow->integrate_simplex(*t_ref,'C'); |
---|
| 878 | } |
---|
| 879 | } |
---|
[1271] | 880 | |
---|
[1301] | 881 | current_parent->positivechildren.clear(); |
---|
| 882 | current_parent->negativechildren.clear(); |
---|
| 883 | current_parent->neutralchildren.clear(); |
---|
| 884 | current_parent->totallyneutralchildren.clear(); |
---|
| 885 | current_parent->totallyneutralgrandchildren.clear(); |
---|
| 886 | // current_parent->grandparents.clear(); |
---|
| 887 | current_parent->positiveneutralvertices.clear(); |
---|
| 888 | current_parent->negativeneutralvertices.clear(); |
---|
| 889 | current_parent->totally_neutral = NULL; |
---|
| 890 | current_parent->kids_rel_addresses.clear(); |
---|
| 891 | current_parent->message_counter = 0; |
---|
[1270] | 892 | } |
---|
| 893 | } |
---|
[1301] | 894 | } |
---|
[1270] | 895 | |
---|
[1301] | 896 | if(is_last) |
---|
| 897 | { |
---|
| 898 | send_state_message(current_parent,toadd,toremove,level+1); |
---|
| 899 | } |
---|
[1270] | 900 | |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | |
---|
[1266] | 906 | public: |
---|
[1272] | 907 | c_statistic statistic; |
---|
[1266] | 908 | |
---|
[1282] | 909 | vertex* minimal_vertex; |
---|
| 910 | |
---|
| 911 | double likelihood_value; |
---|
| 912 | |
---|
[1280] | 913 | vector<multiset<my_ivec>> correction_factors; |
---|
[1266] | 914 | |
---|
| 915 | int number_of_parameters; |
---|
| 916 | |
---|
| 917 | /// A default constructor creates an emlig with predefined statistic representing only the range of the given |
---|
| 918 | /// parametric space, where the number of parameters of the needed model is given as a parameter to the constructor. |
---|
| 919 | emlig(int number_of_parameters) |
---|
| 920 | { |
---|
| 921 | this->number_of_parameters = number_of_parameters; |
---|
| 922 | |
---|
[1282] | 923 | create_statistic(number_of_parameters); |
---|
| 924 | |
---|
| 925 | likelihood_value = numeric_limits<double>::max(); |
---|
[1266] | 926 | } |
---|
| 927 | |
---|
| 928 | /// A constructor for creating an emlig when the user wants to create the statistic by himself. The creation of a |
---|
| 929 | /// statistic is needed outside the constructor. Used for a user defined prior distribution on the parameters. |
---|
| 930 | emlig(c_statistic statistic) |
---|
| 931 | { |
---|
[1282] | 932 | this->statistic = statistic; |
---|
| 933 | |
---|
| 934 | likelihood_value = numeric_limits<double>::max(); |
---|
[1266] | 935 | } |
---|
| 936 | |
---|
| 937 | void step_me(int marker) |
---|
| 938 | { |
---|
[1301] | 939 | |
---|
[1266] | 940 | for(int i = 0;i<statistic.size();i++) |
---|
| 941 | { |
---|
| 942 | for(polyhedron* horiz_ref = statistic.rows[i];horiz_ref!=statistic.get_end();horiz_ref=horiz_ref->next_poly) |
---|
| 943 | { |
---|
[1301] | 944 | |
---|
[1275] | 945 | if(i==statistic.size()-1) |
---|
| 946 | { |
---|
[1301] | 947 | //cout << ((toprow*)horiz_ref)->condition_sum << " " << ((toprow*)horiz_ref)->probability << endl; |
---|
[1275] | 948 | cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; |
---|
| 949 | } |
---|
[1301] | 950 | if(i==0) |
---|
| 951 | { |
---|
| 952 | cout << ((vertex*)horiz_ref)->get_coordinates() << endl; |
---|
| 953 | } |
---|
| 954 | |
---|
[1266] | 955 | char* string = "Checkpoint"; |
---|
| 956 | } |
---|
| 957 | } |
---|
[1301] | 958 | |
---|
[1282] | 959 | |
---|
| 960 | /* |
---|
| 961 | list<vec> table_entries; |
---|
| 962 | for(polyhedron* horiz_ref = statistic.rows[statistic.size()-1];horiz_ref!=statistic.row_ends[statistic.size()-1];horiz_ref=horiz_ref->next_poly) |
---|
| 963 | { |
---|
| 964 | toprow *current_toprow = (toprow*)(horiz_ref); |
---|
| 965 | for(list<set<vertex*>>::iterator tri_ref = current_toprow->triangulation.begin();tri_ref!=current_toprow->triangulation.end();tri_ref++) |
---|
| 966 | { |
---|
| 967 | for(set<vertex*>::iterator vert_ref = (*tri_ref).begin();vert_ref!=(*tri_ref).end();vert_ref++) |
---|
| 968 | { |
---|
| 969 | vec table_entry = vec(); |
---|
| 970 | |
---|
| 971 | table_entry.ins(0,(*vert_ref)->get_coordinates()*current_toprow->condition.get(1,current_toprow->condition.size()-1)-current_toprow->condition.get(0,0)); |
---|
| 972 | |
---|
| 973 | table_entry.ins(0,(*vert_ref)->get_coordinates()); |
---|
| 974 | |
---|
| 975 | table_entries.push_back(table_entry); |
---|
| 976 | } |
---|
| 977 | } |
---|
| 978 | } |
---|
| 979 | |
---|
| 980 | unique(table_entries.begin(),table_entries.end()); |
---|
| 981 | |
---|
| 982 | |
---|
| 983 | |
---|
| 984 | for(list<vec>::iterator entry_ref = table_entries.begin();entry_ref!=table_entries.end();entry_ref++) |
---|
| 985 | { |
---|
| 986 | ofstream myfile; |
---|
| 987 | myfile.open("robust_data.txt", ios::out | ios::app); |
---|
| 988 | if (myfile.is_open()) |
---|
| 989 | { |
---|
| 990 | for(int i = 0;i<(*entry_ref).size();i++) |
---|
| 991 | { |
---|
| 992 | myfile << (*entry_ref)[i] << ";"; |
---|
| 993 | } |
---|
| 994 | myfile << endl; |
---|
| 995 | |
---|
| 996 | myfile.close(); |
---|
| 997 | } |
---|
| 998 | else |
---|
| 999 | { |
---|
| 1000 | cout << "File problem." << endl; |
---|
| 1001 | } |
---|
| 1002 | } |
---|
| 1003 | */ |
---|
| 1004 | |
---|
| 1005 | |
---|
| 1006 | return; |
---|
[1266] | 1007 | } |
---|
| 1008 | |
---|
| 1009 | int statistic_rowsize(int row) |
---|
| 1010 | { |
---|
| 1011 | return statistic.row_size(row); |
---|
| 1012 | } |
---|
| 1013 | |
---|
| 1014 | void add_condition(vec toadd) |
---|
| 1015 | { |
---|
| 1016 | vec null_vector = ""; |
---|
| 1017 | |
---|
| 1018 | add_and_remove_condition(toadd, null_vector); |
---|
| 1019 | } |
---|
| 1020 | |
---|
| 1021 | |
---|
| 1022 | void remove_condition(vec toremove) |
---|
| 1023 | { |
---|
| 1024 | vec null_vector = ""; |
---|
| 1025 | |
---|
| 1026 | add_and_remove_condition(null_vector, toremove); |
---|
| 1027 | |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | void add_and_remove_condition(vec toadd, vec toremove) |
---|
| 1031 | { |
---|
[1282] | 1032 | likelihood_value = numeric_limits<double>::max(); |
---|
| 1033 | |
---|
[1266] | 1034 | bool should_remove = (toremove.size() != 0); |
---|
| 1035 | bool should_add = (toadd.size() != 0); |
---|
| 1036 | |
---|
| 1037 | for_splitting.clear(); |
---|
| 1038 | for_merging.clear(); |
---|
| 1039 | |
---|
| 1040 | for(int i = 0;i<statistic.size();i++) |
---|
| 1041 | { |
---|
| 1042 | list<polyhedron*> empty_split; |
---|
| 1043 | list<polyhedron*> empty_merge; |
---|
| 1044 | |
---|
| 1045 | for_splitting.push_back(empty_split); |
---|
| 1046 | for_merging.push_back(empty_merge); |
---|
| 1047 | } |
---|
| 1048 | |
---|
| 1049 | list<condition*>::iterator toremove_ref = conditions.end(); |
---|
[1301] | 1050 | bool condition_should_be_added = should_add; |
---|
[1266] | 1051 | |
---|
| 1052 | for(list<condition*>::iterator ref = conditions.begin();ref!=conditions.end();ref++) |
---|
| 1053 | { |
---|
| 1054 | if(should_remove) |
---|
| 1055 | { |
---|
| 1056 | if((*ref)->value == toremove) |
---|
| 1057 | { |
---|
| 1058 | if((*ref)->multiplicity>1) |
---|
| 1059 | { |
---|
| 1060 | (*ref)->multiplicity--; |
---|
| 1061 | |
---|
[1300] | 1062 | alter_toprow_conditions(*ref,false); |
---|
[1266] | 1063 | |
---|
| 1064 | should_remove = false; |
---|
| 1065 | } |
---|
| 1066 | else |
---|
| 1067 | { |
---|
| 1068 | toremove_ref = ref; |
---|
| 1069 | } |
---|
| 1070 | } |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | if(should_add) |
---|
| 1074 | { |
---|
| 1075 | if((*ref)->value == toadd) |
---|
| 1076 | { |
---|
| 1077 | (*ref)->multiplicity++; |
---|
| 1078 | |
---|
[1300] | 1079 | alter_toprow_conditions(*ref,true); |
---|
[1266] | 1080 | |
---|
| 1081 | should_add = false; |
---|
[1301] | 1082 | |
---|
| 1083 | condition_should_be_added = false; |
---|
| 1084 | } |
---|
[1266] | 1085 | } |
---|
[1301] | 1086 | } |
---|
[1266] | 1087 | |
---|
[1300] | 1088 | condition* condition_to_remove = NULL; |
---|
| 1089 | |
---|
[1266] | 1090 | if(toremove_ref!=conditions.end()) |
---|
| 1091 | { |
---|
[1300] | 1092 | condition_to_remove = *toremove_ref; |
---|
[1301] | 1093 | conditions.erase(toremove_ref); |
---|
[1266] | 1094 | } |
---|
| 1095 | |
---|
[1300] | 1096 | condition* condition_to_add = NULL; |
---|
| 1097 | |
---|
[1266] | 1098 | if(condition_should_be_added) |
---|
| 1099 | { |
---|
[1301] | 1100 | condition* new_condition = new condition(toadd); |
---|
| 1101 | |
---|
| 1102 | conditions.push_back(new_condition); |
---|
| 1103 | condition_to_add = new_condition; |
---|
| 1104 | } |
---|
[1266] | 1105 | |
---|
| 1106 | for(polyhedron* horizontal_position = statistic.rows[0];horizontal_position!=statistic.get_end();horizontal_position=horizontal_position->next_poly) |
---|
| 1107 | { |
---|
| 1108 | vertex* current_vertex = (vertex*)horizontal_position; |
---|
| 1109 | |
---|
| 1110 | if(should_add||should_remove) |
---|
| 1111 | { |
---|
[1300] | 1112 | vec appended_coords = current_vertex->get_coordinates(); |
---|
| 1113 | appended_coords.ins(0,-1.0); |
---|
[1266] | 1114 | |
---|
| 1115 | if(should_add) |
---|
| 1116 | { |
---|
[1300] | 1117 | double local_condition = 0;// = toadd*(appended_coords.first/=appended_coords.second); |
---|
[1266] | 1118 | |
---|
[1300] | 1119 | local_condition = appended_coords*toadd; |
---|
| 1120 | |
---|
[1266] | 1121 | current_vertex->set_state(local_condition,SPLIT); |
---|
| 1122 | |
---|
[1300] | 1123 | /// \TODO There should be a rounding error tolerance used here to insure we are not having too many points because of rounding error. |
---|
[1266] | 1124 | if(local_condition == 0) |
---|
| 1125 | { |
---|
| 1126 | current_vertex->totally_neutral = true; |
---|
| 1127 | |
---|
| 1128 | current_vertex->raise_multiplicity(); |
---|
| 1129 | |
---|
| 1130 | current_vertex->negativeneutralvertices.insert(current_vertex); |
---|
| 1131 | current_vertex->positiveneutralvertices.insert(current_vertex); |
---|
| 1132 | } |
---|
| 1133 | } |
---|
| 1134 | |
---|
| 1135 | if(should_remove) |
---|
[1300] | 1136 | { |
---|
| 1137 | set<condition*>::iterator cond_ref; |
---|
| 1138 | |
---|
| 1139 | for(cond_ref = current_vertex->parentconditions.begin();cond_ref!=current_vertex->parentconditions.end();cond_ref++) |
---|
| 1140 | { |
---|
| 1141 | if(*cond_ref == condition_to_remove) |
---|
| 1142 | { |
---|
| 1143 | break; |
---|
| 1144 | } |
---|
| 1145 | } |
---|
[1266] | 1146 | |
---|
[1300] | 1147 | if(cond_ref!=current_vertex->parentconditions.end()) |
---|
[1266] | 1148 | { |
---|
[1300] | 1149 | current_vertex->parentconditions.erase(cond_ref); |
---|
| 1150 | current_vertex->set_state(0,MERGE); |
---|
[1266] | 1151 | for_merging[0].push_back(current_vertex); |
---|
| 1152 | } |
---|
[1300] | 1153 | else |
---|
| 1154 | { |
---|
| 1155 | double local_condition = toremove*appended_coords; |
---|
| 1156 | current_vertex->set_state(local_condition,MERGE); |
---|
| 1157 | } |
---|
[1266] | 1158 | } |
---|
| 1159 | } |
---|
| 1160 | |
---|
[1300] | 1161 | send_state_message(current_vertex, condition_to_add, condition_to_remove, 0); |
---|
[1266] | 1162 | |
---|
| 1163 | } |
---|
| 1164 | |
---|
[1300] | 1165 | |
---|
| 1166 | |
---|
[1299] | 1167 | if(should_remove) |
---|
| 1168 | { |
---|
[1300] | 1169 | for(int i = 0;i<for_merging.size();i++) |
---|
| 1170 | { |
---|
| 1171 | for(list<polyhedron*>::iterator merge_ref = for_merging[i].begin();merge_ref!=for_merging[i].end();merge_ref++) |
---|
| 1172 | { |
---|
| 1173 | cout << (*merge_ref)->get_state(MERGE) << ","; |
---|
| 1174 | } |
---|
| 1175 | |
---|
| 1176 | cout << endl; |
---|
| 1177 | } |
---|
| 1178 | |
---|
[1299] | 1179 | set<vertex*> vertices_to_be_reduced; |
---|
| 1180 | |
---|
| 1181 | int k = 1; |
---|
| 1182 | |
---|
| 1183 | for(vector<list<polyhedron*>>::iterator vert_ref = for_merging.begin();vert_ref<for_merging.end();vert_ref++) |
---|
| 1184 | { |
---|
| 1185 | for(list<polyhedron*>::reverse_iterator merge_ref = vert_ref->rbegin();merge_ref!=vert_ref->rend();merge_ref++) |
---|
| 1186 | { |
---|
| 1187 | if((*merge_ref)->get_multiplicity()>1) |
---|
| 1188 | { |
---|
| 1189 | if(k==1) |
---|
| 1190 | { |
---|
| 1191 | vertices_to_be_reduced.insert((vertex*)(*merge_ref)); |
---|
| 1192 | } |
---|
| 1193 | else |
---|
| 1194 | { |
---|
| 1195 | (*merge_ref)->lower_multiplicity(); |
---|
| 1196 | } |
---|
| 1197 | } |
---|
| 1198 | else |
---|
| 1199 | { |
---|
| 1200 | toprow* current_positive = (toprow*)(*merge_ref)->positiveparent; |
---|
| 1201 | toprow* current_negative = (toprow*)(*merge_ref)->negativeparent; |
---|
| 1202 | |
---|
[1300] | 1203 | current_positive->condition_sum -= toremove; |
---|
[1299] | 1204 | current_positive->condition_order--; |
---|
| 1205 | |
---|
| 1206 | current_positive->children.insert(current_positive->children.end(),current_negative->children.begin(),current_negative->children.end()); |
---|
| 1207 | current_positive->children.remove(*merge_ref); |
---|
| 1208 | |
---|
| 1209 | for(list<polyhedron*>::iterator child_ref = current_negative->children.begin();child_ref!=current_negative->children.end();child_ref++) |
---|
| 1210 | { |
---|
| 1211 | (*child_ref)->parents.remove(current_negative); |
---|
[1301] | 1212 | (*child_ref)->parents.push_back(current_positive); |
---|
[1299] | 1213 | } |
---|
| 1214 | |
---|
| 1215 | current_positive->negativechildren.insert(current_positive->negativechildren.end(),current_negative->negativechildren.begin(),current_negative->negativechildren.end()); |
---|
| 1216 | |
---|
| 1217 | current_positive->positivechildren.insert(current_positive->positivechildren.end(),current_negative->positivechildren.begin(),current_negative->positivechildren.end()); |
---|
| 1218 | |
---|
| 1219 | current_positive->neutralchildren.insert(current_positive->neutralchildren.end(),current_negative->positivechildren.begin(),current_negative->positivechildren.end()); |
---|
| 1220 | |
---|
| 1221 | switch((*merge_ref)->get_state(SPLIT)) |
---|
| 1222 | { |
---|
| 1223 | case -1: |
---|
| 1224 | current_positive->negativechildren.remove(*merge_ref); |
---|
| 1225 | break; |
---|
| 1226 | case 0: |
---|
| 1227 | current_positive->neutralchildren.remove(*merge_ref); |
---|
| 1228 | break; |
---|
| 1229 | case 1: |
---|
| 1230 | current_positive->positivechildren.remove(*merge_ref); |
---|
| 1231 | break; |
---|
| 1232 | } |
---|
| 1233 | |
---|
| 1234 | current_positive->parents.insert(current_positive->parents.begin(),current_negative->parents.begin(),current_negative->parents.end()); |
---|
[1301] | 1235 | // unique(current_positive->parents.begin(),current_positive->parents.end()); |
---|
[1299] | 1236 | |
---|
| 1237 | for(list<polyhedron*>::iterator parent_ref = current_negative->parents.begin();parent_ref!=current_negative->parents.end();parent_ref++) |
---|
| 1238 | { |
---|
| 1239 | (*parent_ref)->children.remove(current_negative); |
---|
| 1240 | (*parent_ref)->children.push_back(current_positive); |
---|
| 1241 | } |
---|
| 1242 | |
---|
| 1243 | current_positive->totallyneutralchildren.insert(current_negative->totallyneutralchildren.begin(),current_negative->totallyneutralchildren.end()); |
---|
| 1244 | current_positive->totallyneutralchildren.erase(*merge_ref); |
---|
| 1245 | |
---|
| 1246 | current_positive->totallyneutralgrandchildren.insert(current_negative->totallyneutralgrandchildren.begin(),current_negative->totallyneutralgrandchildren.end()); |
---|
| 1247 | |
---|
| 1248 | current_positive->vertices.insert(current_negative->vertices.begin(),current_negative->vertices.end()); |
---|
| 1249 | current_positive->negativeneutralvertices.insert(current_negative->negativeneutralvertices.begin(),current_negative->negativeneutralvertices.end()); |
---|
| 1250 | current_positive->positiveneutralvertices.insert(current_negative->positiveneutralvertices.begin(),current_negative->positiveneutralvertices.end()); |
---|
| 1251 | |
---|
| 1252 | for(set<vertex*>::iterator vert_ref = (*merge_ref)->vertices.begin();vert_ref!=(*merge_ref)->vertices.end();vert_ref++) |
---|
| 1253 | { |
---|
| 1254 | if((*vert_ref)->get_multiplicity()==1) |
---|
| 1255 | { |
---|
| 1256 | current_positive->vertices.erase(*vert_ref); |
---|
| 1257 | current_positive->negativeneutralvertices.erase(*vert_ref); |
---|
| 1258 | current_positive->positiveneutralvertices.erase(*vert_ref); |
---|
| 1259 | } |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | if(current_negative->get_state(SPLIT)==0&&!current_negative->totally_neutral) |
---|
| 1263 | { |
---|
| 1264 | for_splitting[k].remove(current_negative); |
---|
| 1265 | |
---|
| 1266 | if(current_positive->get_state(SPLIT)!=0||current_positive->totally_neutral) |
---|
| 1267 | { |
---|
| 1268 | for_splitting[k].push_back(current_positive); |
---|
| 1269 | } |
---|
| 1270 | } |
---|
| 1271 | |
---|
| 1272 | if(current_positive->totally_neutral) |
---|
| 1273 | { |
---|
| 1274 | if(!current_negative->totally_neutral) |
---|
| 1275 | { |
---|
| 1276 | for(set<polyhedron*>::iterator grand_ref = current_positive->grandparents.begin();grand_ref!=current_positive->grandparents.end();grand_ref++) |
---|
| 1277 | { |
---|
| 1278 | (*grand_ref)->totallyneutralgrandchildren.erase(current_positive); |
---|
[1301] | 1279 | } |
---|
[1299] | 1280 | } |
---|
| 1281 | else |
---|
| 1282 | { |
---|
| 1283 | for(set<polyhedron*>::iterator grand_ref = current_negative->grandparents.begin();grand_ref!=current_negative->grandparents.end();grand_ref++) |
---|
| 1284 | { |
---|
| 1285 | (*grand_ref)->totallyneutralgrandchildren.erase(current_negative); |
---|
| 1286 | (*grand_ref)->totallyneutralgrandchildren.insert(current_positive); |
---|
[1301] | 1287 | } |
---|
[1299] | 1288 | } |
---|
| 1289 | } |
---|
| 1290 | else |
---|
| 1291 | { |
---|
| 1292 | if(current_negative->totally_neutral) |
---|
| 1293 | { |
---|
| 1294 | for(set<polyhedron*>::iterator grand_ref = current_negative->grandparents.begin();grand_ref!=current_negative->grandparents.end();grand_ref++) |
---|
| 1295 | { |
---|
| 1296 | (*grand_ref)->totallyneutralgrandchildren.erase(current_negative); |
---|
| 1297 | } |
---|
| 1298 | } |
---|
| 1299 | } |
---|
| 1300 | |
---|
[1301] | 1301 | current_positive->grandparents.clear(); |
---|
| 1302 | |
---|
[1299] | 1303 | current_positive->totally_neutral = (current_positive->totally_neutral && current_negative->totally_neutral); |
---|
| 1304 | |
---|
| 1305 | current_positive->triangulate(k==for_splitting.size()-1); |
---|
| 1306 | |
---|
| 1307 | statistic.delete_polyhedron(k,current_negative); |
---|
| 1308 | |
---|
| 1309 | delete current_negative; |
---|
| 1310 | |
---|
| 1311 | for(list<polyhedron*>::iterator child_ref = (*merge_ref)->children.begin();child_ref!=(*merge_ref)->children.end();child_ref++) |
---|
| 1312 | { |
---|
| 1313 | (*child_ref)->parents.remove(*merge_ref); |
---|
| 1314 | } |
---|
| 1315 | |
---|
| 1316 | for(list<polyhedron*>::iterator parent_ref = (*merge_ref)->parents.begin();parent_ref!=(*merge_ref)->parents.end();parent_ref++) |
---|
| 1317 | { |
---|
| 1318 | (*parent_ref)->positivechildren.remove(*merge_ref); |
---|
| 1319 | (*parent_ref)->negativechildren.remove(*merge_ref); |
---|
| 1320 | (*parent_ref)->neutralchildren.remove(*merge_ref); |
---|
| 1321 | (*parent_ref)->children.remove(*merge_ref); |
---|
| 1322 | } |
---|
| 1323 | |
---|
| 1324 | for(set<polyhedron*>::iterator grand_ch_ref = (*merge_ref)->totallyneutralgrandchildren.begin();grand_ch_ref!=(*merge_ref)->totallyneutralgrandchildren.end();grand_ch_ref++) |
---|
| 1325 | { |
---|
| 1326 | (*grand_ch_ref)->grandparents.erase(*merge_ref); |
---|
| 1327 | } |
---|
| 1328 | |
---|
[1301] | 1329 | |
---|
[1299] | 1330 | for(set<polyhedron*>::iterator grand_p_ref = (*merge_ref)->grandparents.begin();grand_p_ref!=(*merge_ref)->grandparents.end();grand_p_ref++) |
---|
| 1331 | { |
---|
| 1332 | (*grand_p_ref)->totallyneutralgrandchildren.erase(*merge_ref); |
---|
| 1333 | } |
---|
[1301] | 1334 | |
---|
[1299] | 1335 | |
---|
| 1336 | statistic.delete_polyhedron(k-1,*merge_ref); |
---|
| 1337 | |
---|
| 1338 | if(k==1) |
---|
| 1339 | { |
---|
| 1340 | vertices_to_be_reduced.insert((vertex*)(*merge_ref)); |
---|
| 1341 | } |
---|
| 1342 | else |
---|
| 1343 | { |
---|
| 1344 | delete *merge_ref; |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | k++; |
---|
| 1350 | |
---|
| 1351 | } |
---|
| 1352 | |
---|
| 1353 | for(set<vertex*>::iterator vert_ref = vertices_to_be_reduced.begin();vert_ref!=vertices_to_be_reduced.end();vert_ref++) |
---|
| 1354 | { |
---|
| 1355 | if((*vert_ref)->get_multiplicity()>1) |
---|
| 1356 | { |
---|
| 1357 | (*vert_ref)->lower_multiplicity(); |
---|
| 1358 | } |
---|
| 1359 | else |
---|
| 1360 | { |
---|
| 1361 | delete *vert_ref; |
---|
| 1362 | } |
---|
| 1363 | } |
---|
| 1364 | } |
---|
[1300] | 1365 | |
---|
[1299] | 1366 | |
---|
[1266] | 1367 | if(should_add) |
---|
| 1368 | { |
---|
| 1369 | int k = 1; |
---|
| 1370 | |
---|
| 1371 | vector<list<polyhedron*>>::iterator beginning_ref = ++for_splitting.begin(); |
---|
| 1372 | |
---|
| 1373 | for(vector<list<polyhedron*>>::iterator vert_ref = beginning_ref;vert_ref<for_splitting.end();vert_ref++) |
---|
| 1374 | { |
---|
| 1375 | |
---|
| 1376 | for(list<polyhedron*>::reverse_iterator split_ref = vert_ref->rbegin();split_ref != vert_ref->rend();split_ref++) |
---|
| 1377 | { |
---|
| 1378 | polyhedron* new_totally_neutral_child; |
---|
| 1379 | |
---|
| 1380 | polyhedron* current_polyhedron = (*split_ref); |
---|
| 1381 | |
---|
| 1382 | if(vert_ref == beginning_ref) |
---|
| 1383 | { |
---|
| 1384 | vec coordinates1 = ((vertex*)(*(current_polyhedron->children.begin())))->get_coordinates(); |
---|
[1271] | 1385 | vec coordinates2 = ((vertex*)(*(++current_polyhedron->children.begin())))->get_coordinates(); |
---|
[1266] | 1386 | |
---|
[1271] | 1387 | vec extended_coord2 = coordinates2; |
---|
[1300] | 1388 | extended_coord2.ins(0,-1.0); |
---|
[1266] | 1389 | |
---|
[1300] | 1390 | double t = (-toadd*extended_coord2)/(toadd(1,toadd.size()-1)*(coordinates1-coordinates2)); |
---|
[1266] | 1391 | |
---|
[1300] | 1392 | vec new_coordinates = (1-t)*coordinates2+t*coordinates1; |
---|
[1271] | 1393 | |
---|
| 1394 | // cout << "c1:" << coordinates1 << endl << "c2:" << coordinates2 << endl << "nc:" << new_coordinates << endl; |
---|
| 1395 | |
---|
[1269] | 1396 | vertex* neutral_vertex = new vertex(new_coordinates); |
---|
[1266] | 1397 | |
---|
| 1398 | new_totally_neutral_child = neutral_vertex; |
---|
| 1399 | } |
---|
| 1400 | else |
---|
| 1401 | { |
---|
[1270] | 1402 | toprow* neutral_toprow = new toprow(); |
---|
[1299] | 1403 | |
---|
[1300] | 1404 | neutral_toprow->condition_sum = ((toprow*)current_polyhedron)->condition_sum; // tohle tu bylo driv: zeros(number_of_parameters+1); |
---|
[1270] | 1405 | neutral_toprow->condition_order = ((toprow*)current_polyhedron)->condition_order+1; |
---|
| 1406 | |
---|
[1266] | 1407 | new_totally_neutral_child = neutral_toprow; |
---|
| 1408 | } |
---|
[1269] | 1409 | |
---|
[1301] | 1410 | new_totally_neutral_child->parentconditions.insert(current_polyhedron->parentconditions.begin(),current_polyhedron->parentconditions.end()); |
---|
| 1411 | new_totally_neutral_child->parentconditions.insert(condition_to_add); |
---|
| 1412 | |
---|
[1269] | 1413 | new_totally_neutral_child->my_emlig = this; |
---|
[1266] | 1414 | |
---|
| 1415 | new_totally_neutral_child->children.insert(new_totally_neutral_child->children.end(), |
---|
| 1416 | current_polyhedron->totallyneutralgrandchildren.begin(), |
---|
| 1417 | current_polyhedron->totallyneutralgrandchildren.end()); |
---|
| 1418 | |
---|
[1299] | 1419 | |
---|
[1266] | 1420 | |
---|
[1270] | 1421 | // cout << ((toprow*)current_polyhedron)->condition << endl << toadd << endl; |
---|
[1269] | 1422 | |
---|
[1300] | 1423 | toprow* positive_poly = new toprow(((toprow*)current_polyhedron)->condition_sum+toadd, ((toprow*)current_polyhedron)->condition_order+1); |
---|
| 1424 | toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition_sum-toadd, ((toprow*)current_polyhedron)->condition_order+1); |
---|
[1266] | 1425 | |
---|
[1268] | 1426 | positive_poly->my_emlig = this; |
---|
| 1427 | negative_poly->my_emlig = this; |
---|
| 1428 | |
---|
[1299] | 1429 | for(set<polyhedron*>::iterator grand_ref = current_polyhedron->totallyneutralgrandchildren.begin(); grand_ref != current_polyhedron->totallyneutralgrandchildren.end();grand_ref++) |
---|
| 1430 | { |
---|
| 1431 | (*grand_ref)->parents.push_back(new_totally_neutral_child); |
---|
[1301] | 1432 | |
---|
| 1433 | // tohle tu nebylo. ma to tu byt? |
---|
| 1434 | //positive_poly->totallyneutralgrandchildren.insert(*grand_ref); |
---|
| 1435 | //negative_poly->totallyneutralgrandchildren.insert(*grand_ref); |
---|
[1299] | 1436 | |
---|
[1301] | 1437 | //(*grand_ref)->grandparents.insert(positive_poly); |
---|
| 1438 | //(*grand_ref)->grandparents.insert(negative_poly); |
---|
| 1439 | |
---|
[1299] | 1440 | new_totally_neutral_child->vertices.insert((*grand_ref)->vertices.begin(),(*grand_ref)->vertices.end()); |
---|
| 1441 | } |
---|
| 1442 | |
---|
| 1443 | positive_poly->children.push_back(new_totally_neutral_child); |
---|
| 1444 | negative_poly->children.push_back(new_totally_neutral_child); |
---|
| 1445 | |
---|
| 1446 | |
---|
[1266] | 1447 | for(list<polyhedron*>::iterator parent_ref = current_polyhedron->parents.begin();parent_ref!=current_polyhedron->parents.end();parent_ref++) |
---|
| 1448 | { |
---|
[1299] | 1449 | (*parent_ref)->totallyneutralgrandchildren.insert(new_totally_neutral_child); |
---|
[1301] | 1450 | // new_totally_neutral_child->grandparents.insert(*parent_ref); |
---|
[1266] | 1451 | |
---|
| 1452 | (*parent_ref)->neutralchildren.remove(current_polyhedron); |
---|
| 1453 | (*parent_ref)->children.remove(current_polyhedron); |
---|
| 1454 | |
---|
| 1455 | (*parent_ref)->children.push_back(positive_poly); |
---|
| 1456 | (*parent_ref)->children.push_back(negative_poly); |
---|
| 1457 | (*parent_ref)->positivechildren.push_back(positive_poly); |
---|
| 1458 | (*parent_ref)->negativechildren.push_back(negative_poly); |
---|
| 1459 | } |
---|
| 1460 | |
---|
| 1461 | positive_poly->parents.insert(positive_poly->parents.end(), |
---|
| 1462 | current_polyhedron->parents.begin(), |
---|
| 1463 | current_polyhedron->parents.end()); |
---|
| 1464 | |
---|
| 1465 | negative_poly->parents.insert(negative_poly->parents.end(), |
---|
| 1466 | current_polyhedron->parents.begin(), |
---|
| 1467 | current_polyhedron->parents.end()); |
---|
| 1468 | |
---|
[1299] | 1469 | |
---|
[1266] | 1470 | |
---|
| 1471 | new_totally_neutral_child->parents.push_back(positive_poly); |
---|
| 1472 | new_totally_neutral_child->parents.push_back(negative_poly); |
---|
| 1473 | |
---|
| 1474 | for(list<polyhedron*>::iterator child_ref = current_polyhedron->positivechildren.begin();child_ref!=current_polyhedron->positivechildren.end();child_ref++) |
---|
| 1475 | { |
---|
| 1476 | (*child_ref)->parents.remove(current_polyhedron); |
---|
| 1477 | (*child_ref)->parents.push_back(positive_poly); |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | positive_poly->children.insert(positive_poly->children.end(), |
---|
| 1481 | current_polyhedron->positivechildren.begin(), |
---|
| 1482 | current_polyhedron->positivechildren.end()); |
---|
| 1483 | |
---|
| 1484 | for(list<polyhedron*>::iterator child_ref = current_polyhedron->negativechildren.begin();child_ref!=current_polyhedron->negativechildren.end();child_ref++) |
---|
| 1485 | { |
---|
| 1486 | (*child_ref)->parents.remove(current_polyhedron); |
---|
| 1487 | (*child_ref)->parents.push_back(negative_poly); |
---|
| 1488 | } |
---|
| 1489 | |
---|
| 1490 | negative_poly->children.insert(negative_poly->children.end(), |
---|
| 1491 | current_polyhedron->negativechildren.begin(), |
---|
| 1492 | current_polyhedron->negativechildren.end()); |
---|
| 1493 | |
---|
| 1494 | positive_poly->vertices.insert(current_polyhedron->positiveneutralvertices.begin(),current_polyhedron->positiveneutralvertices.end()); |
---|
| 1495 | positive_poly->vertices.insert(new_totally_neutral_child->vertices.begin(),new_totally_neutral_child->vertices.end()); |
---|
| 1496 | |
---|
| 1497 | negative_poly->vertices.insert(current_polyhedron->negativeneutralvertices.begin(),current_polyhedron->negativeneutralvertices.end()); |
---|
| 1498 | negative_poly->vertices.insert(new_totally_neutral_child->vertices.begin(),new_totally_neutral_child->vertices.end()); |
---|
[1268] | 1499 | |
---|
[1266] | 1500 | new_totally_neutral_child->triangulate(false); |
---|
| 1501 | |
---|
| 1502 | positive_poly->triangulate(k==for_splitting.size()-1); |
---|
| 1503 | negative_poly->triangulate(k==for_splitting.size()-1); |
---|
| 1504 | |
---|
[1268] | 1505 | statistic.append_polyhedron(k-1, new_totally_neutral_child); |
---|
| 1506 | |
---|
[1266] | 1507 | statistic.insert_polyhedron(k, positive_poly, current_polyhedron); |
---|
| 1508 | statistic.insert_polyhedron(k, negative_poly, current_polyhedron); |
---|
| 1509 | |
---|
| 1510 | statistic.delete_polyhedron(k, current_polyhedron); |
---|
| 1511 | |
---|
| 1512 | delete current_polyhedron; |
---|
| 1513 | } |
---|
| 1514 | |
---|
| 1515 | k++; |
---|
| 1516 | } |
---|
| 1517 | } |
---|
| 1518 | |
---|
[1268] | 1519 | |
---|
[1266] | 1520 | vector<int> sizevector; |
---|
| 1521 | for(int s = 0;s<statistic.size();s++) |
---|
| 1522 | { |
---|
| 1523 | sizevector.push_back(statistic.row_size(s)); |
---|
[1301] | 1524 | cout << statistic.row_size(s) << ", "; |
---|
[1268] | 1525 | } |
---|
[1266] | 1526 | |
---|
[1301] | 1527 | cout << endl; |
---|
| 1528 | |
---|
[1269] | 1529 | /* |
---|
| 1530 | for(polyhedron* topr_ref = statistic.rows[statistic.size()-1];topr_ref!=statistic.row_ends[statistic.size()-1]->next_poly;topr_ref=topr_ref->next_poly) |
---|
| 1531 | { |
---|
| 1532 | cout << ((toprow*)topr_ref)->condition << endl; |
---|
| 1533 | } |
---|
| 1534 | */ |
---|
| 1535 | |
---|
[1266] | 1536 | } |
---|
| 1537 | |
---|
| 1538 | void set_correction_factors(int order) |
---|
| 1539 | { |
---|
[1280] | 1540 | for(int remaining_order = correction_factors.size();remaining_order<order;remaining_order++) |
---|
[1266] | 1541 | { |
---|
[1280] | 1542 | multiset<my_ivec> factor_templates; |
---|
| 1543 | multiset<my_ivec> final_factors; |
---|
[1266] | 1544 | |
---|
[1280] | 1545 | my_ivec orig_template = my_ivec(); |
---|
| 1546 | |
---|
| 1547 | for(int i = 1;i<number_of_parameters-remaining_order+1;i++) |
---|
[1266] | 1548 | { |
---|
[1280] | 1549 | bool in_cycle = false; |
---|
| 1550 | for(int j = 0;j<=remaining_order;j++) { |
---|
| 1551 | |
---|
| 1552 | multiset<my_ivec>::iterator fac_ref = factor_templates.begin(); |
---|
[1266] | 1553 | |
---|
[1280] | 1554 | do |
---|
[1266] | 1555 | { |
---|
[1280] | 1556 | my_ivec current_template; |
---|
| 1557 | if(!in_cycle) |
---|
| 1558 | { |
---|
| 1559 | current_template = orig_template; |
---|
| 1560 | in_cycle = true; |
---|
| 1561 | } |
---|
| 1562 | else |
---|
| 1563 | { |
---|
| 1564 | current_template = (*fac_ref); |
---|
| 1565 | fac_ref++; |
---|
| 1566 | } |
---|
[1266] | 1567 | |
---|
| 1568 | current_template.ins(current_template.size(),i); |
---|
| 1569 | |
---|
[1281] | 1570 | // cout << "template:" << current_template << endl; |
---|
[1266] | 1571 | |
---|
[1280] | 1572 | if(current_template.size()==remaining_order+1) |
---|
[1266] | 1573 | { |
---|
[1280] | 1574 | final_factors.insert(current_template); |
---|
[1266] | 1575 | } |
---|
| 1576 | else |
---|
| 1577 | { |
---|
| 1578 | factor_templates.insert(current_template); |
---|
| 1579 | } |
---|
| 1580 | } |
---|
[1280] | 1581 | while(fac_ref!=factor_templates.end()); |
---|
[1266] | 1582 | } |
---|
| 1583 | } |
---|
| 1584 | |
---|
| 1585 | correction_factors.push_back(final_factors); |
---|
| 1586 | |
---|
| 1587 | } |
---|
| 1588 | } |
---|
| 1589 | |
---|
| 1590 | protected: |
---|
| 1591 | |
---|
| 1592 | /// A method for creating plain default statistic representing only the range of the parameter space. |
---|
| 1593 | void create_statistic(int number_of_parameters) |
---|
| 1594 | { |
---|
[1301] | 1595 | /* |
---|
[1266] | 1596 | for(int i = 0;i<number_of_parameters;i++) |
---|
| 1597 | { |
---|
| 1598 | vec condition_vec = zeros(number_of_parameters+1); |
---|
| 1599 | condition_vec[i+1] = 1; |
---|
| 1600 | |
---|
| 1601 | condition* new_condition = new condition(condition_vec); |
---|
| 1602 | |
---|
| 1603 | conditions.push_back(new_condition); |
---|
| 1604 | } |
---|
[1301] | 1605 | */ |
---|
[1266] | 1606 | |
---|
| 1607 | // An empty vector of coordinates. |
---|
| 1608 | vec origin_coord; |
---|
| 1609 | |
---|
| 1610 | // We create an origin - this point will have all the coordinates zero, but now it has an empty vector of coords. |
---|
| 1611 | vertex *origin = new vertex(origin_coord); |
---|
[1268] | 1612 | |
---|
| 1613 | origin->my_emlig = this; |
---|
[1266] | 1614 | |
---|
| 1615 | /* |
---|
| 1616 | // As a statistic, we have to create a vector of vectors of polyhedron pointers. It will then represent the Hasse |
---|
| 1617 | // diagram. First we create a vector of polyhedrons.. |
---|
| 1618 | list<polyhedron*> origin_vec; |
---|
| 1619 | |
---|
| 1620 | // ..we fill it with the origin.. |
---|
| 1621 | origin_vec.push_back(origin); |
---|
| 1622 | |
---|
| 1623 | // ..and we fill the statistic with the created vector. |
---|
| 1624 | statistic.push_back(origin_vec); |
---|
| 1625 | */ |
---|
| 1626 | |
---|
[1268] | 1627 | statistic = *(new c_statistic()); |
---|
| 1628 | |
---|
[1266] | 1629 | statistic.append_polyhedron(0, origin); |
---|
| 1630 | |
---|
| 1631 | // Now we have a statistic for a zero dimensional space. Regarding to how many dimensional space we need to |
---|
| 1632 | // describe, we have to widen the descriptional default statistic. We use an iterative procedure as follows: |
---|
| 1633 | for(int i=0;i<number_of_parameters;i++) |
---|
| 1634 | { |
---|
| 1635 | // We first will create two new vertices. These will be the borders of the parameter space in the dimension |
---|
| 1636 | // of newly added parameter. Therefore they will have all coordinates except the last one zero. We get the |
---|
| 1637 | // right amount of zero cooridnates by reading them from the origin |
---|
| 1638 | vec origin_coord = origin->get_coordinates(); |
---|
| 1639 | |
---|
| 1640 | // And we incorporate the nonzero coordinates into the new cooordinate vectors |
---|
| 1641 | vec origin_coord1 = concat(origin_coord,-max_range); |
---|
| 1642 | vec origin_coord2 = concat(origin_coord,max_range); |
---|
| 1643 | |
---|
| 1644 | |
---|
| 1645 | // Now we create the points |
---|
| 1646 | vertex* new_point1 = new vertex(origin_coord1); |
---|
[1268] | 1647 | vertex* new_point2 = new vertex(origin_coord2); |
---|
| 1648 | |
---|
| 1649 | new_point1->my_emlig = this; |
---|
| 1650 | new_point2->my_emlig = this; |
---|
[1266] | 1651 | |
---|
| 1652 | //********************************************************************************************************* |
---|
| 1653 | // The algorithm for recursive build of a new Hasse diagram representing the space structure from the old |
---|
| 1654 | // diagram works so that you create two copies of the old Hasse diagram, you shift them up one level (points |
---|
| 1655 | // will be segments, segments will be areas etc.) and you connect each one of the original copied polyhedrons |
---|
| 1656 | // with its offspring by a parent-child relation. Also each of the segments in the first (second) copy is |
---|
| 1657 | // connected to the first (second) newly created vertex by a parent-child relation. |
---|
| 1658 | //********************************************************************************************************* |
---|
| 1659 | |
---|
| 1660 | |
---|
| 1661 | /* |
---|
| 1662 | // Create the vectors of vectors of pointers to polyhedrons to hold the copies of the old Hasse diagram |
---|
| 1663 | vector<vector<polyhedron*>> new_statistic1; |
---|
| 1664 | vector<vector<polyhedron*>> new_statistic2; |
---|
| 1665 | */ |
---|
| 1666 | |
---|
| 1667 | c_statistic* new_statistic1 = new c_statistic(); |
---|
| 1668 | c_statistic* new_statistic2 = new c_statistic(); |
---|
| 1669 | |
---|
| 1670 | |
---|
| 1671 | // Copy the statistic by rows |
---|
| 1672 | for(int j=0;j<statistic.size();j++) |
---|
| 1673 | { |
---|
| 1674 | |
---|
| 1675 | |
---|
| 1676 | // an element counter |
---|
| 1677 | int element_number = 0; |
---|
| 1678 | |
---|
| 1679 | /* |
---|
| 1680 | vector<polyhedron*> supportnew_1; |
---|
| 1681 | vector<polyhedron*> supportnew_2; |
---|
| 1682 | |
---|
| 1683 | new_statistic1.push_back(supportnew_1); |
---|
| 1684 | new_statistic2.push_back(supportnew_2); |
---|
| 1685 | */ |
---|
| 1686 | |
---|
| 1687 | // for each polyhedron in the given row |
---|
| 1688 | for(polyhedron* horiz_ref = statistic.rows[j];horiz_ref!=statistic.get_end();horiz_ref=horiz_ref->next_poly) |
---|
| 1689 | { |
---|
| 1690 | // Append an extra zero coordinate to each of the vertices for the new dimension |
---|
| 1691 | // If vert_ref is at the first index => we loop through vertices |
---|
| 1692 | if(j == 0) |
---|
| 1693 | { |
---|
| 1694 | // cast the polyhedron pointer to a vertex pointer and push a zero to its vector of coordinates |
---|
| 1695 | ((vertex*) horiz_ref)->push_coordinate(0); |
---|
| 1696 | } |
---|
| 1697 | /* |
---|
| 1698 | else |
---|
| 1699 | { |
---|
| 1700 | ((toprow*) (*horiz_ref))->condition.ins(0,0); |
---|
| 1701 | }*/ |
---|
| 1702 | |
---|
| 1703 | // if it has parents |
---|
| 1704 | if(!horiz_ref->parents.empty()) |
---|
| 1705 | { |
---|
| 1706 | // save the relative address of this child in a vector kids_rel_addresses of all its parents. |
---|
| 1707 | // This information will later be used for copying the whole Hasse diagram with each of the |
---|
| 1708 | // relations contained within. |
---|
| 1709 | for(list<polyhedron*>::iterator parent_ref = horiz_ref->parents.begin();parent_ref != horiz_ref->parents.end();parent_ref++) |
---|
| 1710 | { |
---|
| 1711 | (*parent_ref)->kids_rel_addresses.push_back(element_number); |
---|
| 1712 | } |
---|
| 1713 | } |
---|
| 1714 | |
---|
| 1715 | // ************************************************************************************************** |
---|
| 1716 | // Here we begin creating a new polyhedron, which will be a copy of the old one. Each such polyhedron |
---|
| 1717 | // will be created as a toprow, but this information will be later forgotten and only the polyhedrons |
---|
| 1718 | // in the top row of the Hasse diagram will be considered toprow for later use. |
---|
| 1719 | // ************************************************************************************************** |
---|
| 1720 | |
---|
| 1721 | // First we create vectors specifying a toprow condition. In the case of a preconstructed statistic |
---|
| 1722 | // this condition will be a vector of zeros. There are two vectors, because we need two copies of |
---|
| 1723 | // the original Hasse diagram. |
---|
| 1724 | vec vec1(number_of_parameters+1); |
---|
| 1725 | vec1.zeros(); |
---|
| 1726 | |
---|
| 1727 | vec vec2(number_of_parameters+1); |
---|
| 1728 | vec2.zeros(); |
---|
| 1729 | |
---|
| 1730 | // We create a new toprow with the previously specified condition. |
---|
| 1731 | toprow* current_copy1 = new toprow(vec1, 0); |
---|
[1268] | 1732 | toprow* current_copy2 = new toprow(vec2, 0); |
---|
[1266] | 1733 | |
---|
[1268] | 1734 | current_copy1->my_emlig = this; |
---|
| 1735 | current_copy2->my_emlig = this; |
---|
| 1736 | |
---|
[1266] | 1737 | // The vertices of the copies will be inherited, because there will be a parent/child relation |
---|
| 1738 | // between each polyhedron and its offspring (comming from the copy) and a parent has all the |
---|
| 1739 | // vertices of its child plus more. |
---|
| 1740 | for(set<vertex*>::iterator vertex_ref = horiz_ref->vertices.begin();vertex_ref!=horiz_ref->vertices.end();vertex_ref++) |
---|
| 1741 | { |
---|
| 1742 | current_copy1->vertices.insert(*vertex_ref); |
---|
| 1743 | current_copy2->vertices.insert(*vertex_ref); |
---|
| 1744 | } |
---|
| 1745 | |
---|
| 1746 | // The only new vertex of the offspring should be the newly created point. |
---|
| 1747 | current_copy1->vertices.insert(new_point1); |
---|
| 1748 | current_copy2->vertices.insert(new_point2); |
---|
| 1749 | |
---|
| 1750 | // This method guarantees that each polyhedron is already triangulated, therefore its triangulation |
---|
| 1751 | // is only one set of vertices and it is the set of all its vertices. |
---|
| 1752 | set<vertex*> t_simplex1; |
---|
| 1753 | set<vertex*> t_simplex2; |
---|
| 1754 | |
---|
| 1755 | t_simplex1.insert(current_copy1->vertices.begin(),current_copy1->vertices.end()); |
---|
| 1756 | t_simplex2.insert(current_copy2->vertices.begin(),current_copy2->vertices.end()); |
---|
| 1757 | |
---|
| 1758 | current_copy1->triangulation.push_back(t_simplex1); |
---|
| 1759 | current_copy2->triangulation.push_back(t_simplex2); |
---|
| 1760 | |
---|
| 1761 | // Now we have copied the polyhedron and we have to copy all of its relations. Because we are copying |
---|
| 1762 | // in the Hasse diagram from bottom up, we always have to copy the parent/child relations to all the |
---|
| 1763 | // kids and when we do that and know the child, in the child we will remember the parent we came from. |
---|
| 1764 | // This way all the parents/children relations are saved in both the parent and the child. |
---|
| 1765 | if(!horiz_ref->kids_rel_addresses.empty()) |
---|
| 1766 | { |
---|
| 1767 | for(list<int>::iterator kid_ref = horiz_ref->kids_rel_addresses.begin();kid_ref!=horiz_ref->kids_rel_addresses.end();kid_ref++) |
---|
| 1768 | { |
---|
| 1769 | polyhedron* new_kid1 = new_statistic1->rows[j-1]; |
---|
| 1770 | polyhedron* new_kid2 = new_statistic2->rows[j-1]; |
---|
| 1771 | |
---|
| 1772 | // THIS IS NOT EFFECTIVE: It could be improved by having the list indexed for new_statistic, but |
---|
| 1773 | // not indexed for statistic. Hopefully this will not cause a big slowdown - happens only offline. |
---|
| 1774 | if(*kid_ref) |
---|
| 1775 | { |
---|
| 1776 | for(int k = 1;k<=(*kid_ref);k++) |
---|
| 1777 | { |
---|
| 1778 | new_kid1=new_kid1->next_poly; |
---|
| 1779 | new_kid2=new_kid2->next_poly; |
---|
| 1780 | } |
---|
| 1781 | } |
---|
| 1782 | |
---|
| 1783 | // find the child and save the relation to the parent |
---|
| 1784 | current_copy1->children.push_back(new_kid1); |
---|
| 1785 | current_copy2->children.push_back(new_kid2); |
---|
| 1786 | |
---|
| 1787 | // in the child save the parents' address |
---|
| 1788 | new_kid1->parents.push_back(current_copy1); |
---|
| 1789 | new_kid2->parents.push_back(current_copy2); |
---|
| 1790 | } |
---|
| 1791 | |
---|
| 1792 | // Here we clear the parents kids_rel_addresses vector for later use (when we need to widen the |
---|
| 1793 | // Hasse diagram again) |
---|
| 1794 | horiz_ref->kids_rel_addresses.clear(); |
---|
| 1795 | } |
---|
| 1796 | // If there were no children previously, we are copying a polyhedron that has been a vertex before. |
---|
| 1797 | // In this case it is a segment now and it will have a relation to its mother (copywise) and to the |
---|
| 1798 | // newly created point. Here we create the connection to the new point, again from both sides. |
---|
| 1799 | else |
---|
| 1800 | { |
---|
| 1801 | // Add the address of the new point in the former vertex |
---|
| 1802 | current_copy1->children.push_back(new_point1); |
---|
| 1803 | current_copy2->children.push_back(new_point2); |
---|
| 1804 | |
---|
| 1805 | // Add the address of the former vertex in the new point |
---|
| 1806 | new_point1->parents.push_back(current_copy1); |
---|
| 1807 | new_point2->parents.push_back(current_copy2); |
---|
| 1808 | } |
---|
| 1809 | |
---|
| 1810 | // Save the mother in its offspring |
---|
| 1811 | current_copy1->children.push_back(horiz_ref); |
---|
| 1812 | current_copy2->children.push_back(horiz_ref); |
---|
| 1813 | |
---|
| 1814 | // Save the offspring in its mother |
---|
| 1815 | horiz_ref->parents.push_back(current_copy1); |
---|
| 1816 | horiz_ref->parents.push_back(current_copy2); |
---|
| 1817 | |
---|
| 1818 | |
---|
| 1819 | // Add the copies into the relevant statistic. The statistic will later be appended to the previous |
---|
| 1820 | // Hasse diagram |
---|
| 1821 | new_statistic1->append_polyhedron(j,current_copy1); |
---|
| 1822 | new_statistic2->append_polyhedron(j,current_copy2); |
---|
| 1823 | |
---|
| 1824 | // Raise the count in the vector of polyhedrons |
---|
| 1825 | element_number++; |
---|
| 1826 | |
---|
| 1827 | } |
---|
| 1828 | |
---|
| 1829 | } |
---|
| 1830 | |
---|
| 1831 | /* |
---|
| 1832 | statistic.begin()->push_back(new_point1); |
---|
| 1833 | statistic.begin()->push_back(new_point2); |
---|
| 1834 | */ |
---|
| 1835 | |
---|
| 1836 | statistic.append_polyhedron(0, new_point1); |
---|
| 1837 | statistic.append_polyhedron(0, new_point2); |
---|
| 1838 | |
---|
| 1839 | // Merge the new statistics into the old one. This will either be the final statistic or we will |
---|
| 1840 | // reenter the widening loop. |
---|
| 1841 | for(int j=0;j<new_statistic1->size();j++) |
---|
| 1842 | { |
---|
| 1843 | /* |
---|
| 1844 | if(j+1==statistic.size()) |
---|
| 1845 | { |
---|
| 1846 | list<polyhedron*> support; |
---|
| 1847 | statistic.push_back(support); |
---|
| 1848 | } |
---|
| 1849 | |
---|
| 1850 | (statistic.begin()+j+1)->insert((statistic.begin()+j+1)->end(),new_statistic1[j].begin(),new_statistic1[j].end()); |
---|
| 1851 | (statistic.begin()+j+1)->insert((statistic.begin()+j+1)->end(),new_statistic2[j].begin(),new_statistic2[j].end()); |
---|
| 1852 | */ |
---|
| 1853 | statistic.append_polyhedron(j+1,new_statistic1->rows[j],new_statistic1->row_ends[j]); |
---|
| 1854 | statistic.append_polyhedron(j+1,new_statistic2->rows[j],new_statistic2->row_ends[j]); |
---|
[1268] | 1855 | } |
---|
[1266] | 1856 | } |
---|
| 1857 | |
---|
| 1858 | /* |
---|
| 1859 | vector<list<toprow*>> toprow_statistic; |
---|
| 1860 | int line_count = 0; |
---|
| 1861 | |
---|
| 1862 | for(vector<list<polyhedron*>>::iterator polyhedron_ref = ++statistic.begin(); polyhedron_ref!=statistic.end();polyhedron_ref++) |
---|
| 1863 | { |
---|
| 1864 | list<toprow*> support_list; |
---|
| 1865 | toprow_statistic.push_back(support_list); |
---|
| 1866 | |
---|
| 1867 | for(list<polyhedron*>::iterator polyhedron_ref2 = polyhedron_ref->begin(); polyhedron_ref2 != polyhedron_ref->end(); polyhedron_ref2++) |
---|
| 1868 | { |
---|
| 1869 | toprow* support_top = (toprow*)(*polyhedron_ref2); |
---|
| 1870 | |
---|
| 1871 | toprow_statistic[line_count].push_back(support_top); |
---|
| 1872 | } |
---|
| 1873 | |
---|
| 1874 | line_count++; |
---|
| 1875 | }*/ |
---|
| 1876 | |
---|
| 1877 | /* |
---|
| 1878 | vector<int> sizevector; |
---|
| 1879 | for(int s = 0;s<statistic.size();s++) |
---|
| 1880 | { |
---|
| 1881 | sizevector.push_back(statistic.row_size(s)); |
---|
| 1882 | } |
---|
| 1883 | */ |
---|
| 1884 | |
---|
| 1885 | } |
---|
| 1886 | |
---|
[1270] | 1887 | |
---|
| 1888 | |
---|
| 1889 | |
---|
| 1890 | }; |
---|
| 1891 | |
---|
| 1892 | |
---|
[1300] | 1893 | |
---|
[1270] | 1894 | //! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density |
---|
[1300] | 1895 | class RARX //: public BM |
---|
[1270] | 1896 | { |
---|
| 1897 | private: |
---|
| 1898 | |
---|
[1301] | 1899 | |
---|
[1270] | 1900 | |
---|
[1301] | 1901 | int window_size; |
---|
[1300] | 1902 | |
---|
[1301] | 1903 | list<vec> conditions; |
---|
| 1904 | |
---|
[1270] | 1905 | public: |
---|
[1301] | 1906 | emlig* posterior; |
---|
| 1907 | |
---|
[1300] | 1908 | RARX(int number_of_parameters, const int window_size)//:BM() |
---|
[1270] | 1909 | { |
---|
[1300] | 1910 | posterior = new emlig(number_of_parameters); |
---|
| 1911 | |
---|
[1301] | 1912 | this->window_size = window_size; |
---|
[1270] | 1913 | }; |
---|
| 1914 | |
---|
[1300] | 1915 | void bayes(const itpp::vec &yt, const itpp::vec &cond = "") |
---|
[1270] | 1916 | { |
---|
[1301] | 1917 | conditions.push_back(yt); |
---|
| 1918 | |
---|
| 1919 | //posterior->step_me(0); |
---|
[1270] | 1920 | |
---|
[1301] | 1921 | if(conditions.size()>window_size && window_size!=0) |
---|
| 1922 | { |
---|
| 1923 | posterior->add_and_remove_condition(yt,conditions.front()); |
---|
| 1924 | conditions.pop_front(); |
---|
| 1925 | |
---|
| 1926 | //posterior->step_me(1); |
---|
| 1927 | } |
---|
| 1928 | else |
---|
| 1929 | { |
---|
| 1930 | posterior->add_condition(yt); |
---|
| 1931 | } |
---|
| 1932 | |
---|
[1270] | 1933 | } |
---|
| 1934 | |
---|
[1300] | 1935 | }; |
---|
[1270] | 1936 | |
---|
| 1937 | |
---|
| 1938 | |
---|
| 1939 | #endif //TRAGE_H |
---|