Changeset 1208 for applications/robust

Show
Ignore:
Timestamp:
10/03/10 15:26:26 (14 years ago)
Author:
sindj
Message:

Dodelavky mergovani a splitovani - zatim nedokonceno. JS

Location:
applications/robust
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1186 r1208  
    88 
    99#include "robustlib.h" 
     10using namespace itpp; 
    1011 
    1112//using namespace bdm; 
     
    1314int main ( int argc, char* argv[] ) { 
    1415         
    15         emlig* emlig1 = new emlig(10); 
     16        emlig* emlig1 = new emlig(3); 
     17 
     18        vec condition = "3.0 -5.0 3.0 2.0";      
     19 
     20        emlig1->add_condition(condition); 
    1621 
    1722        return 0; 
  • applications/robust/robustlib.h

    r1207 r1208  
    1818 
    1919const double max_range = numeric_limits<double>::max()/10e-5; 
     20 
     21enum actions {MERGE, SPLIT}; 
    2022 
    2123class polyhedron; 
     
    5658        vector<polyhedron*> neutralchildren; 
    5759 
     60        bool totally_neutral; 
     61 
    5862        vector<polyhedron*> mergechildren; 
    5963 
     
    7680 
    7781                message_counter = 0; 
     82 
     83                totally_neutral = NULL; 
    7884        } 
    7985         
     
    101107                return false; 
    102108        } 
     109 
     110         
    103111 
    104112        void set_state(double state_indicator, actions action) 
     
    143151        vec coordinates;         
    144152 
    145         enum actions {MERGE, SPLIT}; 
     153         
    146154 
    147155public: 
     
    207215                multiplicity = 1; 
    208216        } 
    209 } 
     217}; 
    210218 
    211219 
     
    236244                        do 
    237245                        { 
    238                                 product = (*vertex_ref)->coordinates*condition; 
    239                         } 
    240                         while(product == 0) 
     246                                product = (*vertex_ref)->get_coordinates()*condition; 
     247                        } 
     248                        while(product == 0); 
    241249 
    242250                        if((product>0 && should_be_added)||(product<0 && !should_be_added)) 
     
    319327                                        } 
    320328 
    321                                         if(shouldsplit) 
     329                                         
     330                                } 
     331 
     332                                if(shouldsplit) 
    322333                                        { 
    323334                                                switch(sender->get_state(SPLIT)) 
     
    328339                                                case 0: 
    329340                                                        current_parent->neutralchildren.push_back(sender); 
     341 
     342                                                        if(current_parent->totally_neutral == NULL) 
     343                                                        { 
     344                                                                current_parent->totally_neutral = sender->totally_neutral; 
     345                                                        } 
     346                                                        else 
     347                                                        { 
     348                                                                current_parent->totally_neutral = current_parent->totally_neutral && sender->totally_neutral; 
     349                                                        } 
     350                                                         
    330351                                                break; 
    331352                                                case -1: 
     
    336357                                                if(is_last) 
    337358                                                { 
    338                                                         if(current_parent->negativechildren.size()>0)  
     359                                                        if((current_parent->negativechildren.size()>0&&current_parent->positivechildren.size()>0)|| 
     360                                                                                                                (current_parent->neutralchildren.size()>0&&current_parent->totally_neutral==false)) 
    339361                                                        {                                                                
    340                                                                 if(current_parent->positivechildren.size()>0) 
    341                                                                 { 
     362                                                                 
    342363                                                                        for_splitting[level+1].push_back(current_parent); 
    343364                                                                 
    344365                                                                        current_parent->set_state(0, SPLIT); 
    345                                                                 } 
    346                                                                 else  
    347                                                                 { 
    348                                                                         current_parent->set_state(-1, SPLIT); 
    349  
    350                                                                         current_parent->negativechildren.clear(); 
    351                                                                         current_parent->neutralchildren.clear(); 
    352                                                                 } 
     366                                                        } 
     367                                                        else if(current_parent->negativechildren.size()>0) 
     368                                                        { 
     369                                                                current_parent->set_state(-1, SPLIT); 
     370 
     371                                                                current_parent->negativechildren.clear(); 
     372                                                                current_parent->neutralchildren.clear(); 
     373                                                                 
    353374                                                        } 
    354375                                                        else if(current_parent->positivechildren.size()>0) 
     
    372393                                                send_state_message(current_parent,shouldsplit,shouldmerge,level+1); 
    373394                                        } 
    374                                 }                        
    375395                         
    376396                        } 
     
    404424        } 
    405425 
    406         void add_and_remove_condition(vec toremove, vec toadd) 
    407         { 
     426        void add_condition(vec toadd) 
     427        { 
     428                vec null_vector = ""; 
     429 
     430                add_and_remove_condition(toadd, null_vector); 
     431        } 
     432 
     433        void remove_condition(vec toremove) 
     434        { 
     435                vec null_vector = ""; 
     436 
     437                add_and_remove_condition(null_vector, toremove); 
     438         
     439        } 
     440 
     441        void add_and_remove_condition(vec toadd, vec toremove) 
     442        { 
     443                bool should_remove = (toremove.size() != 0); 
     444                bool should_add    = (toadd.size() != 0); 
     445 
    408446                vector<condition*>::iterator toremove_ref = conditions.end(); 
    409447                bool condition_should_be_added = false; 
     
    411449                for(vector<condition*>::iterator ref = conditions.begin();ref<conditions.end();ref++) 
    412450                { 
    413                         if(toremove != NULL) 
     451                        if(should_remove) 
    414452                        { 
    415453                                if((*ref)->value == toremove) 
    416454                                { 
    417                                         if(multiplicity>1) 
    418                                         { 
    419                                                 multiplicity--; 
     455                                        if((*ref)->multiplicity>1) 
     456                                        { 
     457                                                (*ref)->multiplicity--; 
    420458 
    421459                                                alter_toprow_conditions(toremove,false); 
    422460 
    423                                                 toremove = NULL; 
     461                                                should_remove = false; 
    424462                                        } 
    425463                                        else 
     
    430468                        } 
    431469 
    432                         if(toadd != NULL) 
    433                         { 
    434                                 if((*iterator)->value == toadd) 
     470                        if(should_add) 
     471                        { 
     472                                if((*ref)->value == toadd) 
    435473                                { 
    436                                         (*iterator)->multiplicity++; 
     474                                        (*ref)->multiplicity++; 
    437475 
    438476                                        alter_toprow_conditions(toadd,true); 
    439477 
    440                                         toadd = NULL; 
     478                                        should_add = false; 
    441479                                } 
    442480                                else 
     
    461499                for(vector<polyhedron*>::iterator horizontal_position = statistic[0].begin();horizontal_position<statistic[0].end();horizontal_position++) 
    462500                {                
    463                         vertex* current_vertex = (vertex*)horizontal_position; 
     501                        vertex* current_vertex = (vertex*)(*horizontal_position); 
    464502                         
    465                         if(toadd != NULL) 
    466                         { 
    467                                 current_vertex->set_state(toadd*current_vertex->coordinates,SPLIT); 
    468                         } 
     503                        if(should_add||should_remove) 
     504                        { 
     505                                vec appended_vec = current_vertex->get_coordinates(); 
     506                                appended_vec.ins(0,1.0); 
     507 
     508                                if(should_add) 
     509                                { 
     510                                        current_vertex->set_state(toadd*appended_vec,SPLIT); 
     511                                } 
    469512                         
    470                         if(toremove != NULL) 
    471                         { 
    472                                 current_vertex->set_state(toremove*current_vertex->coordinates,MERGE); 
     513                                if(should_remove) 
     514                                { 
     515                                        current_vertex->set_state(toremove*current_vertex->get_coordinates(),MERGE); 
     516                                } 
    473517 
    474518                                if(current_vertex->get_state(MERGE) == 0) 
     
    478522                        } 
    479523 
    480                         send_state_message(current_vertex, toadd != NULL, toremove != NULL, 0); 
    481  
    482                          
    483                 } 
     524                        send_state_message(current_vertex, should_add, should_remove, 0);                        
     525                } 
     526 
     527                for(vector<vector<polyhedron*>>::iterator vert_ref = for_splitting.begin();vert_ref<for_splitting.end();vert_ref++) 
     528                { 
     529                        int original_size = (*vert_ref).size(); 
     530 
     531                        for(int split_counter = 0;split_counter<original_size;split_counter++) 
     532                        { 
     533                                polyhedron* current_polyhedron = (*vert_ref)[original_size-1-split_counter]; 
     534 
     535 
     536                        } 
     537                } 
     538 
     539 
    484540        } 
    485541 
     
    690746}; 
    691747 
     748/* 
     749 
    692750//! Robust Bayesian AR model for Multicriteria-Laplace-Inverse-Gamma density 
    693751class RARX : public BM 
     
    707765        } 
    708766 
    709 }; 
     767};*/ 
     768 
    710769 
    711770