Changeset 1362 for applications

Show
Ignore:
Timestamp:
05/09/11 19:07:15 (13 years ago)
Author:
sindj
Message:

Pridani soft apriorna, boj s integraly. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1361 r1362  
    111111                        if(has_constant) 
    112112                        {                                
    113                                 V0  = 0.0001 * eye(ar_components.size()+2); 
    114                                 //V0(0,0) = 0.1; 
     113                                V0  = 0.01 * eye(ar_components.size()+2); 
     114                                V0(0,0) = 1; 
    115115                                my_arx->set_constant(true);      
    116116                                 
     
    119119                        { 
    120120                                 
    121                                 V0  = 0.0001 * eye(ar_components.size()+1); 
    122                                 //V0(0,0) = 0.1; 
     121                                V0  = 0.01 * eye(ar_components.size()+1); 
     122                                V0(0,0) = 1; 
    123123                                my_arx->set_constant(false);                             
    124124                                 
  • applications/robust/robustlib.cpp

    r1357 r1362  
    9696        { 
    9797                // cout << ((toprow*)this)->condition << endl;           
    98  
    99                 int condition_order = ((toprow*)this)->condition_order-2; // -2 by bylo, pokud chceme uniformni apriorno 
    100  
    101                 int sigma_order = condition_order-my_emlig->number_of_parameters; 
     98                int sigma_order = ((toprow*)this)->condition_order-simplex->vertices.size()-1; 
    10299 
    103100                // cout << "C:" << condition_order << "  N:" << my_emlig->number_of_parameters << "  C+N:" << condition_order-my_emlig->number_of_parameters << endl; 
     
    147144 
    148145                                base_vertex = (*base_ref); 
    149  
    150                          
    151                                 // cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl; 
     146                         
     147                                //cout << "Base coords: " << base_vertex->get_coordinates() << endl; 
     148                                //cout << "Condition: " << as_toprow->condition_sum << endl; 
     149                                //pause(10); 
    152150 
    153151                                a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition_sum[0]; 
     
    340338                else 
    341339                { 
     340                        cout << "Improper probability density." << endl; 
    342341                        return 0.0; 
    343342                } 
  • applications/robust/robustlib.h

    r1361 r1362  
    2222using namespace itpp; 
    2323 
    24 const double max_range = 20;//numeric_limits<double>::max()/10e-10; 
     24const double max_range = 5;//numeric_limits<double>::max()/10e-10; 
    2525 
    2626/// An enumeration of possible actions performed on the polyhedrons. We can merge them or split them. 
     
    740740        int condition_order; 
    741741 
     742        double last_log_nc; 
     743 
    742744         
    743745 
     
    826828                                        if(is_last) 
    827829                                        {                                                
    828                                                 if(parent_state == 1) 
    829                                                 { 
    830                                                         ((toprow*)current_parent)->condition_sum-=toremove->value;                                                       
    831                                                 } 
    832  
    833                                                 if(parent_state == -1) 
    834                                                 { 
    835                                                         ((toprow*)current_parent)->condition_sum+=toremove->value;                                                       
     830                                                if(level == number_of_parameters-1) 
     831                                                { 
     832                                                        if(parent_state == 1) 
     833                                                        { 
     834                                                                ((toprow*)current_parent)->condition_sum-=toremove->value;                                                       
     835                                                        } 
     836 
     837                                                        if(parent_state == -1) 
     838                                                        { 
     839                                                                ((toprow*)current_parent)->condition_sum+=toremove->value;                                                       
     840                                                        } 
    836841                                                } 
    837842 
     
    964969                                                                current_parent->set_state(-1, SPLIT); 
    965970 
    966                                                                 ((toprow*)current_parent)->condition_sum-=toadd->value; 
     971                                                                if(level == number_of_parameters-1) 
     972                                                                { 
     973                                                                        ((toprow*)current_parent)->condition_sum-=toadd->value; 
     974                                                                } 
    967975                                                                         
    968976                                                        } 
     
    971979                                                                current_parent->set_state(1, SPLIT); 
    972980 
    973                                                                 ((toprow*)current_parent)->condition_sum+=toadd->value;                                                                  
     981                                                                if(level == number_of_parameters-1) 
     982                                                                { 
     983                                                                        ((toprow*)current_parent)->condition_sum+=toadd->value;                                                                  
     984                                                                } 
    974985                                                        } 
    975986                                                        else 
     
    10441055        double log_nc; 
    10451056 
     1057         
     1058 
    10461059        vector<multiset<my_ivec>> correction_factors; 
    10471060 
     
    10501063        /// A default constructor creates an emlig with predefined statistic representing only the range of the given 
    10511064        /// parametric space, where the number of parameters of the needed model is given as a parameter to the constructor. 
    1052         emlig(int number_of_parameters) 
     1065        emlig(int number_of_parameters, bool is_proper, double soft_prior_parameter) 
    10531066        {        
    10541067                this->number_of_parameters = number_of_parameters; 
    10551068 
    1056                 create_statistic(number_of_parameters); 
    1057  
    1058                 min_ll = numeric_limits<double>::max(); 
    1059  
    1060                 condition_order = 0; 
     1069                condition_order = number_of_parameters+2; 
     1070 
     1071                if(is_proper) 
     1072                        condition_order++; 
     1073                 
     1074                create_statistic(number_of_parameters, soft_prior_parameter); 
     1075 
     1076                //step_me(10); 
     1077 
     1078                min_ll = numeric_limits<double>::max();          
     1079 
     1080                if(is_proper) 
     1081                { 
     1082                        double normalization_factor = 0; 
     1083                        int counter = 0; 
     1084                        for(polyhedron* top_ref = statistic.rows[number_of_parameters];top_ref!=statistic.get_end();top_ref=top_ref->next_poly) 
     1085                        { 
     1086                                counter++; 
     1087                                toprow* cur_toprow = (toprow*)top_ref; 
     1088                                 
     1089                                set<simplex*>::iterator cur_simplex = cur_toprow->triangulation.begin(); 
     1090                                normalization_factor += cur_toprow->integrate_simplex(*cur_simplex,'X'); 
     1091                        } 
     1092 
     1093                        log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2); 
     1094 
     1095                        /* 
     1096                        cout << "part1: " << log(normalization_factor) << endl; 
     1097                        cout << "part2: " << logfact(condition_order-number_of_parameters-2) << endl; 
     1098                        pause(1); 
     1099                        */ 
     1100                } 
     1101 
    10611102        } 
    10621103 
     
    10851126                        { 
    10861127                                 
    1087                                 /* 
     1128                                 
    10881129                                if(i==statistic.size()-1) 
    10891130                                { 
    10901131                                        cout << ((toprow*)horiz_ref)->condition_sum << "   " << ((toprow*)horiz_ref)->probability << endl; 
     1132                                        cout << "Condition: " << ((toprow*)horiz_ref)->condition_sum << endl; 
    10911133                                        cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; 
    10921134                                } 
    1093                                 */ 
     1135                                 
    10941136 
    10951137                                // cout << "Stepped." << endl; 
     
    12121254        void add_and_remove_condition(vec toadd, vec toremove) 
    12131255        { 
     1256                 
    12141257                //step_me(0); 
    12151258                normalization_factor = 0; 
     
    17171760 
    17181761                                        // cout << ((toprow*)current_polyhedron)->condition << endl << toadd << endl; 
    1719  
    1720                                         toprow* positive_poly = new toprow(((toprow*)current_polyhedron)->condition_sum+toadd, ((toprow*)current_polyhedron)->condition_order+1); 
    1721                                         toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition_sum-toadd, ((toprow*)current_polyhedron)->condition_order+1); 
     1762                                        vec cur_pos_condition = ((toprow*)current_polyhedron)->condition_sum; 
     1763                                        vec cur_neg_condition = ((toprow*)current_polyhedron)->condition_sum; 
     1764                                         
     1765                                        if(k == number_of_parameters) 
     1766                                        { 
     1767                                                cur_pos_condition = cur_pos_condition + toadd; 
     1768                                                cur_neg_condition = cur_neg_condition - toadd; 
     1769                                        } 
     1770 
     1771                                        toprow* positive_poly = new toprow(cur_pos_condition, ((toprow*)current_polyhedron)->condition_order+1); 
     1772                                        toprow* negative_poly = new toprow(cur_neg_condition, ((toprow*)current_polyhedron)->condition_order+1); 
    17221773 
    17231774                                        positive_poly->my_emlig = this; 
     
    18351886                log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2); 
    18361887 
     1888                 
     1889                cout << "part1: " << log(normalization_factor) << endl; 
     1890                cout << "part2: " << logfact(condition_order-number_of_parameters-2) << endl; 
     1891                pause(1); 
     1892                 
     1893 
    18371894                /* 
    18381895                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) 
     
    18421899                */ 
    18431900 
    1844                 step_me(101); 
     1901                // step_me(101); 
    18451902 
    18461903        } 
     
    24032460 
    24042461        /// A method for creating plain default statistic representing only the range of the parameter space. 
    2405     void create_statistic(int number_of_parameters) 
     2462    void create_statistic(int number_of_parameters, double soft_prior_parameter) 
    24062463        { 
    24072464                /* 
     
    24482505                        // of newly added parameter. Therefore they will have all coordinates except the last one zero. We get the  
    24492506                        // right amount of zero cooridnates by reading them from the origin 
    2450                         vec origin_coord = origin->get_coordinates();                                            
     2507                        vec origin_coord = origin->get_coordinates();    
     2508 
     2509                         
    24512510 
    24522511                        // And we incorporate the nonzero coordinates into the new cooordinate vectors 
     
    25342593                                        // this condition will be a vector of zeros. There are two vectors, because we need two copies of  
    25352594                                        // the original Hasse diagram. 
    2536                                         vec vec1(number_of_parameters+1); 
    2537                                         vec1.zeros(); 
    2538  
    2539                                         vec vec2(number_of_parameters+1); 
    2540                                         vec2.zeros(); 
     2595                                        vec vec1; 
     2596                                        vec vec2; 
     2597                                        if(!horiz_ref->kids_rel_addresses.empty()) 
     2598                                        {                                        
     2599                                                vec1 = ((toprow*)horiz_ref)->condition_sum; 
     2600                                                vec1.ins(vec1.size(),-soft_prior_parameter); 
     2601 
     2602                                                vec2 = ((toprow*)horiz_ref)->condition_sum; 
     2603                                                vec2.ins(vec2.size(),soft_prior_parameter); 
     2604                                        } 
     2605                                        else 
     2606                                        {                                                
     2607                                                vec1.ins(0,-soft_prior_parameter); 
     2608                                                vec2.ins(0,soft_prior_parameter); 
     2609 
     2610                                                vec1.ins(0,-1); 
     2611                                                vec2.ins(0,-1); 
     2612                                        } 
     2613                                         
     2614                                        cout << vec1 << endl; 
     2615                                        cout << vec2 << endl; 
     2616 
    25412617 
    25422618                                        // We create a new toprow with the previously specified condition. 
    2543                                         toprow* current_copy1 = new toprow(vec1, 0); 
    2544                                         toprow* current_copy2 = new toprow(vec2, 0); 
     2619                                        toprow* current_copy1 = new toprow(vec1, this->condition_order); 
     2620                                        toprow* current_copy2 = new toprow(vec2, this->condition_order); 
    25452621 
    25462622                                        current_copy1->my_emlig = this; 
     
    27152791                this->has_constant = has_constant; 
    27162792                 
    2717                 posterior = new emlig(number_of_parameters); 
     2793                posterior = new emlig(number_of_parameters,true,0.001); 
    27182794 
    27192795                this->window_size = window_size;