Changeset 1396 for applications

Show
Ignore:
Timestamp:
09/29/11 16:28:33 (13 years ago)
Author:
sindj
Message:

Sampling finished. First experiments set up properly - sampling from posterior on parameters. JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1395 r1396  
    2929const int max_model_order = 1; 
    3030const double apriorno     = 0.01; 
     31const int max_window_size = 121; 
    3132 
    3233/* 
     
    148149                                 
    149150                                V0  = apriorno * eye(ar_components.size()+1);//menit konstantu 
    150                                 //V0(0,0) = 0; 
     151                                //V0(0,1) = -0.01; 
     152                                //V0(1,0) = -0.01; 
    151153                                my_arx->set_constant(false);                             
    152154                                 
     
    156158                        my_arx->set_parameters(window_size); 
    157159                        my_arx->validate(); 
     160 
     161                        vec mean = my_arx->posterior().mean(); 
     162                        cout << mean << endl; 
    158163                } 
    159164        } 
     
    190195                if(my_rarx!=NULL) 
    191196                { 
    192                         pair<vec,mat> imp_samples = my_rarx->posterior->importance_sample(sample_size); 
     197                        pair<vec,mat> imp_samples = my_rarx->posterior->sample(sample_size,false); 
    193198 
    194199                        //cout << imp_samples.first << endl;                     
     
    298303        vector<vector<string>> strings; 
    299304 
    300         char* file_string =  "C:\\ar_student_single"; // "C:\\dataADClosePercDiff"; //   
     305        char* file_string =  "C:\\results\\cauchy"; // "C:\\dataADClosePercDiff"; //   
    301306 
    302307        char dfstring[80]; 
     
    338343        for(set<set<pair<int,int>>>::iterator model_type = model_types.begin();model_type!=model_types.end();model_type++) 
    339344        {// prechadza rozne typy kanalov, a poctu regresorov 
    340                 for(int window_size = 50;window_size < 51;window_size++) 
    341                 { 
    342                         models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix));   // to su len konstruktory, len inicializujeme rozne typy 
    343                         models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); 
     345                for(int window_size = max_window_size-1;window_size < max_window_size;window_size++) 
     346                { 
     347                        //models.push_back(new model((*model_type),true,true,window_size,0,&data_matrix));   // to su len konstruktory, len inicializujeme rozne typy 
     348                        //models.push_back(new model((*model_type),false,true,window_size,0,&data_matrix)); 
    344349                        models.push_back(new model((*model_type),true,false,window_size,0,&data_matrix)); 
    345350                        models.push_back(new model((*model_type),false,false,window_size,0,&data_matrix));               
     
    360365 
    361366        for(int time = max_model_order;time<data_matrix.cols();time++) //time<data_matrix.cols()  
    362         {       //pocet stlpcov data_matrix je pocet casovych krokov 
     367        {        
     368                if(time==max_window_size) 
     369                { 
     370                        exit(1); 
     371                } 
     372                 
     373                //pocet stlpcov data_matrix je pocet casovych krokov 
    363374                vec cur_res_lognc; 
    364375                // vec preds; 
     
    373384                        if((*model_ref)->my_rarx!=NULL) //vklada normalizacni faktor do cur_res_lognc 
    374385                        { 
     386                                cout << "Maxlik vertex:" << (*model_ref)->my_rarx->posterior->minimal_vertex->get_coordinates() << endl; 
    375387                                cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_rarx->posterior->_ll());                                 
    376388                        } 
     
    379391                                cur_res_lognc.ins(cur_res_lognc.size(),(*model_ref)->my_arx->_ll()); 
    380392                        } 
    381  
    382                         int sample_size = 10; 
    383                         pair<vec,mat> samples; 
    384                         if((*model_ref)->my_arx!=NULL) 
    385                         { 
    386                                 mat samp_mat = (*model_ref)->my_arx->posterior().sample_mat(sample_size); 
    387                                 samples = pair<vec,mat>(ones(samp_mat.rows()),samp_mat); 
    388                         } 
    389                         else 
    390                         { 
    391                                 samples = (*model_ref)->my_rarx->posterior->importance_sample(sample_size); 
    392                         } 
    393393                         
    394                         for(int i=0;i<(*model_ref)->ar_components.size()+1;i++) 
    395                         { 
     394                        if(time == max_window_size-1) 
     395                        { 
     396                                //*********************** 
     397                                int sample_size = 100000; 
     398                                //*********************** 
     399                                 
     400                                pair<vec,mat> samples; 
     401                                if((*model_ref)->my_arx!=NULL) 
     402                                { 
     403                                        mat samp_mat = (*model_ref)->my_arx->posterior().sample_mat(sample_size); 
     404                                        samples = pair<vec,mat>(ones(samp_mat.cols()),samp_mat); 
     405                                } 
     406                                else 
     407                                { 
     408                                        samples = (*model_ref)->my_rarx->posterior->sample(sample_size,true);                                    
     409                                } 
     410 
    396411                                char fstring[80];                                        
    397412                                strcpy(fstring,file_string); 
     
    399414                                strcat(fstring,".txt"); 
    400415                                 
    401                                 cout << samples.first << endl; 
     416                                //cout << samples.first << endl; 
    402417                                 
    403418                                myfilew.open(fstring,ios::app); 
    404                                 myfilew << samples.first << endl << samples.second << endl << zeros(samples.first.size()) << endl;  
    405                                 myfilew.close(); 
    406                         }                        
     419                                 
     420                                /* 
     421                                for(int i = 0;i<samples.first.size();i++) 
     422                                { 
     423                                        myfilew << samples.first.get(i) << ","; 
     424                                } 
     425                                myfilew << endl; 
     426                                */ 
     427 
     428                                for(int j = 0;j<samples.second.rows()+1;j++) 
     429                                {                        
     430                                        for(int i = 0;i<samples.second.cols();i++) 
     431                                        { 
     432                                                if(j!=samples.second.rows()) 
     433                                                { 
     434                                                        myfilew << samples.second.get(j,i) << ","; 
     435                                                } 
     436                                                /* 
     437                                                else 
     438                                                { 
     439                                                        myfilew << "0,"; 
     440                                                } 
     441                                                */ 
     442                                        }                                
     443                                        myfilew << endl; 
     444                                } 
     445 
     446                                cout << "*************************************" << endl; 
     447 
     448                                myfilew.close();                                 
     449                        } 
    407450                         
    408451                        /* // PREDICTIONS 
  • applications/robust/robustlib.cpp

    r1395 r1396  
    175175                                as_count++; 
    176176                        } 
    177                         */               
     177                        */                       
    178178 
    179179                        vector<double> gamma_facs; 
     
    258258                        simplex->probability = int_value; 
    259259                        simplex->volume = volume; 
    260                         //cout << "Probability:" << int_value << endl; 
     260                        cout << "Probability:" << int_value << endl << endl; 
    261261                        //pause(0.1); 
    262262                        return int_value;                
  • applications/robust/robustlib.h

    r1395 r1396  
    22522252                                if(sum_g>rnumber) 
    22532253                                {                                        
    2254                                         GamRNG.setup(condition_order-number_of_parameters-1+i,1/(*g_ref).second); 
     2254                                        // tady je mozna chyba ve vaskove kodu 
     2255                                        GamRNG.setup(condition_order-number_of_parameters-1+i,(*g_ref).second); 
    22552256                                                                                                                                 
    22562257                                        sigma = 1/GamRNG(); 
     
    22732274                        for(multimap<double,double>::iterator pg_ref = (*v_ref).begin();pg_ref!=(*v_ref).end();pg_ref++) 
    22742275                        { 
    2275                                 pg_sum += exp(-(*pg_ref).second/sigma)*pow((*pg_ref).second/sigma,condition_order-number_of_parameters-1+i)/sigma/fact(condition_order-number_of_parameters-1+i)*(*pg_ref).first;  // pg_sum += exp((sampled_simplex->min_beta-(*pg_ref).second)/sigma)*pow((*pg_ref).second/sigma,(int)conditions.size())*(*pg_ref).second/fact(conditions.size())*(*pg_ref).first; 
     2276                                pg_sum += exp(-(*pg_ref).second/sigma)*pow((*pg_ref).second/sigma,condition_order-number_of_parameters-1+i)/sigma/fact(condition_order-number_of_parameters-2+i)*(*pg_ref).first;  // pg_sum += exp((sampled_simplex->min_beta-(*pg_ref).second)/sigma)*pow((*pg_ref).second/sigma,(int)conditions.size())*(*pg_ref).second/fact(conditions.size())*(*pg_ref).first; 
    22762277                        } 
    22772278 
     
    22792280                }        
    22802281 
    2281                 return pair<double,double>(sum_g/pg_sum,sigma); 
    2282         } 
    2283  
    2284         mat sample_mat(int n) 
    2285         {                
    2286  
    2287                 /// \TODO tady je to spatne, tady nesmi byt conditions.size(), viz RARX.bayes() 
    2288                 if(conditions.size()-2-number_of_parameters>=0) 
    2289                 {                        
    2290                         mat sample_mat; 
    2291                         map<double,toprow*> ordered_toprows;                     
    2292                         double sum_a = 0; 
    2293                          
    2294                         //cout << "Likelihoods of toprows:" << endl; 
    2295  
    2296                         for(polyhedron* top_ref = statistic.rows[number_of_parameters];top_ref!=statistic.end_poly;top_ref=top_ref->next_poly) 
    2297                         { 
    2298                                 toprow* current_top = (toprow*)top_ref; 
    2299  
    2300                                 sum_a+=current_top->probability; 
    2301                                 /* 
    2302                                 cout << current_top->probability << "   "; 
    2303  
    2304                                 for(set<vertex*>::iterator vert_ref = (*top_ref).vertices.begin();vert_ref!=(*top_ref).vertices.end();vert_ref++) 
    2305                                 { 
    2306                                         cout << round(100*(*vert_ref)->get_coordinates())/100 << " ; "; 
    2307                                 } 
    2308                                 */ 
    2309  
    2310                                 // cout << endl; 
    2311                                 ordered_toprows.insert(pair<double,toprow*>(sum_a,current_top)); 
    2312                         }                        
    2313                          
    2314                         // cout << "Sum N: " << normalization_factor << endl; 
    2315  
    2316                         while(sample_mat.cols()<n) 
    2317                         { 
    2318                                 //// cout << "*************************************" << endl; 
    2319  
    2320                                  
    2321                                  
    2322                                 double rnumber = randu()*sum_a; 
    2323  
    2324                                 // cout << "RND:" << rnumber << endl; 
    2325  
    2326                                 // This could be more efficient (log n), but map::upper_bound() doesn't let me dereference returned iterator 
    2327                                 int toprow_count = 0; 
    2328                                 toprow* sampled_toprow;                          
    2329                                 for(map<double,toprow*>::iterator top_ref = ordered_toprows.begin();top_ref!=ordered_toprows.end();top_ref++) 
    2330                                 { 
    2331                                         // cout << "CDF:"<< (*top_ref).first << endl; 
    2332                                         toprow_count++; 
    2333  
    2334                                         if((*top_ref).first >= rnumber) 
    2335                                         { 
    2336                                                 sampled_toprow = (*top_ref).second; 
    2337                                                 break; 
    2338                                         }                                                
    2339                                 }                                
    2340  
    2341                                 //// cout << "Toprow/Count: " << toprow_count << "/" << ordered_toprows.size() << endl; 
    2342                                 // cout << &sampled_toprow << ";"; 
    2343  
    2344                                 rnumber = randu();                               
    2345  
    2346                                 set<simplex*>::iterator s_ref; 
    2347                                 double sum_b = 0; 
    2348                                 int simplex_count = 0; 
    2349                                 for(s_ref = sampled_toprow->triangulation.begin();s_ref!=sampled_toprow->triangulation.end();s_ref++) 
    2350                                 { 
    2351                                         simplex_count++; 
    2352                                          
    2353                                         sum_b += (*s_ref)->probability; 
    2354  
    2355                                         if(sum_b/sampled_toprow->probability >= rnumber) 
    2356                                                 break; 
    2357                                 } 
    2358  
    2359                                 //// cout << "Simplex/Count: " << simplex_count << "/" << sampled_toprow->triangulation.size() << endl; 
    2360                                 //// cout << "Simplex factor: " << (*s_ref)->probability << endl; 
    2361                                 //// cout << "Toprow factor:  " << sampled_toprow->probability << endl; 
    2362                                 //// cout << "Emlig factor:   " << normalization_factor << endl; 
    2363                                 // cout << &(*tri_ref) << endl; 
    2364  
    2365                                 int number_of_runs = 0; 
    2366                                 bool have_sigma = false; 
    2367                                 double sigma = 0; 
    2368                                 do 
    2369                                 { 
    2370                                         rnumber = randu(); 
    2371                                          
    2372                                         double sum_g = 0; 
    2373                                         for(int i = 0;i<(*s_ref)->positive_gamma_parameters.size();i++) 
    2374                                         { 
    2375                                                 for(multimap<double,double>::iterator g_ref = (*s_ref)->positive_gamma_parameters[i].begin();g_ref != (*s_ref)->positive_gamma_parameters[i].end();g_ref++) 
    2376                                                 { 
    2377                                                         sum_g += (*g_ref).first/(*s_ref)->positive_gamma_sum; 
    2378  
    2379                                                          
    2380                                                         if(sum_g>rnumber) 
    2381                                                         { 
    2382                                                                 //itpp::Gamma_RNG* gamma = new itpp::Gamma_RNG(conditions.size()-number_of_parameters,1/(*g_ref).second); 
    2383                                                                 //sigma = 1/(*gamma)(); 
    2384                                                                  
    2385                                                                 GamRNG.setup(conditions.size()-number_of_parameters,(*g_ref).second); 
    2386                                                                                                                                  
    2387                                                                 sigma = 1/GamRNG(); 
    2388  
    2389                                                                 // cout << "Sigma mean:   " << (*g_ref).second/(conditions.size()-number_of_parameters-1) << endl;                                                               
    2390                                                                 break; 
    2391                                                         }                                                        
    2392                                                 } 
    2393  
    2394                                                 if(sigma!=0) 
    2395                                                 { 
    2396                                                         break; 
    2397                                                 } 
    2398                                         } 
    2399  
    2400                                         rnumber = randu(); 
    2401  
    2402                                         double pg_sum = 0; 
    2403                                         for(vector<multimap<double,double>>::iterator v_ref = (*s_ref)->positive_gamma_parameters.begin();v_ref!=(*s_ref)->positive_gamma_parameters.end();v_ref++) 
    2404                                         { 
    2405                                                 for(multimap<double,double>::iterator pg_ref = (*v_ref).begin();pg_ref!=(*v_ref).end();pg_ref++) 
    2406                                                 { 
    2407                                                         pg_sum += exp(((*s_ref)->min_beta-(*pg_ref).second)/sigma)*pow((*pg_ref).second/sigma,(int)conditions.size()-number_of_parameters-1)*(*pg_ref).second/fact(conditions.size()-number_of_parameters-1)*(*pg_ref).first; 
    2408                                                 }                                        
    2409                                         } 
    2410  
    2411                                         double ng_sum = 0; 
    2412                                         for(vector<multimap<double,double>>::iterator v_ref = (*s_ref)->negative_gamma_parameters.begin();v_ref!=(*s_ref)->negative_gamma_parameters.end();v_ref++) 
    2413                                         { 
    2414                                                 for(multimap<double,double>::iterator ng_ref = (*v_ref).begin();ng_ref!=(*v_ref).end();ng_ref++) 
    2415                                                 { 
    2416                                                         ng_sum += exp(((*s_ref)->min_beta-(*ng_ref).second)/sigma)*pow((*ng_ref).second/sigma,(int)conditions.size()-number_of_parameters-1)*(*ng_ref).second/fact(conditions.size()-number_of_parameters-1)*(*ng_ref).first; 
    2417                                                 }                                        
    2418                                         } 
    2419                                          
    2420                                         if((pg_sum-ng_sum)/pg_sum>rnumber) 
    2421                                         { 
    2422                                                 have_sigma = true; 
    2423                                         } 
    2424  
    2425                                         number_of_runs++; 
    2426                                 } 
    2427                                 while(!have_sigma); 
    2428  
    2429                                 //// cout << "Sigma: " << sigma << endl; 
    2430                                 //// cout << "Nr. of sigma runs: " << number_of_runs << endl; 
    2431  
    2432                                 int dimension = (*s_ref)->vertices.size()-1; 
    2433  
    2434                                 mat jacobian(dimension,dimension); 
    2435                                 vec gradient = sampled_toprow->condition_sum.right(dimension); 
    2436  
    2437                                 vertex* base_vert = *(*s_ref)->vertices.begin(); 
    2438  
    2439                                 //// cout << "Base vertex coords(should be close to est. param.): " << base_vert->get_coordinates() << endl; 
    2440                                  
    2441                                 int row_count = 0; 
    2442  
    2443                                 for(set<vertex*>::iterator vert_ref = ++(*s_ref)->vertices.begin();vert_ref!=(*s_ref)->vertices.end();vert_ref++) 
    2444                                 { 
    2445                                         vec current_coords = (*vert_ref)->get_coordinates(); 
    2446  
    2447                                         //// cout << "Coords of vertex[" << row_count << "]: " << current_coords << endl;  
    2448                                          
    2449                                         vec relative_coords = current_coords-base_vert->get_coordinates();                               
    2450  
    2451                                         jacobian.set_row(row_count,relative_coords); 
    2452  
    2453                                         row_count++; 
    2454                                 }                                
    2455                                  
    2456                                 //// cout << "Jacobian: " << jacobian << endl; 
    2457  
    2458                                 //// cout << "Gradient before trafo:" << gradient << endl; 
    2459                                                                  
    2460                                 gradient = jacobian*gradient;    
    2461  
    2462                                 //// cout << "Gradient after trafo:" << gradient << endl; 
    2463  
    2464                                 // vec normal_gradient = gradient/sqrt(gradient*gradient); 
    2465                                 // cout << gradient << endl; 
    2466                                 // cout << normal_gradient << endl; 
    2467                                 // cout << sqrt(gradient*gradient) << endl; 
    2468  
    2469                                 mat rotation_matrix = eye(dimension);                            
    2470  
    2471                                                                  
    2472  
    2473                                 for(int i = 1;i<dimension;i++) 
    2474                                 { 
    2475                                         vec x_axis = zeros(dimension); 
    2476                                         x_axis.set(0,1); 
    2477  
    2478                                         x_axis = rotation_matrix*x_axis; 
    2479  
    2480                                         double t = abs(gradient[i]/gradient*x_axis); 
    2481  
    2482                                         double sin_theta = sign(gradient[i])*t/sqrt(1+pow(t,2)); 
    2483                                         double cos_theta = sign(gradient*x_axis)/sqrt(1+pow(t,2)); 
    2484  
    2485                                         mat partial_rotation = eye(dimension); 
    2486  
    2487                                         partial_rotation.set(0,0,cos_theta); 
    2488                                         partial_rotation.set(i,i,cos_theta); 
    2489                                          
    2490                                         partial_rotation.set(0,i,sin_theta); 
    2491                                         partial_rotation.set(i,0,-sin_theta); 
    2492                                          
    2493                                         rotation_matrix = rotation_matrix*partial_rotation;                              
    2494                                          
    2495                                 } 
    2496  
    2497                                 // cout << rotation_matrix << endl; 
    2498                                  
    2499                                 mat extended_rotation = rotation_matrix; 
    2500                                 extended_rotation.ins_col(0,zeros(extended_rotation.rows())); 
    2501  
    2502                                 //// cout << "Extended rotation: " << extended_rotation << endl; 
    2503                                  
    2504                                 vec minima = itpp::min(extended_rotation,2); 
    2505                                 vec maxima = itpp::max(extended_rotation,2); 
    2506  
    2507                                 //// cout << "Minima: " << minima << endl; 
    2508                                 //// cout << "Maxima: " << maxima << endl; 
    2509  
    2510                                 vec sample_coordinates;          
    2511                                 bool is_inside = true; 
    2512                                  
    2513                                 vec new_sample; 
    2514                                 sample_coordinates = new_sample; 
    2515  
    2516                                 for(int j = 0;j<number_of_parameters;j++) 
    2517                                 { 
    2518                                         rnumber = randu(); 
    2519                                          
    2520                                         double coordinate; 
    2521  
    2522                                         if(j==0) 
    2523                                         {                                                
    2524                                                 vec new_gradient = rotation_matrix*gradient; 
    2525                                                  
    2526                                                 //// cout << "New gradient(should have only first component nonzero):" << new_gradient << endl; 
    2527  
    2528                                                 // cout << "Max: " << maxima[0] << "  Min: " << minima[0] << "  Grad:" << new_gradient[0] << endl; 
    2529                                                  
    2530                                                 double log_bracket = 1-rnumber*(1-exp(new_gradient[0]/sigma*(minima[0]-maxima[0]))); 
    2531                                                  
    2532                                                 coordinate = minima[0]-sigma/new_gradient[0]*log(log_bracket); 
    2533                                         } 
    2534                                         else 
    2535                                         { 
    2536                                                 coordinate = minima[j]+rnumber*(maxima[j]-minima[j]); 
    2537                                         } 
    2538  
    2539                                         sample_coordinates.ins(j,coordinate); 
    2540                                 } 
    2541  
    2542                                 //// cout << "Sampled coordinates(gradient direction): " << sample_coordinates << endl; 
    2543  
    2544                                 sample_coordinates = rotation_matrix.T()*sample_coordinates; 
    2545  
    2546                                 //// cout << "Sampled coordinates(backrotated direction):" << sample_coordinates << endl; 
    2547  
    2548                                  
    2549                                 for(int j = 0;j<sample_coordinates.size();j++) 
    2550                                 { 
    2551                                         if(sample_coordinates[j]<0) 
    2552                                         { 
    2553                                                 is_inside = false; 
    2554                                         } 
    2555                                 } 
    2556  
    2557                                 double above_criterion = ones(sample_coordinates.size())*sample_coordinates; 
    2558  
    2559                                 if(above_criterion>1) 
    2560                                 { 
    2561                                         is_inside = false; 
    2562                                 } 
    2563  
    2564                                 if(is_inside) 
    2565                                 {                                        
    2566                                         sample_coordinates = jacobian.T()*sample_coordinates+(*base_vert).get_coordinates(); 
    2567                                          
    2568                                         sample_coordinates.ins(0,sigma); 
    2569                                          
    2570                                         //// cout << "Sampled coordinates(parameter space):" << sample_coordinates << endl; 
    2571  
    2572                                         sample_mat.ins_col(0,sample_coordinates); 
    2573  
    2574                                         // cout << sample_mat.cols() << ","; 
    2575                                 } 
    2576  
    2577                                 // cout << sampled_toprow->condition_sum.right(sampled_toprow->condition_sum.size()-1)*min_grad->get_coordinates()-sampled_toprow->condition_sum[0] << endl; 
    2578                                 // cout << sampled_toprow->condition_sum.right(sampled_toprow->condition_sum.size()-1)*max_grad->get_coordinates()-sampled_toprow->condition_sum[0] << endl; 
    2579  
    2580                                  
    2581                         } 
    2582  
    2583                         cout << endl; 
    2584                         return sample_mat; 
    2585                 } 
    2586                 else 
    2587                 { 
    2588                         throw new exception("You are trying to sample from density that is not determined (parameters can't be integrated out)!"); 
     2282                return pair<double,double>(sampled_simplex->positive_gamma_sum/pg_sum,sigma); 
     2283        } 
     2284 
     2285        pair<vec,mat> sample(int n, bool rejection) 
     2286        { 
     2287                vec probabilities; 
     2288                mat samples;             
    25892289                 
    2590                         return 0; 
    2591                 } 
    2592  
    2593                  
    2594         } 
    2595  
    2596         pair<vec,mat> importance_sample(int n) 
    2597         { 
    2598                 vec probabilities; 
    2599                 mat samples; 
    2600                  
    2601                 for(int i = 0;i<n;i++) 
     2290                while(samples.cols()<n) 
    26022291                { 
    26032292                        pair<vec,simplex*> condition_and_simplex = choose_simplex(); 
     
    26392328 
    26402329                        double exponent = extended_coords*condition_and_simplex.first; 
    2641                         double sample_prob = 1*condition_and_simplex.second->volume/condition_and_simplex.second->probability/pow(2*probability_and_sigma.second,condition_order)*exp(-exponent/probability_and_sigma.second)*probability_and_sigma.first;                       
     2330                        double sample_prob = 1*condition_and_simplex.second->volume/condition_and_simplex.second->probability/pow(2*probability_and_sigma.second,condition_order)*exp(-exponent/probability_and_sigma.second);//*probability_and_sigma.first;                    
    26422331 
    26432332                        sample_coords.ins(sample_coords.size(),probability_and_sigma.second); 
    2644  
     2333                         
    26452334                        samples.ins_col(0,sample_coords); 
    26462335                        probabilities.ins(0,sample_prob); 
    26472336 
    2648                         cout << "C:" << sample_coords << "   p:" << sample_prob << endl; 
    2649                         pause(1 ); 
    2650                 } 
    2651          
    2652                 return pair<vec,mat>(probabilities,samples); 
     2337                         
     2338 
     2339                        //cout << "C:" << sample_coords << "   p:" << sample_prob << endl; 
     2340                        //pause(1); 
     2341                } 
     2342 
     2343                if(rejection) 
     2344                { 
     2345                        double max_prob = max(probabilities); 
     2346 
     2347                        set<int> indices; 
     2348                        for(int i = 0;i<n;i++) 
     2349                        { 
     2350                                double randn = randu(); 
     2351 
     2352                                if(probabilities.get(i)<randn*max_prob) 
     2353                                { 
     2354                                        indices.insert(i); 
     2355                                } 
     2356                        } 
     2357 
     2358                        for(set<int>::reverse_iterator ind_ref = indices.rbegin();ind_ref!=indices.rend();ind_ref++) 
     2359                        { 
     2360                                samples.del_col(*ind_ref);                               
     2361                        } 
     2362 
     2363                        return pair<vec,mat>(ones(samples.cols()),samples); 
     2364                } 
     2365                else 
     2366                {        
     2367                        return pair<vec,mat>(probabilities,samples); 
     2368                } 
    26532369        } 
    26542370 
     
    30322748                //posterior->step_me(0); 
    30332749                 
    3034                 cout << "Current condition:" << yt << endl; 
     2750                cout << "*************************************" << endl << "Current condition:" << yt << endl << "*************************************" << endl; 
    30352751 
    30362752                /// \TODO tohle je spatne, tady musi byt jiny vypocet poctu podminek, kdyby nejaka byla multiplicitni, tak tohle bude spatne