Changeset 1213 for applications/robust

Show
Ignore:
Timestamp:
10/08/10 18:39:39 (14 years ago)
Author:
sindj
Message:

Predelani vektoru na listy a doplneni drobnosti - nedokonceno. JS

Location:
applications/robust
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1208 r1213  
    1010using namespace itpp; 
    1111 
    12 //using namespace bdm; 
     12using namespace bdm; 
    1313 
    1414int main ( int argc, char* argv[] ) { 
  • applications/robust/robustlib.h

    r1212 r1213  
    1111#include <limits> 
    1212#include <vector> 
     13#include <list> 
    1314#include <algorithm> 
    1415         
     
    4142public: 
    4243        /// A list of polyhedrons parents within the Hasse diagram. 
    43         vector<polyhedron*> parents; 
     44        list<polyhedron*> parents; 
    4445 
    4546        /// A list of polyhedrons children withing the Hasse diagram. 
    46         vector<polyhedron*> children; 
     47        list<polyhedron*> children; 
    4748 
    4849        /// All the vertices of the given polyhedron 
    49         vector<vertex*> vertices; 
     50        list<vertex*> vertices; 
    5051 
    5152        /// 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; 
    5354 
    5455        /// 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; 
    5657 
    5758        /// 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; 
    6364 
    6465        bool totally_neutral; 
    6566 
    66         vector<polyhedron*> mergechildren; 
     67        list<polyhedron*> mergechildren; 
    6768 
    6869        polyhedron* positiveparent; 
     
    7374 
    7475        /// List of triangulation polyhedrons of the polyhedron given by their relative vertices.  
    75         vector<vector<vertex*>> triangulations; 
     76        list<list<vertex*>> triangulations; 
    7677 
    7778        /// A list of relative addresses serving for Hasse diagram construction. 
    78         vector<int> kids_rel_addresses; 
     79        list<int> kids_rel_addresses; 
    7980 
    8081        /// Default constructor 
     
    197198 
    198199        /// Default constructor 
    199         toprow(); 
     200        toprow(){}; 
    200201 
    201202        /// Constructor creating a toprow from the condition 
     
    228229        /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result 
    229230        /// 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; 
    233234                 
    234         vector<vector<polyhedron*>> for_merging; 
    235  
    236         vector<condition*> conditions; 
     235        vector<list<polyhedron*>> for_merging; 
     236 
     237        list<condition*> conditions; 
    237238 
    238239        double normalization_factor; 
     
    240241        void alter_toprow_conditions(vec condition, bool should_be_added) 
    241242        { 
    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++) 
    243244                { 
    244245                        double product = 0; 
    245246 
    246                         vector<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin(); 
     247                        list<vertex*>::iterator vertex_ref = (*horiz_ref)->vertices.begin(); 
    247248 
    248249                        do 
     
    267268        {                        
    268269 
    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); 
    271272                 
    272273                if(shouldsplit||shouldmerge) 
    273274                { 
    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++) 
    275276                        { 
    276277                                polyhedron* current_parent = *parent_iterator; 
     
    313314                                                if(parent_state > 0) 
    314315                                                { 
    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++) 
    316317                                                        { 
    317318                                                                (*merge_child)->positiveparent = current_parent; 
     
    321322                                                if(parent_state < 0) 
    322323                                                { 
    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++) 
    324325                                                        { 
    325326                                                                (*merge_child)->negativeparent = current_parent; 
     
    413414                                        if(is_last) 
    414415                                        { 
    415                                                 send_state_message(current_parent,shouldsplit,shouldmerge,level+1); 
     416                                                send_state_message(current_parent,toadd,toremove,level+1); 
    416417                                        } 
    417418                         
     
    429430                create_statistic(number_of_parameters); 
    430431 
    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; 
    435436 
    436437                        for_splitting.push_back(empty_split); 
     
    441442        /// A constructor for creating an emlig when the user wants to create the statistic by himself. The creation of a 
    442443        /// 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) 
    444445        { 
    445446                this->statistic = statistic; 
     
    466467                bool should_add    = (toadd.size() != 0); 
    467468 
    468                 vector<condition*>::iterator toremove_ref = conditions.end(); 
     469                list<condition*>::iterator toremove_ref = conditions.end(); 
    469470                bool condition_should_be_added = false; 
    470471 
    471                 for(vector<condition*>::iterator ref = conditions.begin();ref<conditions.end();ref++) 
     472                for(list<condition*>::iterator ref = conditions.begin();ref!=conditions.end();ref++) 
    472473                { 
    473474                        if(should_remove) 
     
    519520                 
    520521 
    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++) 
    522523                {                
    523524                        vertex* current_vertex = (vertex*)(*horizontal_position); 
     
    538539                                                current_vertex->totally_neutral = true; 
    539540 
    540                                                 current_vertex->multiplicity++; 
     541                                                current_vertex->raise_multiplicity(); 
    541542                                        }                                        
    542543                                } 
     
    560561                if(should_add) 
    561562                { 
    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++) 
    567567                                { 
    568                                         polyhedron* current_polyhedron = (*vert_ref)[original_size-1-split_counter]; 
    569  
    570568                                        polyhedron* new_totally_neutral_child; 
     569 
     570                                        polyhedron* current_polyhedron = (*split_ref); 
    571571                                         
    572572                                        if(vert_ref == for_splitting.begin()) 
    573573                                        { 
    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(); 
    576576                                                coordinates2.ins(0,-1.0); 
    577577                                                 
     
    646646                // As a statistic, we have to create a vector of vectors of polyhedron pointers. It will then represent the Hasse 
    647647                // diagram. First we create a vector of polyhedrons.. 
    648                 vector<polyhedron*> origin_vec; 
     648                list<polyhedron*> origin_vec; 
    649649 
    650650                // ..we fill it with the origin.. 
     
    684684                        vector<vector<polyhedron*>> new_statistic2; 
    685685 
    686                         // Copy the statistic by rows 
     686                         
     687                        // Copy the statistic by rows                    
    687688                        for(int j=0;j<statistic.size();j++) 
    688689                        { 
     690                                 
     691 
    689692                                // an element counter 
    690693                                int element_number = 0; 
     
    697700 
    698701                                // 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++) 
    700703                                {        
    701704                                        // Append an extra zero coordinate to each of the vertices for the new dimension 
    702                                         // If j==0 => we loop through vertices 
     705                                        // If vert_ref is at the first index => we loop through vertices 
    703706                                        if(j == 0) 
    704707                                        { 
     
    706709                                                ((vertex*) (*horiz_ref))->push_coordinate(0); 
    707710                                        } 
     711                                        /* 
     712                                        else 
     713                                        { 
     714                                                ((toprow*) (*horiz_ref))->condition.ins(0,0); 
     715                                        }*/ 
    708716 
    709717                                        // if it has parents 
     
    713721                                                // This information will later be used for copying the whole Hasse diagram with each of the 
    714722                                                // 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++) 
    716724                                                { 
    717725                                                        (*parent_ref)->kids_rel_addresses.push_back(element_number);                                                     
     
    728736                                        // this condition will be a vector of zeros. There are two vectors, because we need two copies of  
    729737                                        // the original Hasse diagram. 
    730                                         vec vec1(i+2); 
     738                                        vec vec1(number_of_parameters+1); 
    731739                                        vec1.zeros(); 
    732740 
    733                                         vec vec2(i+2); 
     741                                        vec vec2(number_of_parameters+1); 
    734742                                        vec2.zeros(); 
    735743 
    736744                                        // 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);                                        
    739747 
    740748                                        // The vertices of the copies will be inherited, because there will be a parent/child relation 
    741749                                        // between each polyhedron and its offspring (comming from the copy) and a parent has all the 
    742750                                        // 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);                                          
    747755                                        } 
    748756                                         
     
    762770                                        if(!(*horiz_ref)->kids_rel_addresses.empty()) 
    763771                                        { 
    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++) 
    765773                                                {        
    766774                                                        // find the child and save the relation to the parent 
     
    808816                                        element_number++; 
    809817                                         
    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); 
    815824 
    816825                        // Merge the new statistics into the old one. This will either be the final statistic or we will 
     
    820829                                if(j+1==statistic.size()) 
    821830                                { 
    822                                         vector<polyhedron*> support; 
     831                                        list<polyhedron*> support; 
    823832                                        statistic.push_back(support); 
    824833                                } 
    825834                                 
    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++; 
    829858                } 
    830859        }