#include "sampling.h" #include //rand() srand() #include //time() #include //swap #include using namespace std; void Sampling::Init(fx_module *module, int *num_of_people, Vector *ind_unknown_x, double *initial_percent_sample, Vector *initial_parameter) { module_=module; const char *data_file1=fx_param_str_req(module_, "data1"); const char *info_file1=fx_param_str_req(module_, "info1"); Matrix x; data::Load(data_file1, &x); //num_of_betas_=x.n_rows(); Matrix info1; data::Load(info_file1, &info1); num_of_people_=info1.n_cols(); *num_of_people=num_of_people_; population_first_stage_x_.Init(num_of_people_); index_t start_col=0; for(index_t i=0; iCopy(population_ind_unknown_x_); if (fx_param_exists(module_, "starting_points")) { const char *initial_parameter_file=fx_param_str_req(module_,"stating_points"); Matrix mtx_initial_parameter; data::Load(initial_parameter_file, &mtx_initial_parameter); if(mtx_initial_parameter.n_rows() != x.n_rows()){ NOTIFY("The number of starting points given is not same as the number of parameters"); NOTIFY("Use default..."); initial_parameter->Init(x.n_rows()+2); //beta+p+q initial_parameter->SetZero(); } //if mtx_initial_parameter.MakeColumnVector(0, initial_parameter); } //if else { NOTIFY("Starting points are not given. Use default..."); initial_parameter->Init(x.n_rows()+2); initial_parameter->SetZero(); } //const char *initial_parameter_file=fx_param_str(module_, "stating_points", "default_initial.csv"); /*if(initial_parameter_file !=NULL) { Matrix mtx_initial_parameter; data::Load(initial_parameter_file, &mtx_initial_parameter); mtx_initial_parameter.MakeColumnVector(0, initial_parameter); } else { NOTIFY("Starting points are not given. Use default..."); initial_parameter->Init(x.n_rows()); initial_parameter->SetZero(); } */ /*Matrix mtx_initial_parameter; data::Load(initial_parameter_file, &mtx_initial_parameter); if(mtx_initial_parameter.n_rows()==1 && mtx_initial_parameter.get(0,0)==0){ NOTIFY("Starting points are not given. Use default..."); initial_parameter->Init(x.n_rows()); initial_parameter->SetZero(); } else if(mtx_initial_parameter.n_rows() != x.n_rows()){ FATAL("The number of starting points given is not same as the number of parameters"); } else { mtx_initial_parameter.MakeColumnVector(0, initial_parameter); } */ double arg_initial_percent_sample=fx_param_double(module_, "initial_percent_sample", 5); //Initilize memeber variables num_of_selected_sample_=0; count_num_sampling_=0; initial_percent_sample_=arg_initial_percent_sample; *initial_percent_sample=initial_percent_sample_; shuffled_array_.Init(num_of_people_); //return num_of_people_; } void Sampling::Shuffle() { //check - can be done in initilization int random =0; for(index_t i=0; i *added_first_stage_x, ArrayList *added_second_stage_x, ArrayList *added_unknown_x_past, ArrayList *added_first_stage_y, Vector *ind_unknown_x) { */ void Sampling::ExpandSubset(double percent_added_sample, ArrayList *added_first_stage_x, ArrayList *added_second_stage_x, ArrayList *added_unknown_x_past, ArrayList *added_first_stage_y) { int num_added_sample=0; //int old_num_selected_sample=num_of_selected_sample_; /*if(count_num_sampling_==0) { num_add_sample=math::RoundInt((num_of_people_)*(percent_added_sample)); if(num_add_sample==0) { NOTIFY("number of sample to add is zero. start with Two samples."); num_add_sample=2; } } else { num_add_sample=math::RoundInt((num_of_selected_sample_)*(percent_added_sample)); } //else */ if(num_of_selected_sample_==0) { NOTIFY("Initial sampling..."); cout<<"initial_percent_sample_="< num_of_people) { NOTIFY("number of sample to add exceeds total number of data points. Use all data"); } //if //Copy to currect Subset //added_first_stage_x->Init(); //added_second_stage_x->Init(); //added_unknown_x_past->Init(); //added_first_stage_y->Init(); //ind_unknown_x->CopyValues(population_ind_unknown_x_); if(num_added_sample+num_of_selected_sample_ >= num_of_people_){ for(index_t i=num_of_selected_sample_; iPushBackCopy(population_first_stage_x_[shuffled_array_[i]]); added_second_stage_x->PushBackCopy(population_second_stage_x_[shuffled_array_[i]]); added_unknown_x_past->PushBackCopy(population_unknown_x_past_[shuffled_array_[i]]); added_first_stage_y->PushBackCopy(population_first_stage_y_[shuffled_array_[i]]); } //i num_of_selected_sample_=num_of_people_; NOTIFY("All data are used"); } else { for(index_t i=num_of_selected_sample_; i<(num_of_selected_sample_+num_added_sample); i++){ added_first_stage_x->PushBackCopy(population_first_stage_x_[shuffled_array_[i]]); added_second_stage_x->PushBackCopy(population_second_stage_x_[shuffled_array_[i]]); added_unknown_x_past->PushBackCopy(population_unknown_x_past_[shuffled_array_[i]]); added_first_stage_y->PushBackCopy(population_first_stage_y_[shuffled_array_[i]]); } //i num_of_selected_sample_+=num_added_sample; } //else //DEBUG_SAME_SIZE(sample_selector->size(), num_selected_sample); /*DEBUG_ASSERT_MSG(added_first_stage_x->size()==num_added_sample, "Size of added first stage x is not same as number of added sample %i != %i", added_first_stage_x->size(), num_added_sample); */ count_num_sampling_+=1; NOTIFY("Extend subset (%d)", count_num_sampling_); cout<<"num_added_sample="<