Changeset 1365 for applications

Show
Ignore:
Timestamp:
05/10/11 13:10:46 (13 years ago)
Author:
sindj
Message:

Cele rozkopano a znovu poskladano za ucelem spravne integrace a nic - jen se mi podarilo doplnit faktor 1/2n. Sakris. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1362 r1365  
    4848        HSZ hszItem = DdeCreateStringHandle(idInst, szItem, 0); 
    4949        HDDEDATA hData = DdeClientTransaction(NULL,0,hConv,hszItem,CF_TEXT,  
    50                                                                         XTYP_REQUEST,TIMEOUT_ASYNC , NULL); 
     50                                                                        XTYP_ADVSTART,TIMEOUT_ASYNC , NULL); //TIMEOUT_ASYNC 
    5151        if (hData==NULL) 
    5252        { 
     
    112112                        {                                
    113113                                V0  = 0.01 * eye(ar_components.size()+2); 
    114                                 V0(0,0) = 1; 
     114                                V0(0,0) = 0; 
    115115                                my_arx->set_constant(true);      
    116116                                 
     
    120120                                 
    121121                                V0  = 0.01 * eye(ar_components.size()+1); 
    122                                 V0(0,0) = 1; 
     122                                V0(0,0) = 0; 
    123123                                my_arx->set_constant(false);                             
    124124                                 
     
    207207        /* 
    208208        char szApp[] = "MT4"; 
    209         char szTopic[] = "ASK";  
    210         char szItem1[] = "EURUSD";       
     209        char szTopic[] = "BID";  
     210        char szItem1[] = "EURJPY";       
    211211 
    212212        //DDE Initialization 
     
    260260        Sleep(300000); 
    261261        Sleep(3000); 
    262         */ 
     262         
    263263 
    264264        /* 
     
    375375         
    376376 
     377         
    377378        vector<vector<string>> strings; 
    378379 
     
    410411        } 
    411412         
     413 
    412414        list<list<pair<int,int>>> model_types = model::possible_models_recurse(max_model_order,data_matrix.rows()); 
    413  
     415         
    414416        list<model*> models; 
    415417        for(list<list<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) 
     
    441443 
    442444                cout << "Updated." << endl; 
    443  
     445         
    444446                /* 
    445447                vector<vec> conditions; 
     
    652654                                        */ 
    653655 
     656                                         
    654657                                        ofstream myfile; 
    655658                                        char fstring[80];                                        
     
    670673                                         
    671674                                        myfile.close(); 
    672  
     675                        } 
    673676                                        /* 
    674677                                        myfile.open(f2string,ios::app); 
     
    706709 
    707710 
    708         } 
     711        //} 
    709712 
    710713 
  • applications/robust/robustlib.cpp

    r1362 r1365  
    147147                                //cout << "Base coords: " << base_vertex->get_coordinates() << endl; 
    148148                                //cout << "Condition: " << as_toprow->condition_sum << endl; 
    149                                 //pause(10); 
    150  
    151                                 a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition_sum[0]; 
    152                                  
    153  
     149                                //pause(0.1); 
     150 
     151                                a_0 = -base_vertex->get_coordinates()*cur_condition+as_toprow->condition_sum[0];                 
     152                                 
    154153                                int row_count = 0; 
    155154                                for(set<vertex*>::iterator vert_ref = simplex->vertices.begin(); vert_ref!=simplex->vertices.end();vert_ref++) 
     
    230229                                cout << "a_" << as_count << ": " << (*as_ref).first << "    "; 
    231230                                as_count++; 
    232                         }*/ 
     231                        } 
     232                        */ 
    233233 
    234234                        double int_value = 0;                    
     
    269269                                                multiplier        /= (*as_ref).first; 
    270270                                                number_of_factors += 1; 
    271                                         } 
    272                                          
    273                                 } 
    274                                  
     271                                        }                                        
     272                                }        
     273 
     274                                double gamma_multiplier = -(*as_ref).first-a_0; 
     275 
     276                                double bracket = fact(as1_order-1)/pow(gamma_multiplier,sigma_order+1); 
    275277                                                                 
    276  
    277                                 double bracket = fact(as1_order-1)/pow(a_0-(*as_ref).first,sigma_order+1); 
    278                                                                  
    279                                 simplex->insert_gamma(0,bracket*multiplier,a_0-(*as_ref).first);                                                                 
    280  
    281                                 // bracket *= fact(sigma_order); 
     278                                simplex->insert_gamma(0,bracket*multiplier,gamma_multiplier);                                                            
     279 
     280                                // bracket *= fact(sigma_order);                                 
    282281 
    283282                                for(int k = 0;k < as1_order-1;k++) 
    284283                                { 
    285284                                        double local_bracket = 0; 
    286                                         double bracket_factor = -pow((double)-1,k+1)/fact(as1_order-1-k)/pow(a_0-(*as_ref).first,sigma_order-k); 
     285                                        double bracket_factor = 1/fact(as1_order-1-k)/pow(gamma_multiplier,sigma_order-k);//pow((double)-1,k+1) 
    287286                                         
    288287                                        ivec control_vec = ivec(); 
     
    302301                                        } 
    303302 
    304                                         simplex->insert_gamma(k+1,local_bracket*multiplier,a_0-(*as_ref).first); 
     303                                        simplex->insert_gamma(k+1,local_bracket*multiplier,gamma_multiplier); 
    305304 
    306305                                        int division_factor = 1; 
     
    314313 
    315314                                int_value += multiplier*bracket; 
     315 
     316                                 
    316317                                                                                                                                                 
    317318                        } 
    318319 
    319                         double correction_term_base = correction_term/pow(a_0,sigma_order+1); 
    320  
    321                         simplex->insert_gamma(0,correction_term_base,a_0);                       
     320                        double correction_term_base = correction_term/pow(-a_0,sigma_order+1); 
     321 
     322                        simplex->insert_gamma(0,correction_term_base,-a_0);                      
    322323 
    323324                        correction_term = correction_term_base;//fact(sigma_order)*correction_term_base; 
     
    325326                        //cout << c << int_value << endl; 
    326327 
    327                         int_value += correction_term; 
    328                  
     328                        int_value += correction_term;                    
    329329 
    330330                        //cout << "Probability:" << int_value << endl; 
  • applications/robust/robustlib.h

    r1362 r1365  
    10631063        /// A default constructor creates an emlig with predefined statistic representing only the range of the given 
    10641064        /// parametric space, where the number of parameters of the needed model is given as a parameter to the constructor. 
    1065         emlig(int number_of_parameters, bool is_proper, double soft_prior_parameter) 
     1065        emlig(int number_of_parameters, double soft_prior_parameter) 
    10661066        {        
    10671067                this->number_of_parameters = number_of_parameters; 
    10681068 
    10691069                condition_order = number_of_parameters+2; 
    1070  
    1071                 if(is_proper) 
    1072                         condition_order++; 
    1073                  
     1070                                                 
    10741071                create_statistic(number_of_parameters, soft_prior_parameter); 
    10751072 
     
    10781075                min_ll = numeric_limits<double>::max();          
    10791076 
    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; 
     1077                 
     1078                double normalization_factor = 0; 
     1079                int counter = 0; 
     1080                for(polyhedron* top_ref = statistic.rows[number_of_parameters];top_ref!=statistic.get_end();top_ref=top_ref->next_poly) 
     1081                { 
     1082                        counter++; 
     1083                        toprow* cur_toprow = (toprow*)top_ref; 
    10881084                                 
    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                 } 
     1085                        set<simplex*>::iterator cur_simplex = cur_toprow->triangulation.begin(); 
     1086                        normalization_factor += cur_toprow->integrate_simplex(*cur_simplex,'X'); 
     1087                } 
     1088 
     1089                log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2)-(condition_order-number_of_parameters-2)*2; 
     1090 
     1091                /* 
     1092                cout << "part1: " << log(normalization_factor) << endl; 
     1093                cout << "part2: " << logfact(condition_order-number_of_parameters-2) << endl; 
     1094                pause(1); 
     1095                */ 
     1096                 
    11011097 
    11021098        } 
     
    18841880                // cout << "Normalization factor: " << normalization_factor << endl;     
    18851881 
    1886                 log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2); 
    1887  
    1888                  
     1882                log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2)-(condition_order-number_of_parameters-2)*2; 
     1883 
     1884                /* 
    18891885                cout << "part1: " << log(normalization_factor) << endl; 
    18901886                cout << "part2: " << logfact(condition_order-number_of_parameters-2) << endl; 
    18911887                pause(1); 
     1888                */ 
    18921889                 
    18931890 
     
    26082605                                                vec2.ins(0,soft_prior_parameter); 
    26092606 
    2610                                                 vec1.ins(0,-1); 
    2611                                                 vec2.ins(0,-1); 
    2612                                         } 
    2613                                          
    2614                                         cout << vec1 << endl; 
    2615                                         cout << vec2 << endl; 
     2607                                                vec1.ins(0,0); 
     2608                                                vec2.ins(0,0); 
     2609                                        } 
     2610                                         
     2611                                        // cout << vec1 << endl; 
     2612                                        // cout << vec2 << endl; 
    26162613 
    26172614 
     
    27912788                this->has_constant = has_constant; 
    27922789                 
    2793                 posterior = new emlig(number_of_parameters,true,0.001); 
     2790                posterior = new emlig(number_of_parameters,0.001); 
    27942791 
    27952792                this->window_size = window_size;