Changeset 1362 for applications
- Timestamp:
- 05/09/11 19:07:15 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1361 r1362 111 111 if(has_constant) 112 112 { 113 V0 = 0.0 001 * eye(ar_components.size()+2);114 //V0(0,0) = 0.1;113 V0 = 0.01 * eye(ar_components.size()+2); 114 V0(0,0) = 1; 115 115 my_arx->set_constant(true); 116 116 … … 119 119 { 120 120 121 V0 = 0.0 001 * eye(ar_components.size()+1);122 //V0(0,0) = 0.1;121 V0 = 0.01 * eye(ar_components.size()+1); 122 V0(0,0) = 1; 123 123 my_arx->set_constant(false); 124 124 -
applications/robust/robustlib.cpp
r1357 r1362 96 96 { 97 97 // cout << ((toprow*)this)->condition << endl; 98 99 int condition_order = ((toprow*)this)->condition_order-2; // -2 by bylo, pokud chceme uniformni apriorno 100 101 int sigma_order = condition_order-my_emlig->number_of_parameters; 98 int sigma_order = ((toprow*)this)->condition_order-simplex->vertices.size()-1; 102 99 103 100 // cout << "C:" << condition_order << " N:" << my_emlig->number_of_parameters << " C+N:" << condition_order-my_emlig->number_of_parameters << endl; … … 147 144 148 145 base_vertex = (*base_ref); 149 150 151 // cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl; 146 147 //cout << "Base coords: " << base_vertex->get_coordinates() << endl; 148 //cout << "Condition: " << as_toprow->condition_sum << endl; 149 //pause(10); 152 150 153 151 a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition_sum[0]; … … 340 338 else 341 339 { 340 cout << "Improper probability density." << endl; 342 341 return 0.0; 343 342 } -
applications/robust/robustlib.h
r1361 r1362 22 22 using namespace itpp; 23 23 24 const double max_range = 20;//numeric_limits<double>::max()/10e-10;24 const double max_range = 5;//numeric_limits<double>::max()/10e-10; 25 25 26 26 /// An enumeration of possible actions performed on the polyhedrons. We can merge them or split them. … … 740 740 int condition_order; 741 741 742 double last_log_nc; 743 742 744 743 745 … … 826 828 if(is_last) 827 829 { 828 if(parent_state == 1) 829 { 830 ((toprow*)current_parent)->condition_sum-=toremove->value; 831 } 832 833 if(parent_state == -1) 834 { 835 ((toprow*)current_parent)->condition_sum+=toremove->value; 830 if(level == number_of_parameters-1) 831 { 832 if(parent_state == 1) 833 { 834 ((toprow*)current_parent)->condition_sum-=toremove->value; 835 } 836 837 if(parent_state == -1) 838 { 839 ((toprow*)current_parent)->condition_sum+=toremove->value; 840 } 836 841 } 837 842 … … 964 969 current_parent->set_state(-1, SPLIT); 965 970 966 ((toprow*)current_parent)->condition_sum-=toadd->value; 971 if(level == number_of_parameters-1) 972 { 973 ((toprow*)current_parent)->condition_sum-=toadd->value; 974 } 967 975 968 976 } … … 971 979 current_parent->set_state(1, SPLIT); 972 980 973 ((toprow*)current_parent)->condition_sum+=toadd->value; 981 if(level == number_of_parameters-1) 982 { 983 ((toprow*)current_parent)->condition_sum+=toadd->value; 984 } 974 985 } 975 986 else … … 1044 1055 double log_nc; 1045 1056 1057 1058 1046 1059 vector<multiset<my_ivec>> correction_factors; 1047 1060 … … 1050 1063 /// A default constructor creates an emlig with predefined statistic representing only the range of the given 1051 1064 /// parametric space, where the number of parameters of the needed model is given as a parameter to the constructor. 1052 emlig(int number_of_parameters )1065 emlig(int number_of_parameters, bool is_proper, double soft_prior_parameter) 1053 1066 { 1054 1067 this->number_of_parameters = number_of_parameters; 1055 1068 1056 create_statistic(number_of_parameters); 1057 1058 min_ll = numeric_limits<double>::max(); 1059 1060 condition_order = 0; 1069 condition_order = number_of_parameters+2; 1070 1071 if(is_proper) 1072 condition_order++; 1073 1074 create_statistic(number_of_parameters, soft_prior_parameter); 1075 1076 //step_me(10); 1077 1078 min_ll = numeric_limits<double>::max(); 1079 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; 1088 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 } 1101 1061 1102 } 1062 1103 … … 1085 1126 { 1086 1127 1087 /*1128 1088 1129 if(i==statistic.size()-1) 1089 1130 { 1090 1131 cout << ((toprow*)horiz_ref)->condition_sum << " " << ((toprow*)horiz_ref)->probability << endl; 1132 cout << "Condition: " << ((toprow*)horiz_ref)->condition_sum << endl; 1091 1133 cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; 1092 1134 } 1093 */1135 1094 1136 1095 1137 // cout << "Stepped." << endl; … … 1212 1254 void add_and_remove_condition(vec toadd, vec toremove) 1213 1255 { 1256 1214 1257 //step_me(0); 1215 1258 normalization_factor = 0; … … 1717 1760 1718 1761 // cout << ((toprow*)current_polyhedron)->condition << endl << toadd << endl; 1719 1720 toprow* positive_poly = new toprow(((toprow*)current_polyhedron)->condition_sum+toadd, ((toprow*)current_polyhedron)->condition_order+1); 1721 toprow* negative_poly = new toprow(((toprow*)current_polyhedron)->condition_sum-toadd, ((toprow*)current_polyhedron)->condition_order+1); 1762 vec cur_pos_condition = ((toprow*)current_polyhedron)->condition_sum; 1763 vec cur_neg_condition = ((toprow*)current_polyhedron)->condition_sum; 1764 1765 if(k == number_of_parameters) 1766 { 1767 cur_pos_condition = cur_pos_condition + toadd; 1768 cur_neg_condition = cur_neg_condition - toadd; 1769 } 1770 1771 toprow* positive_poly = new toprow(cur_pos_condition, ((toprow*)current_polyhedron)->condition_order+1); 1772 toprow* negative_poly = new toprow(cur_neg_condition, ((toprow*)current_polyhedron)->condition_order+1); 1722 1773 1723 1774 positive_poly->my_emlig = this; … … 1835 1886 log_nc = log(normalization_factor) + logfact(condition_order-number_of_parameters-2); 1836 1887 1888 1889 cout << "part1: " << log(normalization_factor) << endl; 1890 cout << "part2: " << logfact(condition_order-number_of_parameters-2) << endl; 1891 pause(1); 1892 1893 1837 1894 /* 1838 1895 for(polyhedron* topr_ref = statistic.rows[statistic.size()-1];topr_ref!=statistic.row_ends[statistic.size()-1]->next_poly;topr_ref=topr_ref->next_poly) … … 1842 1899 */ 1843 1900 1844 step_me(101);1901 // step_me(101); 1845 1902 1846 1903 } … … 2403 2460 2404 2461 /// A method for creating plain default statistic representing only the range of the parameter space. 2405 void create_statistic(int number_of_parameters )2462 void create_statistic(int number_of_parameters, double soft_prior_parameter) 2406 2463 { 2407 2464 /* … … 2448 2505 // of newly added parameter. Therefore they will have all coordinates except the last one zero. We get the 2449 2506 // right amount of zero cooridnates by reading them from the origin 2450 vec origin_coord = origin->get_coordinates(); 2507 vec origin_coord = origin->get_coordinates(); 2508 2509 2451 2510 2452 2511 // And we incorporate the nonzero coordinates into the new cooordinate vectors … … 2534 2593 // this condition will be a vector of zeros. There are two vectors, because we need two copies of 2535 2594 // the original Hasse diagram. 2536 vec vec1(number_of_parameters+1); 2537 vec1.zeros(); 2538 2539 vec vec2(number_of_parameters+1); 2540 vec2.zeros(); 2595 vec vec1; 2596 vec vec2; 2597 if(!horiz_ref->kids_rel_addresses.empty()) 2598 { 2599 vec1 = ((toprow*)horiz_ref)->condition_sum; 2600 vec1.ins(vec1.size(),-soft_prior_parameter); 2601 2602 vec2 = ((toprow*)horiz_ref)->condition_sum; 2603 vec2.ins(vec2.size(),soft_prior_parameter); 2604 } 2605 else 2606 { 2607 vec1.ins(0,-soft_prior_parameter); 2608 vec2.ins(0,soft_prior_parameter); 2609 2610 vec1.ins(0,-1); 2611 vec2.ins(0,-1); 2612 } 2613 2614 cout << vec1 << endl; 2615 cout << vec2 << endl; 2616 2541 2617 2542 2618 // We create a new toprow with the previously specified condition. 2543 toprow* current_copy1 = new toprow(vec1, 0);2544 toprow* current_copy2 = new toprow(vec2, 0);2619 toprow* current_copy1 = new toprow(vec1, this->condition_order); 2620 toprow* current_copy2 = new toprow(vec2, this->condition_order); 2545 2621 2546 2622 current_copy1->my_emlig = this; … … 2715 2791 this->has_constant = has_constant; 2716 2792 2717 posterior = new emlig(number_of_parameters );2793 posterior = new emlig(number_of_parameters,true,0.001); 2718 2794 2719 2795 this->window_size = window_size;