Changeset 1320 for applications/robust
- Timestamp:
- 03/31/11 18:46:06 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/robustlib.cpp
r1301 r1320 16 16 vert_simplex.insert((vertex*)this); 17 17 18 triangulation. push_back(vert_simplex);18 triangulation.insert(pair<double,set<vertex*>>(0,vert_simplex)); 19 19 } 20 20 21 21 for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++) 22 22 { 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++) 24 24 { 25 25 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()); 27 27 28 28 pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin()); … … 30 30 if(ret_val.second == true) 31 31 { 32 triangulation.push_back(new_simplex);32 double cur_prob = 0; 33 33 34 34 if(should_integrate) 35 35 { 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)); 38 42 } 39 43 } -
applications/robust/robustlib.h
r1319 r1320 164 164 165 165 /// List of triangulation polyhedrons of the polyhedron given by their relative vertices. 166 list<set<vertex*>> triangulation;166 map<double,set<vertex*>> triangulation; 167 167 168 168 /// A list of relative addresses serving for Hasse diagram construction. … … 279 279 vert_simplex.insert(this); 280 280 281 triangulation. push_back(vert_simplex);281 triangulation.insert(pair<double,set<vertex*>>(0,vert_simplex)); 282 282 } 283 283 … … 773 773 toprow* cur_par_toprow = ((toprow*)current_parent); 774 774 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++) 777 779 { 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()); 780 789 } 781 790 } … … 870 879 cur_par_toprow->probability = 0.0; 871 880 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++) 873 884 { 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()); 876 894 } 877 895 … … 1690 1708 } 1691 1709 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 1692 1760 protected: 1693 1761 … … 1858 1926 t_simplex2.insert(current_copy2->vertices.begin(),current_copy2->vertices.end()); 1859 1927 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)); 1862 1930 1863 1931 // Now we have copied the polyhedron and we have to copy all of its relations. Because we are copying … … 2021 2089 //posterior->step_me(0); 2022 2090 2091 /// \TODO tohle je spatne, tady musi byt jiny vypocet poctu podminek, kdyby nejaka byla multiplicitni, tak tohle bude spatne 2023 2092 if(conditions.size()>window_size && window_size!=0) 2024 2093 {