Changeset 1272 for applications/robust

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

Dodelano pocitani, odstranena chyba se zapornymi pravdepodobnostmi. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1271 r1272  
    1414 
    1515const int emlig_size = 4; 
     16 
    1617 
    1718int main ( int argc, char* argv[] ) { 
     
    5152                for(int k = 0;k<=emlig_size;k++) 
    5253                { 
    53                         condition[k] = rand()/1000.0;            
     54                        condition[k] = (rand()-RAND_MAX/2)/1000.0;               
    5455                } 
    5556                         
     
    5859                emlig1->add_condition(*condition_vec); 
    5960 
     61                /* 
     62                for(polyhedron* toprow_ref = emlig1->statistic.rows[emlig_size]; toprow_ref != emlig1->statistic.end_poly; toprow_ref = toprow_ref->next_poly) 
     63                { 
     64                        cout << ((toprow*)toprow_ref)->probability << endl; 
     65                } 
     66                */ 
     67 
    6068                cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; 
    6169         
     70                /* 
    6271                if(i-emlig1->number_of_parameters >= 0) 
    6372                { 
    6473                        pause(30); 
    6574                } 
     75                */ 
    6676 
    6777                // emlig1->step_me(i); 
    6878                 
     79                /* 
    6980                vector<int> sizevector; 
    7081                for(int s = 0;s<=emlig1->number_of_parameters;s++) 
     
    7283                        sizevector.push_back(emlig1->statistic_rowsize(s)); 
    7384                } 
     85                */ 
    7486        } 
    7587 
  • applications/robust/robustlib.cpp

    r1271 r1272  
    5555                        vec cur_condition = as_toprow->condition.get(1,as_toprow->condition.size()-1); 
    5656 
     57                        // cout << as_toprow->condition << endl; 
     58 
    5759                        vertex* base_vertex = (*simplex.begin()); 
    5860 
     
    6163                        mat jacobian(dimension,dimension); 
    6264 
    63                         double a_0 = base_vertex->get_coordinates()*cur_condition+as_toprow->condition[0]; 
     65                        // cout << base_vertex->get_coordinates() << endl; 
     66 
     67                        double a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition[0]; 
    6468                        map<double,int> as; 
    6569 
     
    6973                                vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates(); 
    7074 
     75                                // cout << (*vert_ref)->get_coordinates() << endl; 
    7176                                // cout << relative_coords << endl; 
    7277 
     
    8085                                        (*returned.first).second++; 
    8186                                } 
     87                                /* 
    8288                                else 
    8389                                { 
    8490                                        cout << "a[" << row_count << "] = " << new_a << endl; 
    8591                                } 
     92                                */ 
     93                                 
    8694                                //as.ins(as.size(),new_a);                                                       
    8795                                 
     
    8997                        } 
    9098 
    91                         // cout << endl; 
     99                         
    92100 
    93101                        double int_value = 0; 
     
    95103                        // cout << jacobian << endl; 
    96104 
    97                         double det_jacobian = det(jacobian); 
     105                        double det_jacobian    = abs(det(jacobian)); 
     106                        double correction_term = det_jacobian;                   
    98107                        for(map<double,int>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++) 
    99108                        { 
    100109                                double multiplier = det_jacobian; 
     110                                 
    101111                                if(a_0!=(*as_ref).first) 
    102                                 {                                                                
     112                                { 
    103113                                        int as1_order = (*as_ref).second; 
    104  
     114                                         
     115                                        correction_term /= -pow((*as_ref).first,as1_order);                                      
     116                                         
    105117                                        current_emlig->set_correction_factors(as1_order); 
    106118 
     
    126138                                                        multiplier        /= (*as_ref).first; 
    127139                                                        number_of_factors += 1; 
    128                                                 }                                                                        
     140                                                } 
     141                                                 
    129142                                        }                                        
    130143 
    131                                         double bracket = fact(condition_order-number_of_factors)/fact(as1_order-1)/pow((*as_ref).first-a_0,condition_order-number_of_factors); 
     144                                        double bracket = fact(condition_order-number_of_factors)/fact(as1_order-1)/pow(a_0+(*as_ref).first,condition_order-number_of_factors+1); 
    132145                                        for(int k = 0;k < as1_order-1;k++) 
    133146                                        { 
    134                                                 double bracket_factor = pow((double)-1,k+1)*fact(condition_order-1-number_of_factors-k)/fact(as1_order-2-k)/pow((*as_ref).first-a_0,condition_order-1-number_of_factors-k); 
     147                                                double bracket_factor = pow((double)-1,k+1)*fact(condition_order-1-number_of_factors-k)/fact(as1_order-2-k)/pow(a_0+(*as_ref).first,condition_order-number_of_factors-k); 
    135148                                                 
    136149                                                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++) 
     
    144157                                                        bracket+=bracket_factor*bracket_combination;                                                                     
    145158                                                }                                                                        
    146                                         }                                                                
     159                                        } 
    147160 
    148                                         int_value += multiplier*bracket;         
     161                                         
    149162 
     163                                        int_value += multiplier*bracket; 
    150164                                } 
    151165                                else 
    152166                                { 
    153167                                        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)"); 
    154                                 } 
     168                                }                                                                                                                
     169                        } 
    155170 
    156                                 // cout << c << int_value << endl; 
     171                         
     172                        correction_term *= fact(condition_order-my_emlig->number_of_parameters)/pow(a_0,condition_order-my_emlig->number_of_parameters+1); 
    157173 
    158                                 return int_value;                                                                                
    159                         } 
     174                        // cout << c << int_value << endl; 
     175 
     176                        int_value += correction_term; 
     177 
     178                        // cout << int_value << endl; 
     179 
     180                        // cout  << "***************************"  << endl << endl; 
     181 
     182                        return int_value; 
    160183                         
    161184                } 
  • applications/robust/robustlib.h

    r1271 r1272  
    273273class c_statistic 
    274274{ 
     275 
     276public: 
    275277        polyhedron* end_poly; 
    276278        polyhedron* start_poly; 
    277  
    278 public:  
    279279 
    280280        vector<polyhedron*> rows; 
     
    567567        /// A statistic in a form of a Hasse diagram representing a complex of convex polyhedrons obtained as a result 
    568568        /// of data update from Bayesian estimation or set by the user if this emlig is a prior density 
    569         c_statistic statistic; 
     569         
    570570 
    571571        vector<list<polyhedron*>> for_splitting; 
     
    787787         
    788788public:  
     789        c_statistic statistic; 
    789790 
    790791        vector<set<my_ivec>> correction_factors;