Changeset 1213 for applications/robust
- Timestamp:
- 10/08/10 18:39:39 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1208 r1213 10 10 using namespace itpp; 11 11 12 //using namespace bdm;12 using namespace bdm; 13 13 14 14 int main ( int argc, char* argv[] ) { -
applications/robust/robustlib.h
r1212 r1213 11 11 #include <limits> 12 12 #include <vector> 13 #include <list> 13 14 #include <algorithm> 14 15 … … 41 42 public: 42 43 /// A list of polyhedrons parents within the Hasse diagram. 43 vector<polyhedron*> parents;44 list<polyhedron*> parents; 44 45 45 46 /// A list of polyhedrons children withing the Hasse diagram. 46 vector<polyhedron*> children;47 list<polyhedron*> children; 47 48 48 49 /// All the vertices of the given polyhedron 49 vector<vertex*> vertices;50 list<vertex*> vertices; 50 51 51 52 /// A list used for storing children that lie in the positive region related to a certain condition 52 vector<polyhedron*> positivechildren;53 list<polyhedron*> positivechildren; 53 54 54 55 /// A list used for storing children that lie in the negative region related to a certain condition 55 vector<polyhedron*> negativechildren;56 list<polyhedron*> negativechildren; 56 57 57 58 /// Children intersecting the condition 58 vector<polyhedron*> neutralchildren;59 60 vector<polyhedron*> totallyneutralgrandchildren;61 62 vector<polyhedron*> totallyneutralchildren;59 list<polyhedron*> neutralchildren; 60 61 list<polyhedron*> totallyneutralgrandchildren; 62 63 list<polyhedron*> totallyneutralchildren; 63 64 64 65 bool totally_neutral; 65 66 66 vector<polyhedron*> mergechildren;67 list<polyhedron*> mergechildren; 67 68 68 69 polyhedron* positiveparent; … … 73 74 74 75 /// List of triangulation polyhedrons of the polyhedron given by their relative vertices. 75 vector<vector<vertex*>> triangulations;76 list<list<vertex*>> triangulations; 76 77 77 78 /// A list of relative addresses serving for Hasse diagram construction. 78 vector<int> kids_rel_addresses;79 list<int> kids_rel_addresses; 79 80 80 81 /// Default constructor … … 197 198 198 199 /// Default constructor 199 toprow() ;200 toprow(){}; 200 201 201 202 /// Constructor creating a toprow from the condition … … 228 229 /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result 229 230 /// of data update from Bayesian estimation or set by the user if this emlig is a prior density 230 vector< vector<polyhedron*>> statistic;231 232 vector< vector<polyhedron*>> for_splitting;231 vector<list<polyhedron*>> statistic; 232 233 vector<list<polyhedron*>> for_splitting; 233 234 234 vector< vector<polyhedron*>> for_merging;235 236 vector<condition*> conditions;235 vector<list<polyhedron*>> for_merging; 236 237 list<condition*> conditions; 237 238 238 239 double normalization_factor; … … 240 241 void alter_toprow_conditions(vec condition, bool should_be_added) 241 242 { 242 for( vector<polyhedron*>::iterator horiz_ref = statistic[statistic.size()-1].begin();horiz_ref<statistic[statistic.size()-1].end();horiz_ref++)243 for(list<polyhedron*>::iterator horiz_ref = (statistic.end()--)->begin();horiz_ref!=(statistic.end()--)->end();horiz_ref++) 243 244 { 244 245 double product = 0; 245 246 246 vector<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin();247 list<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin(); 247 248 248 249 do … … 267 268 { 268 269 269 bool should _remove = (toremove.size() != 0);270 bool should _add= (toadd.size() != 0);270 bool shouldmerge = (toremove.size() != 0); 271 bool shouldsplit = (toadd.size() != 0); 271 272 272 273 if(shouldsplit||shouldmerge) 273 274 { 274 for( vector<polyhedron*>::iterator parent_iterator = sender->parents.begin();parent_iterator<sender->parents.end();parent_iterator++)275 for(list<polyhedron*>::iterator parent_iterator = sender->parents.begin();parent_iterator!=sender->parents.end();parent_iterator++) 275 276 { 276 277 polyhedron* current_parent = *parent_iterator; … … 313 314 if(parent_state > 0) 314 315 { 315 for( vector<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child <current_parent->mergechildren.end();merge_child++)316 for(list<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child != current_parent->mergechildren.end();merge_child++) 316 317 { 317 318 (*merge_child)->positiveparent = current_parent; … … 321 322 if(parent_state < 0) 322 323 { 323 for( vector<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child <current_parent->mergechildren.end();merge_child++)324 for(list<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child != current_parent->mergechildren.end();merge_child++) 324 325 { 325 326 (*merge_child)->negativeparent = current_parent; … … 413 414 if(is_last) 414 415 { 415 send_state_message(current_parent, shouldsplit,shouldmerge,level+1);416 send_state_message(current_parent,toadd,toremove,level+1); 416 417 } 417 418 … … 429 430 create_statistic(number_of_parameters); 430 431 431 for(vector< vector<polyhedron*>::iterator local_iter = statistic.begin();local_iter<statistic.end();local_iter++)432 { 433 vector<polyhedron*> empty_split;434 vector<polyhedron*> empty_merge;432 for(vector<list<polyhedron*>>::iterator local_iter = statistic.begin();local_iter<statistic.end();local_iter++) 433 { 434 list<polyhedron*> empty_split; 435 list<polyhedron*> empty_merge; 435 436 436 437 for_splitting.push_back(empty_split); … … 441 442 /// A constructor for creating an emlig when the user wants to create the statistic by himself. The creation of a 442 443 /// statistic is needed outside the constructor. Used for a user defined prior distribution on the parameters. 443 emlig(vector< vector<polyhedron*>> statistic)444 emlig(vector<list<polyhedron*>> statistic) 444 445 { 445 446 this->statistic = statistic; … … 466 467 bool should_add = (toadd.size() != 0); 467 468 468 vector<condition*>::iterator toremove_ref = conditions.end();469 list<condition*>::iterator toremove_ref = conditions.end(); 469 470 bool condition_should_be_added = false; 470 471 471 for( vector<condition*>::iterator ref = conditions.begin();ref<conditions.end();ref++)472 for(list<condition*>::iterator ref = conditions.begin();ref!=conditions.end();ref++) 472 473 { 473 474 if(should_remove) … … 519 520 520 521 521 for( vector<polyhedron*>::iterator horizontal_position = statistic[0].begin();horizontal_position<statistic[0].end();horizontal_position++)522 for(list<polyhedron*>::iterator horizontal_position = statistic.begin()->begin();horizontal_position!=statistic.begin()->end();horizontal_position++) 522 523 { 523 524 vertex* current_vertex = (vertex*)(*horizontal_position); … … 538 539 current_vertex->totally_neutral = true; 539 540 540 current_vertex-> multiplicity++;541 current_vertex->raise_multiplicity(); 541 542 } 542 543 } … … 560 561 if(should_add) 561 562 { 562 for(vector<vector<polyhedron*>>::iterator vert_ref = for_splitting.begin();vert_ref<for_splitting.end();vert_ref++) 563 { 564 int original_size = (*vert_ref).size(); 565 566 for(int split_counter = 0;split_counter<original_size;split_counter++) 563 for(vector<list<polyhedron*>>::iterator vert_ref = for_splitting.begin();vert_ref<for_splitting.end();vert_ref++) 564 { 565 566 for(list<polyhedron*>::reverse_iterator split_ref = vert_ref->rbegin();split_ref != vert_ref->rend();split_ref++) 567 567 { 568 polyhedron* current_polyhedron = (*vert_ref)[original_size-1-split_counter];569 570 568 polyhedron* new_totally_neutral_child; 569 570 polyhedron* current_polyhedron = (*split_ref); 571 571 572 572 if(vert_ref == for_splitting.begin()) 573 573 { 574 vec coordinates1 = ((vertex*) current_polyhedron->children[0])->get_coordinates();575 vec coordinates2 = ((vertex*) current_polyhedron->children[1])->get_coordinates();574 vec coordinates1 = ((vertex*)(*(current_polyhedron->children.begin())))->get_coordinates(); 575 vec coordinates2 = ((vertex*)(*(current_polyhedron->children.begin()++)))->get_coordinates(); 576 576 coordinates2.ins(0,-1.0); 577 577 … … 646 646 // As a statistic, we have to create a vector of vectors of polyhedron pointers. It will then represent the Hasse 647 647 // diagram. First we create a vector of polyhedrons.. 648 vector<polyhedron*> origin_vec;648 list<polyhedron*> origin_vec; 649 649 650 650 // ..we fill it with the origin.. … … 684 684 vector<vector<polyhedron*>> new_statistic2; 685 685 686 // Copy the statistic by rows 686 687 // Copy the statistic by rows 687 688 for(int j=0;j<statistic.size();j++) 688 689 { 690 691 689 692 // an element counter 690 693 int element_number = 0; … … 697 700 698 701 // for each polyhedron in the given row 699 for( vector<polyhedron*>::iterator horiz_ref = statistic[j].begin();horiz_ref<statistic[j].end();horiz_ref++)702 for(list<polyhedron*>::iterator horiz_ref = (statistic.begin()+j)->begin();horiz_ref!=(statistic.begin()+j)->end();horiz_ref++) 700 703 { 701 704 // Append an extra zero coordinate to each of the vertices for the new dimension 702 // If j==0=> we loop through vertices705 // If vert_ref is at the first index => we loop through vertices 703 706 if(j == 0) 704 707 { … … 706 709 ((vertex*) (*horiz_ref))->push_coordinate(0); 707 710 } 711 /* 712 else 713 { 714 ((toprow*) (*horiz_ref))->condition.ins(0,0); 715 }*/ 708 716 709 717 // if it has parents … … 713 721 // This information will later be used for copying the whole Hasse diagram with each of the 714 722 // relations contained within. 715 for( vector<polyhedron*>::iterator parent_ref = (*horiz_ref)->parents.begin();parent_ref <(*horiz_ref)->parents.end();parent_ref++)723 for(list<polyhedron*>::iterator parent_ref = (*horiz_ref)->parents.begin();parent_ref != (*horiz_ref)->parents.end();parent_ref++) 716 724 { 717 725 (*parent_ref)->kids_rel_addresses.push_back(element_number); … … 728 736 // this condition will be a vector of zeros. There are two vectors, because we need two copies of 729 737 // the original Hasse diagram. 730 vec vec1( i+2);738 vec vec1(number_of_parameters+1); 731 739 vec1.zeros(); 732 740 733 vec vec2( i+2);741 vec vec2(number_of_parameters+1); 734 742 vec2.zeros(); 735 743 736 744 // We create a new toprow with the previously specified condition. 737 toprow *current_copy1 = new toprow(vec1);738 toprow *current_copy2 = new toprow(vec2);745 toprow* current_copy1 = new toprow(vec1); 746 toprow* current_copy2 = new toprow(vec2); 739 747 740 748 // The vertices of the copies will be inherited, because there will be a parent/child relation 741 749 // between each polyhedron and its offspring (comming from the copy) and a parent has all the 742 750 // vertices of its child plus more. 743 for( vector<vertex*>::iterator vert_ref = (*horiz_ref)->vertices.begin();vert_ref<(*horiz_ref)->vertices.end();vert_ref++)744 { 745 current_copy1->vertices.push_back(*vert _ref);746 current_copy2->vertices.push_back(*vert _ref);751 for(list<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin();vertex_ref!=(*horiz_ref)->vertices.end();vertex_ref++) 752 { 753 current_copy1->vertices.push_back(*vertex_ref); 754 current_copy2->vertices.push_back(*vertex_ref); 747 755 } 748 756 … … 762 770 if(!(*horiz_ref)->kids_rel_addresses.empty()) 763 771 { 764 for( vector<int>::iterator kid_ref = (*horiz_ref)->kids_rel_addresses.begin();kid_ref<(*horiz_ref)->kids_rel_addresses.end();kid_ref++)772 for(list<int>::iterator kid_ref = (*horiz_ref)->kids_rel_addresses.begin();kid_ref!=(*horiz_ref)->kids_rel_addresses.end();kid_ref++) 765 773 { 766 774 // find the child and save the relation to the parent … … 808 816 element_number++; 809 817 810 } 811 } 812 813 statistic[0].push_back(new_point1); 814 statistic[0].push_back(new_point2); 818 } 819 820 } 821 822 statistic.begin()->push_back(new_point1); 823 statistic.begin()->push_back(new_point2); 815 824 816 825 // Merge the new statistics into the old one. This will either be the final statistic or we will … … 820 829 if(j+1==statistic.size()) 821 830 { 822 vector<polyhedron*> support;831 list<polyhedron*> support; 823 832 statistic.push_back(support); 824 833 } 825 834 826 statistic[j+1].insert(statistic[j+1].end(),new_statistic1[j].begin(),new_statistic1[j].end()); 827 statistic[j+1].insert(statistic[j+1].end(),new_statistic2[j].begin(),new_statistic2[j].end()); 828 } 835 (statistic.begin()+j+1)->insert((statistic.begin()+j+1)->end(),new_statistic1[j].begin(),new_statistic1[j].end()); 836 (statistic.begin()+j+1)->insert((statistic.begin()+j+1)->end(),new_statistic2[j].begin(),new_statistic2[j].end()); 837 } 838 839 840 } 841 842 vector<list<toprow*>> toprow_statistic; 843 int line_count = 0; 844 845 for(vector<list<polyhedron*>>::iterator polyhedron_ref = ++statistic.begin(); polyhedron_ref!=statistic.end();polyhedron_ref++) 846 { 847 list<toprow*> support_list; 848 toprow_statistic.push_back(support_list); 849 850 for(list<polyhedron*>::iterator polyhedron_ref2 = polyhedron_ref->begin(); polyhedron_ref2 != polyhedron_ref->end(); polyhedron_ref2++) 851 { 852 toprow* support_top = (toprow*)(*polyhedron_ref2); 853 854 toprow_statistic[line_count].push_back(support_top); 855 } 856 857 line_count++; 829 858 } 830 859 }