Changeset 1268 for applications/robust

Show
Ignore:
Timestamp:
01/05/11 18:01:55 (13 years ago)
Author:
sindj
Message:

Dodelani vypoctu pri degenerovanych podminkach. Zda se, ze docela funguje, ale neni zohlednena pocatecni divergence integralu aposteriorna pres parametry. Zbyva odladit. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1267 r1268  
    1313using namespace bdm; 
    1414 
     15const int emlig_size = 3; 
     16 
    1517int main ( int argc, char* argv[] ) { 
    1618         
    17         emlig* emlig1 = new emlig(4); 
    1819 
     20        emlig* emlig1 = new emlig(emlig_size); 
     21         
    1922        /* 
    2023        emlig1->set_correction_factors(4); 
     
    2427                for(set<my_ivec>::iterator vec_ref = emlig1->correction_factors[j].begin();vec_ref!=emlig1->correction_factors[j].end();vec_ref++) 
    2528                { 
     29                        cout << j << "    "; 
     30                         
    2631                        for(int i=0;i<(*vec_ref).size();i++) 
    2732                        { 
     
    3136                        cout << endl; 
    3237                } 
    33         } 
    34         */ 
     38        }*/ 
     39         
    3540 
    3641        //emlig1->step_me(0); 
     
    4045                cout << "Step:" << i << endl; 
    4146 
    42                 double condition[4];             
     47                double condition[emlig_size+1];          
    4348 
    44                 condition[0] = rand()/1000.0; 
    45                 condition[1] = rand()/1000.0; 
    46                 condition[2] = rand()/1000.0; 
    47                 condition[3] = rand()/1000.0; 
    48                 /*condition[4] = rand()/1000.0; 
    49                 condition[5] = rand()/1000.0; 
    50                 condition[6] = rand()/1000.0; 
    51                 condition[7] = rand()/1000.0; 
    52                 condition[8] = rand()/1000.0;*/ 
    53                  
     49                for(int k = 0;k<=emlig_size;k++) 
     50                { 
     51                        condition[k] = rand()/1000.0;            
     52                } 
     53                         
    5454 
    55                 vec* condition_vec = new vec(condition,4); 
     55                vec* condition_vec = new vec(condition,emlig_size+1); 
    5656                emlig1->add_condition(*condition_vec); 
     57         
    5758 
    5859                emlig1->step_me(i); 
  • applications/robust/robustlib.cpp

    r1262 r1268  
    2020                                        if(should_integrate) 
    2121                                        { 
     22                                                emlig* current_emlig; 
     23 
     24                                                if(this->my_emlig!=NULL) 
     25                                                { 
     26                                                        current_emlig = this->my_emlig; 
     27                                                } 
     28                                                else 
     29                                                { 
     30                                                        throw exception("The statistic of the polyhedron you are trying to integrate over doesn't belong to any emlig!"); 
     31                                                }                                                
     32 
    2233                                                toprow* as_toprow = (toprow*)this; 
    2334 
     
    5364 
    5465                                                double int_value = 0; 
     66                                                double det_jacobian = det(jacobian); 
    5567                                                for(map<double,int>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++) 
    5668                                                { 
    57                                                         int fac_order = ((toprow*)this)->condition_order-as.size()-1; 
     69                                                        int condition_order = ((toprow*)this)->condition_order-1; 
    5870 
    59                                                         double fac_value = 1; 
     71                                                        double multiplier = det_jacobian; 
    6072                                                        if(a_0!=(*as_ref).first) 
    61                                                         { 
    62                                                                 //fac_value = ((double)tgamma(fac_order)*det(jacobian))/(*as_ref).first/pow((*as_ref).first-a_0,fac_order);  
    63                                                                  
    64                                                                 fac_value /= (*as_ref).first; 
     73                                                        {                                                                
     74                                                                int as1_order = (*as_ref).second; 
    6575 
     76                                                                current_emlig->set_correction_factors(as1_order); 
     77 
     78                                                                vector<double> factors; 
     79                                                                int number_of_factors = 0;                                                               
    6680                                                                for(map<double,int>::iterator as2_ref = as.begin();as2_ref!=as.end();as2_ref++) 
    6781                                                                { 
     82                                                                         
    6883                                                                        if(as2_ref!=as_ref) 
     84                                                                        {                                                                                
     85                                                                                for(int k = 0;k<(*as2_ref).second;k++) 
     86                                                                                { 
     87                                                                                        factors.push_back((*as_ref).first-(*as2_ref).first); 
     88                                                                                } 
     89 
     90                                                                                multiplier        /= pow((*as_ref).first-(*as2_ref).first,(*as2_ref).second); 
     91                                                                                number_of_factors += (*as2_ref).second; 
     92                                                                        } 
     93                                                                        else 
    6994                                                                        { 
    70                                                                                 double current_factor = (*as_ref).first-(*as2_ref).first; 
     95                                                                                factors.push_back((*as_ref).first); 
    7196 
    72                                                                                 fac_value /= current_factor; 
     97                                                                                multiplier        /= (*as_ref).first; 
     98                                                                                number_of_factors += 1; 
     99                                                                        }                                                                        
     100                                                                } 
    73101 
    74                                                                                                                                                                  
    75                                                                         } 
    76                                                                 } 
     102                                                                double bracket = fact(condition_order-1-number_of_factors)/fact(as1_order-1)/*/pow((*as_ref).first-a_0,condition_order-1-number_of_factors)*/; 
     103                                                                for(int k = 0;k < as1_order-1;k++) 
     104                                                                { 
     105                                                                        double bracket_factor = pow((double)-1,k+1)*fact(condition_order-2-number_of_factors-k)/fact(as1_order-2-k)/pow((*as_ref).first-a_0,condition_order-2-number_of_factors-k); 
     106                                                                         
     107                                                                        for(set<my_ivec>::iterator combi_ref = this->my_emlig->correction_factors[k].begin();combi_ref!=this->my_emlig->correction_factors[k].end();combi_ref++) 
     108                                                                        { 
     109                                                                                double bracket_combination = 1; 
     110                                                                                for(int j = 0;j<(*combi_ref).size();j++) 
     111                                                                                { 
     112                                                                                        bracket_combination /= factors[(*combi_ref)[j]]; 
     113                                                                                } 
     114 
     115                                                                                bracket+=bracket_factor*bracket_combination;                                                                     
     116                                                                        }                                                                        
     117                                                                }                                                                
     118 
     119                                                                int_value += multiplier*bracket;         
     120 
    77121                                                        } 
    78122                                                        else 
    79123                                                        { 
    80124                                                                throw new exception("Should this happen? a_i=a_0 in the formula for integrating over a simplex! I think it can happen with 0 probability(when phi*2*v_0=phi*v_i)"); 
    81                                                         } 
    82  
    83                                                          
    84                                                         int_value += fac_value;                                                  
     125                                                        }                                                
     126                                                                                                         
    85127                                                } 
    86128 
  • applications/robust/robustlib.h

    r1267 r1268  
    1212#include <vector> 
    1313#include <list> 
    14 #include <map> 
    1514#include <set> 
    1615#include <algorithm> 
    17 #include <string> 
    1816         
    1917using namespace bdm; 
     
    2119using namespace itpp; 
    2220 
    23 const double max_range = 1000.0;//numeric_limits<double>::max()/10e-10; 
     21const double max_range = 99999999.0;//numeric_limits<double>::max()/10e-10; 
    2422 
    2523enum actions {MERGE, SPLIT}; 
     
    2725class polyhedron; 
    2826class vertex; 
    29 class toprow; 
    3027 
    3128/* 
     
    4340        } 
    4441};*/ 
     42 
     43class emlig; 
     44 
    4545 
    4646/// A class describing a single polyhedron of the split complex. From a collection of such classes a Hasse diagram 
     
    6060 
    6161public: 
     62        emlig* my_emlig; 
     63 
    6264        /// A list of polyhedrons parents within the Hasse diagram. 
    6365        list<polyhedron*> parents; 
     
    173175        } 
    174176 
     177         
    175178        void triangulate(bool should_integrate); 
    176          
    177179 
    178180         
     
    245247        toprow(vec condition, int condition_order) 
    246248        { 
    247                 this->condition       = condition; 
     249                this->condition = condition; 
    248250                this->condition_order = condition_order; 
    249         }        
     251        } 
    250252 
    251253}; 
    252  
    253254 
    254255class condition 
     
    268269 
    269270 
    270  
    271271class c_statistic 
    272272{ 
     
    274274        polyhedron* start_poly; 
    275275 
    276 public: 
     276public:  
     277 
    277278        vector<polyhedron*> rows; 
    278279 
     
    414415        } 
    415416}; 
    416  
    417417 
    418418class my_ivec : public ivec 
     
    557557 
    558558 
     559 
     560 
    559561//! Conditional(e) Multicriteria-Laplace-Inverse-Gamma distribution density 
    560562class emlig // : eEF 
    561563{ 
    562          
    563564 
    564565        /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result 
     
    573574 
    574575        double normalization_factor; 
    575  
    576          
    577576 
    578577        void alter_toprow_conditions(vec condition, bool should_be_added) 
     
    727726                                                        else 
    728727                                                        { 
    729                                                                 ((toprow*)current_parent)->condition_order++; 
    730  
    731728                                                                if(current_parent->negativechildren.size()>0) 
    732729                                                                { 
    733730                                                                        current_parent->set_state(-1, SPLIT); 
    734731 
    735                                                                         ((toprow*)current_parent)->condition-=toadd;                                                             
    736  
     732                                                                        ((toprow*)current_parent)->condition-=toadd; 
    737733                                                                } 
    738734                                                                else if(current_parent->positivechildren.size()>0) 
     
    740736                                                                        current_parent->set_state(1, SPLIT); 
    741737 
    742                                                                         ((toprow*)current_parent)->condition+=toadd;                                                                     
     738                                                                        ((toprow*)current_parent)->condition+=toadd; 
    743739                                                                } 
    744740                                                                else 
     
    790786        emlig(c_statistic statistic) 
    791787        { 
    792                 this->statistic = statistic; 
     788                this->statistic = statistic;             
    793789        } 
    794790 
     
    966962                                                vertex* neutral_vertex = new vertex(new_coordinates); 
    967963 
     964                                                neutral_vertex->my_emlig = this; 
     965 
    968966                                                new_totally_neutral_child = neutral_vertex; 
    969967                                        } 
     
    971969                                        { 
    972970                                                toprow* neutral_toprow = new toprow(); 
     971 
     972                                                neutral_toprow->my_emlig = this; 
    973973 
    974974                                                new_totally_neutral_child = neutral_toprow; 
     
    989989                                        toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition-toadd, ((toprow*)current_polyhedron)->condition_order+1); 
    990990 
     991                                        positive_poly->my_emlig = this; 
     992                                        negative_poly->my_emlig = this; 
     993 
    991994                                        for(list<polyhedron*>::iterator parent_ref = current_polyhedron->parents.begin();parent_ref!=current_polyhedron->parents.end();parent_ref++) 
    992995                                        { 
     
    10411044                                        negative_poly->vertices.insert(current_polyhedron->negativeneutralvertices.begin(),current_polyhedron->negativeneutralvertices.end()); 
    10421045                                        negative_poly->vertices.insert(new_totally_neutral_child->vertices.begin(),new_totally_neutral_child->vertices.end()); 
    1043  
     1046                                                                 
    10441047                                        new_totally_neutral_child->triangulate(false); 
    10451048 
    10461049                                        positive_poly->triangulate(k==for_splitting.size()-1); 
    10471050                                        negative_poly->triangulate(k==for_splitting.size()-1); 
    1048  
    1049                                         statistic.append_polyhedron(k-1, new_totally_neutral_child); 
     1051                                         
     1052                                        statistic.append_polyhedron(k-1, new_totally_neutral_child);                                     
    10501053                                         
    10511054                                        statistic.insert_polyhedron(k, positive_poly, current_polyhedron); 
     
    10611064                } 
    10621065 
    1063                 /* 
     1066                 
    10641067                vector<int> sizevector; 
    10651068                for(int s = 0;s<statistic.size();s++) 
    10661069                { 
    10671070                        sizevector.push_back(statistic.row_size(s)); 
    1068                 }*/ 
     1071                } 
    10691072 
    10701073                 
     
    11361139                // We create an origin - this point will have all the coordinates zero, but now it has an empty vector of coords. 
    11371140                vertex *origin = new vertex(origin_coord); 
     1141 
     1142                origin->my_emlig = this; 
    11381143                 
    11391144                /* 
     
    11491154                */ 
    11501155 
    1151                 statistic = *(new c_statistic()); 
    1152  
     1156                statistic = *(new c_statistic());                
     1157                 
    11531158                statistic.append_polyhedron(0, origin); 
    11541159 
     
    11691174                        // Now we create the points 
    11701175                        vertex* new_point1 = new vertex(origin_coord1); 
    1171                         vertex* new_point2 = new vertex(origin_coord2);                  
     1176                        vertex* new_point2 = new vertex(origin_coord2); 
     1177 
     1178                        new_point1->my_emlig = this; 
     1179                        new_point2->my_emlig = this; 
    11721180                         
    11731181                        //********************************************************************************************************* 
     
    12511259                                        // We create a new toprow with the previously specified condition. 
    12521260                                        toprow* current_copy1 = new toprow(vec1, 0); 
    1253                                         toprow* current_copy2 = new toprow(vec2, 0);                                     
     1261                                        toprow* current_copy2 = new toprow(vec2, 0); 
     1262 
     1263                                        current_copy1->my_emlig = this; 
     1264                                        current_copy2->my_emlig = this; 
    12541265 
    12551266                                        // The vertices of the copies will be inherited, because there will be a parent/child relation 
     
    13711382                                statistic.append_polyhedron(j+1,new_statistic1->rows[j],new_statistic1->row_ends[j]); 
    13721383                                statistic.append_polyhedron(j+1,new_statistic2->rows[j],new_statistic2->row_ends[j]); 
    1373                         } 
    1374  
    1375                  
     1384                        }                        
    13761385                } 
    13771386 
     
    14331442 
    14341443 
    1435  
    1436  
    1437  
    1438  
    1439  
    1440  
    14411444#endif //TRAGE_H