Changeset 1320 for applications/robust

Show
Ignore:
Timestamp:
03/31/11 18:46:06 (13 years ago)
Author:
sindj
Message:

Rozdelano samplovani z emlig. Zbyva dodelat vypocet v jednotlivych simplexech triangulace. JS

Location:
applications/robust
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/robustlib.cpp

    r1301 r1320  
    1616                        vert_simplex.insert((vertex*)this); 
    1717 
    18                         triangulation.push_back(vert_simplex); 
     18                        triangulation.insert(pair<double,set<vertex*>>(0,vert_simplex)); 
    1919                } 
    2020 
    2121                for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++) 
    2222                {                        
    23                         for(list<set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++) 
     23                        for(map<double,set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++) 
    2424                        { 
    2525                                set<vertex*> new_simplex; 
    26                                 new_simplex.insert((*t_ref).begin(),(*t_ref).end());                             
     26                                new_simplex.insert((*t_ref).second.begin(),(*t_ref).second.end());                               
    2727 
    2828                                pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin()); 
     
    3030                                if(ret_val.second == true) 
    3131                                { 
    32                                         triangulation.push_back(new_simplex); 
     32                                        double cur_prob = 0; 
    3333 
    3434                                        if(should_integrate) 
    3535                                        { 
    36                                                 ((toprow *)this)->probability += ((toprow *)this)->integrate_simplex(new_simplex, 'S'); 
    37                                         } 
     36                                                cur_prob = ((toprow *)this)->integrate_simplex(new_simplex, 'S'); 
     37 
     38                                                ((toprow *)this)->probability += cur_prob; 
     39                                        } 
     40 
     41                                        triangulation.insert(pair<double,set<vertex*>>(cur_prob,new_simplex)); 
    3842                                }  
    3943                        }        
  • applications/robust/robustlib.h

    r1319 r1320  
    164164 
    165165        /// List of triangulation polyhedrons of the polyhedron given by their relative vertices.  
    166         list<set<vertex*>> triangulation; 
     166        map<double,set<vertex*>> triangulation; 
    167167 
    168168        /// A list of relative addresses serving for Hasse diagram construction. 
     
    279279                vert_simplex.insert(this); 
    280280 
    281                 triangulation.push_back(vert_simplex); 
     281                triangulation.insert(pair<double,set<vertex*>>(0,vert_simplex)); 
    282282        } 
    283283 
     
    773773                                                                toprow* cur_par_toprow = ((toprow*)current_parent); 
    774774                                                                cur_par_toprow->probability = 0.0; 
    775                                                                                  
    776                                                                 for(list<set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) 
     775                                                                 
     776                                                                map<double,set<vertex*>> new_triangulation; 
     777 
     778                                                                for(map<double,set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) 
    777779                                                                { 
    778                                                                         cur_par_toprow->probability += cur_par_toprow->integrate_simplex(*t_ref,'C'); 
    779                                                                 }                                                                        
     780                                                                        double cur_prob = cur_par_toprow->integrate_simplex((*t_ref).second,'C'); 
     781                                                                         
     782                                                                        cur_par_toprow->probability += cur_prob; 
     783 
     784                                                                        new_triangulation.insert(pair<double,set<vertex*>>(cur_prob,(*t_ref).second)); 
     785                                                                } 
     786 
     787                                                                current_parent->triangulation.clear(); 
     788                                                                current_parent->triangulation.insert(new_triangulation.begin(),new_triangulation.end()); 
    780789                                                        } 
    781790                                                } 
     
    870879                                                                cur_par_toprow->probability = 0.0; 
    871880                                                                         
    872                                                                 for(list<set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) 
     881                                                                map<double,set<vertex*>> new_triangulation; 
     882                                                                 
     883                                                                for(map<double,set<vertex*>>::iterator t_ref = current_parent->triangulation.begin();t_ref!=current_parent->triangulation.end();t_ref++) 
    873884                                                                { 
    874                                                                         cur_par_toprow->probability += cur_par_toprow->integrate_simplex(*t_ref,'C'); 
    875                                                                 }                                                                        
     885                                                                        double cur_prob = cur_par_toprow->integrate_simplex((*t_ref).second,'C'); 
     886                                                                         
     887                                                                        cur_par_toprow->probability += cur_prob; 
     888 
     889                                                                        new_triangulation.insert(pair<double,set<vertex*>>(cur_prob,(*t_ref).second)); 
     890                                                                } 
     891 
     892                                                                current_parent->triangulation.clear(); 
     893                                                                current_parent->triangulation.insert(new_triangulation.begin(),new_triangulation.end()); 
    876894                                                        } 
    877895 
     
    16901708                } 
    16911709 
     1710 
     1711 
     1712        mat sample_mat(int n) 
     1713        { 
     1714                mat sample_mat; 
     1715                map<double,toprow*> ordered_toprows; 
     1716 
     1717                /// \TODO tady je to spatne, tady nesmi byt conditions.size(), viz RARX.bayes() 
     1718                if(conditions.size()-2-number_of_parameters>=0) 
     1719                { 
     1720                        double sum = 0; 
     1721 
     1722                        for(polyhedron* top_ref = statistic.rows[number_of_parameters-1];top_ref!=statistic.end_poly;top_ref=top_ref->next_poly) 
     1723                        { 
     1724                                toprow* current_top = (toprow*)top_ref; 
     1725 
     1726                                sum+=current_top->probability; 
     1727                                ordered_toprows.insert(pair<double,toprow*>(sum,current_top)); 
     1728                        } 
     1729                } 
     1730                else 
     1731                { 
     1732                        throw new exception("You are trying to sample from density that is not determined (parameters can't be integrated out)!"); 
     1733                } 
     1734 
     1735                while(sample_mat.cols()<n) 
     1736                { 
     1737                        double rnumber = randu(); 
     1738 
     1739                        toprow* sampled_toprow = ordered_toprows.upper_bound(rnumber)->second; 
     1740 
     1741                        rnumber = randu(); 
     1742 
     1743                        map<double,set<vertex*>>::iterator tri_ref = sampled_toprow->triangulation.begin() 
     1744                        double sum = 0; 
     1745 
     1746                        for(tri_ref = sampled_toprow->triangulation.begin();tri_ref!=sampled_toprow->triangulation.end();tri_ref++) 
     1747                        { 
     1748                                sum += (*tri_ref).first; 
     1749 
     1750                                if(sum/sampled_toprow->probability >= rnumber) 
     1751                                        break; 
     1752                        } 
     1753 
     1754 
     1755                } 
     1756 
     1757                return sample_mat; 
     1758        } 
     1759 
    16921760protected: 
    16931761 
     
    18581926                                        t_simplex2.insert(current_copy2->vertices.begin(),current_copy2->vertices.end()); 
    18591927                                         
    1860                                         current_copy1->triangulation.push_back(t_simplex1); 
    1861                                         current_copy2->triangulation.push_back(t_simplex2);                                      
     1928                                        current_copy1->triangulation.insert(pair<double,set<vertex*>>(0,t_simplex1)); 
     1929                                        current_copy2->triangulation.insert(pair<double,set<vertex*>>(0,t_simplex2));                                    
    18621930                                         
    18631931                                        // Now we have copied the polyhedron and we have to copy all of its relations. Because we are copying 
     
    20212089                //posterior->step_me(0); 
    20222090                 
     2091                /// \TODO tohle je spatne, tady musi byt jiny vypocet poctu podminek, kdyby nejaka byla multiplicitni, tak tohle bude spatne 
    20232092                if(conditions.size()>window_size && window_size!=0) 
    20242093                {