Changeset 1268 for applications/robust/robustlib.cpp
- Timestamp:
- 01/05/11 18:01:55 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/robustlib.cpp
r1262 r1268 20 20 if(should_integrate) 21 21 { 22 emlig* current_emlig; 23 24 if(this->my_emlig!=NULL) 25 { 26 current_emlig = this->my_emlig; 27 } 28 else 29 { 30 throw exception("The statistic of the polyhedron you are trying to integrate over doesn't belong to any emlig!"); 31 } 32 22 33 toprow* as_toprow = (toprow*)this; 23 34 … … 53 64 54 65 double int_value = 0; 66 double det_jacobian = det(jacobian); 55 67 for(map<double,int>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++) 56 68 { 57 int fac_order = ((toprow*)this)->condition_order-as.size()-1;69 int condition_order = ((toprow*)this)->condition_order-1; 58 70 59 double fac_value = 1;71 double multiplier = det_jacobian; 60 72 if(a_0!=(*as_ref).first) 61 { 62 //fac_value = ((double)tgamma(fac_order)*det(jacobian))/(*as_ref).first/pow((*as_ref).first-a_0,fac_order); 63 64 fac_value /= (*as_ref).first; 73 { 74 int as1_order = (*as_ref).second; 65 75 76 current_emlig->set_correction_factors(as1_order); 77 78 vector<double> factors; 79 int number_of_factors = 0; 66 80 for(map<double,int>::iterator as2_ref = as.begin();as2_ref!=as.end();as2_ref++) 67 81 { 82 68 83 if(as2_ref!=as_ref) 84 { 85 for(int k = 0;k<(*as2_ref).second;k++) 86 { 87 factors.push_back((*as_ref).first-(*as2_ref).first); 88 } 89 90 multiplier /= pow((*as_ref).first-(*as2_ref).first,(*as2_ref).second); 91 number_of_factors += (*as2_ref).second; 92 } 93 else 69 94 { 70 double current_factor = (*as_ref).first-(*as2_ref).first;95 factors.push_back((*as_ref).first); 71 96 72 fac_value /= current_factor; 97 multiplier /= (*as_ref).first; 98 number_of_factors += 1; 99 } 100 } 73 101 74 75 } 76 } 102 double bracket = fact(condition_order-1-number_of_factors)/fact(as1_order-1)/*/pow((*as_ref).first-a_0,condition_order-1-number_of_factors)*/; 103 for(int k = 0;k < as1_order-1;k++) 104 { 105 double bracket_factor = pow((double)-1,k+1)*fact(condition_order-2-number_of_factors-k)/fact(as1_order-2-k)/pow((*as_ref).first-a_0,condition_order-2-number_of_factors-k); 106 107 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++) 108 { 109 double bracket_combination = 1; 110 for(int j = 0;j<(*combi_ref).size();j++) 111 { 112 bracket_combination /= factors[(*combi_ref)[j]]; 113 } 114 115 bracket+=bracket_factor*bracket_combination; 116 } 117 } 118 119 int_value += multiplier*bracket; 120 77 121 } 78 122 else 79 123 { 80 124 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)"); 81 } 82 83 84 int_value += fac_value; 125 } 126 85 127 } 86 128