Changeset 1275
- Timestamp:
- 02/16/11 20:38:48 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1272 r1275 11 11 using namespace itpp; 12 12 13 using namespace bdm;13 //using namespace bdm; 14 14 15 const int emlig_size = 4;15 const int emlig_size = 2; 16 16 17 17 … … 39 39 }*/ 40 40 41 vec condition1 = "0.3 1.0 1.0"; 42 emlig1->add_condition(condition1); 41 43 42 //emlig1->step_me(0); 44 vec condition2 = "-0.5 -1.0 1.0"; 45 emlig1->add_condition(condition2); 43 46 47 //vec condition3 = "-0.3 0.5 0.5"; 48 //emlig1->add_condition(condition3); 49 50 // emlig1->step_me(0); 51 52 //emlig1->remove_condition(condition1); 53 54 55 56 57 58 /* 44 59 for(int i = 0;i<500;i++) 45 60 { … … 65 80 } 66 81 */ 67 82 /* 68 83 cout << emlig1->statistic_rowsize(emlig_size) << endl << endl; 69 84 … … 84 99 } 85 100 */ 86 } 101 //} 102 87 103 88 104 -
applications/robust/robustlib.cpp
r1273 r1275 33 33 double toprow::integrate_simplex(set<vertex*> simplex, char c) 34 34 { 35 int condition_order = ((toprow*)this)->condition_order-1; 35 // cout << ((toprow*)this)->condition << endl; 36 37 int condition_order = ((toprow*)this)->condition_order+1; // -2 by bylo, pokud chceme uniformni apriorno 36 38 37 39 // cout << "C:" << condition_order << " N:" << my_emlig->number_of_parameters << " C+N:" << condition_order-my_emlig->number_of_parameters << endl; 38 40 // pause(0.1); 39 41 40 if(condition_order-my_emlig->number_of_parameters > =0)42 if(condition_order-my_emlig->number_of_parameters > 0) 41 43 { 44 45 cout << endl; 46 cout << ((toprow*)this)->condition << endl; 47 cout << "C:" << condition_order << " N:" << my_emlig->number_of_parameters << " C+N:" << condition_order-my_emlig->number_of_parameters << endl; 48 42 49 emlig* current_emlig; 43 50 … … 55 62 vec cur_condition = as_toprow->condition.get(1,as_toprow->condition.size()-1); 56 63 57 // cout << as_toprow->condition << endl; 58 59 vertex* base_vertex = (*simplex.begin()); 64 // cout << as_toprow->condition << endl; 60 65 61 66 int dimension = simplex.size()-1; 62 67 63 mat jacobian(dimension,dimension); 64 65 // cout << base_vertex->get_coordinates() << endl; 66 67 double a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition[0]; 68 mat jacobian(dimension,dimension); 69 70 double a_0; 68 71 map<double,int> as; 69 70 int row_count = 0; 71 for(set<vertex*>::iterator vert_ref = (++simplex.begin()); vert_ref!=simplex.end();vert_ref++) 72 { 73 vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates(); 74 75 // cout << (*vert_ref)->get_coordinates() << endl; 76 // cout << relative_coords << endl; 77 78 jacobian.set_row(row_count,relative_coords); 79 80 double new_a = relative_coords*cur_condition; 81 82 pair<map<double,int>::iterator,bool> returned = as.insert(pair<double,int>(new_a,1)); 83 if(returned.second == false) 84 { 85 (*returned.first).second++; 72 vertex* base_vertex; 73 set<vertex*>::iterator base_ref = simplex.begin(); 74 bool order_correct; 75 76 77 do 78 { 79 order_correct = true; 80 as.clear(); 81 82 base_vertex = (*base_ref); 83 84 cout << "Base coords:" << base_vertex->get_coordinates() << endl; 85 86 a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition[0]; 87 88 int row_count = 0; 89 for(set<vertex*>::iterator vert_ref = simplex.begin(); vert_ref!=simplex.end();vert_ref++) 90 { 91 if(vert_ref != base_ref) 92 { 93 vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates(); 94 95 96 97 jacobian.set_row(row_count,relative_coords); 98 99 double new_a = relative_coords*cur_condition; 100 101 if(new_a + a_0 == 0) 102 { 103 base_ref++; 104 105 if(base_ref == simplex.end()) 106 { 107 throw new exception("Equal local conditions are paired. If this ever occurs, the software has to be modified to include multiplied a_0!!"); 108 } 109 110 order_correct = false; 111 112 break; 113 } 114 115 cout << "Absolute coords:(V" << row_count << ")" << (*vert_ref)->get_coordinates() << endl; 116 //cout << "Relative coords:(V" << row_count << ")" << relative_coords << endl; 117 118 pair<map<double,int>::iterator,bool> returned = as.insert(pair<double,int>(new_a,1)); 119 if(returned.second == false) 120 { 121 (*returned.first).second++; 122 } 123 /* 124 else 125 { 126 cout << "a[" << row_count << "] = " << new_a << endl; 127 } 128 */ 129 130 //as.ins(as.size(),new_a); 131 132 row_count++; 133 } 86 134 } 87 /*88 else89 {90 cout << "a[" << row_count << "] = " << new_a << endl;91 }92 */93 94 //as.ins(as.size(),new_a);95 96 row_count++;97 135 } 98 136 while(!order_correct); 99 137 100 138 … … 107 145 for(map<double,int>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++) 108 146 { 109 double multiplier = det_jacobian; 110 111 if(a_0!=(*as_ref).first) 112 { 113 int as1_order = (*as_ref).second; 147 double multiplier = det_jacobian; 148 149 int as1_order = (*as_ref).second; 150 151 correction_term /= -pow((*as_ref).first,as1_order); 152 153 current_emlig->set_correction_factors(as1_order); 154 155 vector<double> factors; 156 int number_of_factors = 0; 157 for(map<double,int>::iterator as2_ref = as.begin();as2_ref!=as.end();as2_ref++) 158 { 114 159 115 correction_term /= -pow((*as_ref).first,as1_order); 160 if(as2_ref!=as_ref) 161 { 162 for(int k = 0;k<(*as2_ref).second;k++) 163 { 164 factors.push_back((*as_ref).first-(*as2_ref).first); 165 } 166 167 multiplier /= pow((*as_ref).first-(*as2_ref).first,(*as2_ref).second); 168 number_of_factors += (*as2_ref).second; 169 } 170 else 171 { 172 factors.push_back((*as_ref).first); 173 174 multiplier /= (*as_ref).first; 175 number_of_factors += 1; 176 } 116 177 117 current_emlig->set_correction_factors(as1_order); 118 119 vector<double> factors; 120 int number_of_factors = 0; 121 for(map<double,int>::iterator as2_ref = as.begin();as2_ref!=as.end();as2_ref++) 122 { 123 124 if(as2_ref!=as_ref) 125 { 126 for(int k = 0;k<(*as2_ref).second;k++) 127 { 128 factors.push_back((*as_ref).first-(*as2_ref).first); 129 } 130 131 multiplier /= pow((*as_ref).first-(*as2_ref).first,(*as2_ref).second); 132 number_of_factors += (*as2_ref).second; 133 } 134 else 135 { 136 factors.push_back((*as_ref).first); 137 138 multiplier /= (*as_ref).first; 139 number_of_factors += 1; 140 } 141 142 } 143 144 double bracket = fact(condition_order-number_of_factors)/fact(as1_order-1)/pow(a_0+(*as_ref).first,condition_order-number_of_factors+1); 145 for(int k = 0;k < as1_order-1;k++) 146 { 147 double bracket_factor = pow((double)-1,k+1)*fact(condition_order-1-number_of_factors-k)/fact(as1_order-2-k)/pow(a_0+(*as_ref).first,condition_order-number_of_factors-k); 148 149 for(set<my_ivec>::iterator combi_ref = this->my_emlig->correction_factors[k].begin();combi_ref!=this->my_emlig->correction_factors[k].end();combi_ref++) 150 { 151 double bracket_combination = 1; 152 for(int j = 0;j<(*combi_ref).size();j++) 153 { 154 bracket_combination /= factors[(*combi_ref)[j]]; 155 } 156 157 bracket+=bracket_factor*bracket_combination; 158 } 159 } 160 178 } 179 180 double bracket = fact(condition_order-number_of_factors)/fact(as1_order-1)/pow(a_0+(*as_ref).first,condition_order-number_of_factors); 181 for(int k = 0;k < as1_order-1;k++) 182 { 183 double bracket_factor = pow((double)-1,k+1)*fact(condition_order-number_of_factors-k)/fact(as1_order-2-k)/pow(a_0+(*as_ref).first,condition_order-number_of_factors-k); 161 184 162 163 int_value += multiplier*bracket; 185 for(set<my_ivec>::iterator combi_ref = this->my_emlig->correction_factors[k].begin();combi_ref!=this->my_emlig->correction_factors[k].end();combi_ref++) 186 { 187 double bracket_combination = 1; 188 for(int j = 0;j<(*combi_ref).size();j++) 189 { 190 bracket_combination /= factors[(*combi_ref)[j]]; 191 } 192 193 bracket+=bracket_factor*bracket_combination; 194 } 164 195 } 165 else 166 { 167 throw new exception("Should this happen? a_i=a_0 in the formula for integrating over a simplex! I think it can happen with 0 probability(when phi*2*v_0=phi*v_i)"); 168 } 196 197 198 199 int_value += multiplier*bracket; 200 169 201 } 170 202 … … 175 207 176 208 int_value += correction_term; 177 178 // cout << int_value << endl; 179 180 // cout << "***************************" << endl << endl; 181 209 210 211 cout << "Probability:" << int_value << endl; 212 182 213 return int_value; 214 215 183 216 184 217 } -
applications/robust/robustlib.h
r1273 r1275 822 822 for(polyhedron* horiz_ref = statistic.rows[i];horiz_ref!=statistic.get_end();horiz_ref=horiz_ref->next_poly) 823 823 { 824 if(i==statistic.size()-1) 825 { 826 cout << ((toprow*)horiz_ref)->condition << " " << ((toprow*)horiz_ref)->probability << endl; 827 cout << "Order:" << ((toprow*)horiz_ref)->condition_order << endl; 828 } 824 829 char* string = "Checkpoint"; 825 830 }