void leapfrog(VECT r, VECT v, PVECT newr, PVECT newv, double dt) { VECT a0, a1; a0 = calc_acc(r); *newv = inc_with_scale(v, a0, dt*0.5); *newr = inc_with_scale(r, *newv, dt); a1 = calc_acc(*newr); *newv = inc_with_scale(*newv, a1, dt*0.5); }
//Func: in_thread() //This function is used in the call for pthread_create() //it calls other function and set up a mission for each thread void* in_thread(void *in_targv){ struct timeval t_start; struct timeval t_end; thread_argv *ad_targv = in_targv; thread_argv targv = *ad_targv; gettimeofday(&t_start,NULL); update_loc(targv.num_astr, ad_targv->astr, *(targv.t_info)); calc_f(targv.num_astr, ad_targv->astr, *(targv.t_info)); total_f(targv.num_astr, ad_targv->astr, *(targv.t_info)); calc_acc(targv.num_astr, ad_targv->astr, *(targv.t_info)); calc_velo(targv.num_astr, ad_targv->astr, *(targv.t_info), targv.t); calc_s(targv.num_astr, ad_targv->astr, *(targv.t_info), targv.t); // mutex_lock pls - I like to live dangerously gettimeofday(&t_end,NULL); ad_targv->proc_t = t_end.tv_usec - t_start.tv_usec; pthread_barrier_wait(&barrier); return NULL; }
float LR::classify_testing_file(string testing_file, string output_file, int output_format) { cout << "Classifying testing file..." << endl; vector<sparse_feat> test_feat_vec; vector<int> test_class_vec; vector<int> pred_class_vec; read_samp_file(testing_file, test_feat_vec, test_class_vec); ofstream fout(output_file.c_str()); for (size_t i = 0; i < test_class_vec.size(); i++) { int samp_class = test_class_vec[i]; sparse_feat samp_feat = test_feat_vec[i]; vector<float> pred_score = calc_score(samp_feat); int pred_class = score_to_class(pred_score); pred_class_vec.push_back(pred_class); fout << pred_class << "\t"<<samp_class<<"\t"; if (output_format == 1) { for (int j = 0; j < class_set_size; j++) { fout << j << ":" << pred_score[j] << ' '; } } else if (output_format == 2) { vector<float> pred_prb = score_to_prb(pred_score); for (int j = 0; j < class_set_size; j++) { fout << j << ":" << pred_prb[j] << ' '; } } fout << endl; } fout.close(); float acc = calc_acc(test_class_vec, pred_class_vec); return acc; }