Changeset 1389 for applications/robust/robustlib.h
- Timestamp:
- 09/13/11 19:44:06 (13 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/robustlib.h
r1384 r1389 21 21 using namespace std; 22 22 using namespace itpp; 23 24 static Exponential_RNG ExpRNG; 23 25 24 26 const double max_range = 5;//numeric_limits<double>::max()/10e-10; … … 1372 1374 { 1373 1375 condition_to_add = new condition(toadd); 1374 conditions.push_back( new_condition);1376 conditions.push_back(condition_to_add); 1375 1377 } 1376 1378 … … 2618 2620 pair<double,double> probability_and_sigma = choose_sigma(condition_and_simplex.second); 2619 2621 2620 int dimension = condition_and_simplex.second->vertices.size()-1; 2621 2622 mat jacobian(dimension,dimension); 2623 vec gradient = condition_and_simplex.first.right(dimension); 2624 2625 vertex* base_vert = *condition_and_simplex.second->vertices.begin(); 2626 2627 //// cout << "Base vertex coords(should be close to est. param.): " << base_vert->get_coordinates() << endl; 2622 int dimension = condition_and_simplex.second->vertices.size(); 2623 2624 mat jacobian(dimension,dimension-1); 2625 vec gradient = condition_and_simplex.first; 2628 2626 2629 2627 int row_count = 0; 2630 2628 2631 for(set<vertex*>::iterator vert_ref = ++condition_and_simplex.second->vertices.begin();vert_ref!=condition_and_simplex.second->vertices.end();vert_ref++) 2632 { 2633 vec current_coords = (*vert_ref)->get_coordinates(); 2634 2635 //// cout << "Coords of vertex[" << row_count << "]: " << current_coords << endl; 2636 2637 vec relative_coords = current_coords-base_vert->get_coordinates(); 2638 2639 jacobian.set_row(row_count,relative_coords); 2640 2629 for(set<vertex*>::iterator vert_ref = condition_and_simplex.second->vertices.begin();vert_ref!=condition_and_simplex.second->vertices.end();vert_ref++) 2630 { 2631 jacobian.set_row(row_count,(*vert_ref)->get_coordinates()); 2641 2632 row_count++; 2642 } 2643 2644 //// cout << "Jacobian: " << jacobian << endl; 2645 2646 /// \todo Is this correct? Are the random coordinates really jointly uniform? I don't know. 2633 } 2634 2635 ExpRNG.setup(1); 2636 2647 2637 vec sample_coords; 2648 double sampl ing_diff = 1;2649 for(int j = 0;j< number_of_parameters;j++)2650 { 2651 double rnumber = randu()*sampling_diff;2652 2653 sample_ coords.ins(0,rnumber);2654 2655 sampl ing_diff -= rnumber;2638 double sample_sum = 0; 2639 for(int j = 0;j<dimension;j++) 2640 { 2641 double rnumber = ExpRNG(); 2642 2643 sample_sum += rnumber; 2644 2645 sample_coords.ins(0,rnumber); 2656 2646 } 2657 2647 2658 sample_coords = jacobian.T()*sample_coords+(*base_vert).get_coordinates(); 2648 sample_coords /= sample_sum; 2649 2650 sample_coords = jacobian.T()*sample_coords; 2659 2651 2660 2652 vec extended_coords = sample_coords; … … 2662 2654 2663 2655 double exponent = extended_coords*condition_and_simplex.first; 2664 double sample_prob = 1/ condition_and_simplex.second->probability/pow(probability_and_sigma.second,(int)conditions.size()-number_of_parameters+3)*exp((-1)/probability_and_sigma.second*exponent);2656 double sample_prob = 1/pow(probability_and_sigma.second,(int)conditions.size()-number_of_parameters+3)*exp((-1)/probability_and_sigma.second*exponent); 2665 2657 sample_prob *= probability_and_sigma.first; 2666 2658