void do_stuff() { float eyepoint[3], viewpoint[3]; int k; glEnable(GL_DEPTH_TEST); glClearColor(0.8, 0.6, 0.62, 1.0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 1); glUseProgram(0); for (k=0; k<3; k++) { eyepoint[k] = light0_position[k]; viewpoint[k] = light0_direction[k] + light0_position[k]; } view_volume(eyepoint, viewpoint); drawquads(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); save_matrix(eyepoint, viewpoint); glUseProgram(sprogram); set_uniform(sprogram); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, 1); eyepoint[0] = 1.0; eyepoint[1] = 2.0; eyepoint[2] = 2.0; viewpoint[0] = 0.0; viewpoint[1] = 0.0; viewpoint[2] = 0.0; view_volume(eyepoint, viewpoint); drawquads(); glutSwapBuffers(); }
// Code taken from Dr. Geist's handout void do_stuff() { float eyepoint[3], viewpoint[3]; int k; glEnable(GL_DEPTH_TEST); glClearColor(0.8,0.6,0.62,1.0); glBindFramebufferEXT(GL_FRAMEBUFFER,1); glUseProgram(0); for(k=0;k<3;k++){ eyepoint[k] = light0_position[k]; viewpoint[k] = light0_direction[k]+light0_position[k]; } view_volume(eyepoint,viewpoint, 0); lights(); aa_display(eyepoint,viewpoint); glBindFramebufferEXT(GL_FRAMEBUFFER,0); save_matrix(eyepoint,viewpoint); glUseProgram(sprogram); glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D,1); // Draw scene from the intended eye point, complete with shadows. eyepoint[0] = 1.0; eyepoint[1] = 2.0; eyepoint[2] = -5.0; viewpoint[0] = 0.0; viewpoint[1] = 0.0; viewpoint[2] = 0.0; view_volume(eyepoint,viewpoint, 0); lights(); aa_display(eyepoint,viewpoint); glutSwapBuffers(); }
void parameter_test(Tree &T, Model &Mod, long Nrep, long length, double eps, std::vector<double> &pvals, std::string data_prefix, bool save_mc_exact){ long iter; long i, r; double df, C; double distance, KL; KL=0; distance=0; double likel; Parameters Parsim, Par, Par_noperm; Alignment align; Counts data; double eps_pseudo = 0.001; // Amount added to compute the pseudo-counts. StateList sl; bool save_data = (data_prefix != ""); std::string output_filename; std::stringstream output_index; std::ofstream logfile; std::ofstream logdistfile; std::ofstream out_chi2; std::ofstream out_br; std::ofstream out_brPerc; std::ofstream out_pvals; std::ofstream out_pvals_noperm; std::ofstream out_qvals; std::ofstream out_bound; std::ofstream out_variances; std::ofstream out_qvalsComb; std::ofstream out_qvalsCombzscore; std::ofstream out_covmatrix; std::ofstream out_parest; std::ofstream out_parsim; std::vector<double> KLe; std::vector<std::vector<double> > chi2_array; // an array of chi2 for every edge. std::vector<std::vector<double> > mult_array; // an array of mult for every edge. std::vector<std::vector<double> > br_array; // an array of br. length for every edge. std::vector<std::vector<double> > br_arrayPerc; // an array of br. length for every edge. std::vector<std::vector<double> > cota_array; // an array of upper bounds of the diff in lengths for every edge. std::vector<std::vector<double> > pval_array; // an array of pvals for every edge. std::vector<std::vector<double> > pval_noperm_array; std::vector<std::vector<double> > qval_array; // an array of qvalues for every edge. std::vector<std::vector<double> > variances_array; // an array of theoretical variances. std::vector<std::vector<double> > parest_array; // array of estimated parameters std::vector<std::vector<double> > parsim_array; // array of simulation parameters // ci_binom ci_bin; // condfidence interval std::vector<std::vector<ci_binom> > CIbinomial ; // vector of CIs std::list<long> produced_nan; long npars = T.nedges*Mod.df + Mod.rdf; // Initializing pvals pvals.resize(T.nedges); // Initialize the parameters for simulation of K81 data for testing Par = create_parameters(T); Parsim = create_parameters(T); // Initializing data structures KLe.resize(T.nedges); pval_array.resize(T.nedges); pval_noperm_array.resize(T.nedges); qval_array.resize(T.nedges); chi2_array.resize(T.nedges); mult_array.resize(T.nedges); br_array.resize(T.nedges); br_arrayPerc.resize(T.nedges); cota_array.resize(T.nedges); variances_array.resize(npars); parest_array.resize(npars); parsim_array.resize(npars); // initialize to 0's for (i=0; i < T.nedges; i++) { pval_array[i].resize(Nrep, 0); pval_noperm_array[i].resize(Nrep, 0); qval_array[i].resize(Nrep, 0); chi2_array[i].resize(Nrep, 0); mult_array[i].resize(Nrep, 0); br_array[i].resize(Nrep, 0); br_arrayPerc[i].resize(Nrep, 0); cota_array[i].resize(Nrep, 0); } for(i=0; i < npars; i++) { variances_array[i].resize(Nrep, 0); parest_array[i].resize(Nrep, 0); parsim_array[i].resize(Nrep, 0); } // Information about the chi^2. df = Mod.df; C = get_scale_constant(Mod); if (save_data) { logfile.open((data_prefix + ".log").c_str(), std::ios::out); logfile << "model: " << Mod.name << std::endl; logfile << "length: " << length << std::endl; logfile << "eps: " << eps << std::endl; logfile << "nalpha: " << T.nalpha << std::endl; logfile << "leaves: " << T.nleaves << std::endl; logfile << "tree: " << T.tree_name << std::endl; logfile << std::endl; logdistfile.open((data_prefix + ".dist.log").c_str(), std::ios::out); out_chi2.open(("out_chi2-" + data_prefix + ".txt").c_str(), std::ios::out); out_br.open(("out_br-" + data_prefix + ".txt").c_str(), std::ios::out); out_brPerc.open(("out_brPerc-" + data_prefix + ".txt").c_str(), std::ios::out); out_pvals.open(("out_pvals-" + data_prefix + ".txt").c_str(), std::ios::out); out_pvals_noperm.open(("out_pvals_noperm-" + data_prefix + ".txt").c_str(), std::ios::out); out_qvals.open(("out_qvals-" + data_prefix + ".txt").c_str(), std::ios::out); out_variances.open(("out_variances-" + data_prefix + ".txt").c_str(), std::ios::out); out_parest.open(("out_params-est-" + data_prefix + ".txt").c_str(), std::ios::out); out_parsim.open(("out_params-sim-" + data_prefix + ".txt").c_str(), std::ios::out); out_bound.open(("out_bound-" + data_prefix + ".txt").c_str(), std::ios::out); out_qvalsComb.open(("out_qvalsComb-" + data_prefix + ".txt").c_str(), std::ios::out); out_qvalsCombzscore.open(("out_qvalsCombzscore-" + data_prefix + ".txt").c_str(), std::ios::out); out_parsim.precision(15); out_parest.precision(15); out_variances.precision(15); } // uncomment the 2 following lines if want to fix the parameters // random_parameters_length(T, Mod, Parsim); //random_data(T, Mod, Parsim, length, align); for (iter=0; iter < Nrep; iter++) { std::cout << "iteration: " << iter << " \n"; // Produces an alignment from random parameters random_parameters_length(T, Mod, Parsim); random_data(T, Mod, Parsim, length, align); get_counts(align, data); add_pseudocounts(eps_pseudo, data); // Saving data if (save_data) { output_index.str(""); output_index << iter; output_filename = data_prefix + "-" + output_index.str(); save_alignment(align, output_filename + ".fa"); save_parameters(Parsim, output_filename + ".sim.dat"); } // Runs the EM std::tie(likel, iter) = EMalgorithm(T, Mod, Par, data, eps); // If algorithm returns NaN skip this iteration. if (boost::math::isnan(likel)) { produced_nan.push_back(iter); continue; } copy_parameters(Par, Par_noperm); // Chooses the best permutation. guess_permutation(T, Mod, Par); distance = parameters_distance(Parsim, Par); // estimated counts: Par ; original: Parsim std::vector<double> counts_est; counts_est.resize(T.nalpha, 0); // calculate the cov matrix std::vector<std::vector<double> > Cov; Array2 Cov_br; full_MLE_covariance_matrix(T, Mod, Parsim, length, Cov); if(save_data) { save_matrix(Cov, output_filename + ".cov.dat"); } // Save the covariances in an array std::vector<double> param; std::vector<double> param_sim; param.resize(npars); param_sim.resize(npars); get_free_param_vector(T, Mod, Par, param); get_free_param_vector(T, Mod, Parsim, param_sim); for(i=0; i < npars; i++) { variances_array[i][iter] = Cov[i][i]; parsim_array[i][iter] = param_sim[i]; parest_array[i][iter] = param[i]; } std::vector<double> xbranca, xbranca_noperm, mubranca; double chi2_noperm; xbranca.resize(Mod.df); xbranca_noperm.resize(Mod.df); mubranca.resize(Mod.df); for (i=0; i < T.nedges; i++) { r = 0; // row to be fixed // Extracts the covariance matrix, 1 edge branch_inverted_covariance_matrix(Mod, Cov, i, Cov_br); get_branch_free_param_vector(T, Mod, Parsim, i, mubranca); get_branch_free_param_vector(T, Mod, Par, i, xbranca); get_branch_free_param_vector(T, Mod, Par_noperm, i, xbranca_noperm); chi2_array[i][iter] = chi2_mult(mubranca, xbranca, Cov_br); chi2_noperm = chi2_mult(mubranca, xbranca_noperm, Cov_br); pval_array[i][iter] = pvalue_chi2(chi2_array[i][iter], Mod.df); pval_noperm_array[i][iter] = pvalue_chi2(chi2_noperm, Mod.df); br_array[i][iter] = T.edges[i].br - branch_length(Par.tm[i], T.nalpha); br_arrayPerc[i][iter] = branch_length(Par.tm[i], T.nalpha)/T.edges[i].br; // Upper bound on the parameter distance using multinomial: // cota_array[i][iter] = bound_mult(Parsim.tm[i], Xm, length); // and using the L2 bound cota_array[i][iter] = branch_length_error_bound_mult(Parsim.tm[i], Par.tm[i]); out_br << br_array[i][iter] << " "; out_brPerc << br_arrayPerc[i][iter] << " "; out_bound << cota_array[i][iter] << " "; out_chi2 << chi2_array[i][iter] << " "; } out_chi2 << std::endl; out_bound << std::endl; out_br << std::endl; out_brPerc << std::endl; // Saves more data. if (save_data) { logfile << iter << ": " << distance << " " << KL << std::endl; save_parameters(Par, output_filename + ".est.dat"); logdistfile << iter << ": "; logdistfile << parameters_distance_root(Par, Parsim) << " "; for(int j=0; j < T.nedges; j++) { logdistfile << parameters_distance_edge(Par, Parsim, j) << " "; } logdistfile << std::endl; } } // close iter loop here // Correct the p-values for(i=0; i < T.nedges; i++) { BH(pval_array[i], qval_array[i]); //save them } if (save_mc_exact) { for(long iter=0; iter < Nrep; iter++) { for(long i=0; i < T.nedges; i++) { out_pvals << pval_array[i][iter] << " "; out_pvals_noperm << pval_noperm_array[i][iter] << " "; out_qvals << qval_array[i][iter] << " "; } out_pvals << std::endl; out_pvals_noperm << std::endl; out_qvals << std::endl; for(long i=0; i < npars; i++) { out_variances << variances_array[i][iter] << " "; out_parsim << parsim_array[i][iter] << " "; out_parest << parest_array[i][iter] << " "; } out_variances << std::endl; out_parsim << std::endl; out_parest << std::endl; } } // now combine the pvalues for(i=0; i < T.nedges; i++) { pvals[i] = Fisher_combined_pvalue(pval_array[i]); //using the Zscore it goes like this: pvals[i] = Zscore_combined_pvalue(pval_array[i]); if (save_mc_exact) { out_qvalsComb << pvals[i] << " " ; out_qvalsCombzscore << Zscore_combined_pvalue(pval_array[i]) << " "; } } // Close files if (save_data) { logdistfile.close(); logfile.close(); } if (save_mc_exact) { out_chi2.close(); out_bound.close(); out_variances.close(); out_parest.close(); out_parsim.close(); out_br.close(); out_brPerc.close(); out_pvals.close(); out_qvals.close(); out_qvalsComb.close(); out_qvalsCombzscore.close(); out_covmatrix.close(); } // Warn if some EM's produced NaN. if (produced_nan.size() > 0) { std::cout << std::endl; std::cout << "WARNING: Some iterations produced NaN." << std::endl; std::list<long>::iterator it; for (it = produced_nan.begin(); it != produced_nan.end(); it++) { std::cout << *it << ", "; } std::cout << std::endl; } }
void append_row(const vector<mpq_class> row, map <Type::InputType, vector< vector<mpq_class> > >& input_map, Type::InputType input_type) { vector<vector<mpq_class> > one_row(1,row); save_matrix(input_map,input_type,one_row); }
void save_empty_matrix(map<Type::InputType, vector<vector<mpq_class> > >& input_map, InputType input_type){ vector<vector<mpq_class> > M; save_matrix(input_map, input_type, M); }
map <Type::InputType, vector< vector<Integer> > > readNormalizInput (istream& in, OptionsHandler& options) { string type_string; long i,j; long nr_rows,nr_columns; InputType input_type; Integer number; ConeProperty::Enum cp; map<Type::InputType, vector< vector<Integer> > > input_map; typename map<Type::InputType, vector< vector<Integer> > >::iterator it; in >> std::ws; // eat up any leading white spaces int c = in.peek(); if ( c == EOF ) { cerr << "Error: Empty input file!" << endl; throw BadInputException(); } bool new_input_syntax = !std::isdigit(c); if (new_input_syntax) { long dim; while (in.peek() == '/') { skip_comment(in); in >> std::ws; } in >> type_string; if (!in.good() || type_string != "amb_space") { cerr << "Error: First entry must be \"amb_space\"!" << endl; throw BadInputException(); } in >> dim; if (!in.good() || dim <= 0) { cerr << "Error: Bad amb_space value!" << endl; throw BadInputException(); } while (in.good()) { in >> std::ws; // eat up any leading white spaces c = in.peek(); if (c == EOF) break; if (c == '/') { skip_comment(in); } else { in >> type_string; if (in.fail()) { cerr << "Error: Could not read type string!" << endl; throw BadInputException(); } if (std::isdigit(c)) { cerr << "Error: Unexpected number "<< type_string << " when expecting a type !" << endl; throw BadInputException(); } if (isConeProperty(cp, type_string)) { options.activateInputFileConeProperty(cp); continue; } if (type_string == "BigInt") { options.activateInputFileBigInt(); continue; } if (type_string == "total_degree") { input_type = Type::grading; save_matrix(input_map, input_type, type_string, vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),1))); continue; } if (type_string == "nonnegative") { input_type = Type::signs; save_matrix(input_map, input_type, type_string, vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),1))); continue; } input_type = to_type(type_string); if (type_is_vector(input_type)) { nr_rows = 1; in >> std::ws; // eat up any leading white spaces c = in.peek(); if (!std::isdigit(c) && c != '-') { string vec_kind; in >> vec_kind; if (vec_kind == "unit_vector") { long pos = 0; in >> pos; if (in.fail()) { cerr << "Error while reading " << type_string << " as a unit_vector form the input!" << endl; throw BadInputException(); } vector< vector<Integer> > e_i = vector< vector<Integer> >(1,vector<Integer>(dim+type_nr_columns_correction(input_type),0)); if (pos < 1 || pos > static_cast<long>(e_i[0].size())) { cerr << "Error while reading " << type_string << " as a unit_vector "<< pos <<" form the input!" << endl; throw BadInputException(); } pos--; // in input file counting starts from 1 e_i[0].at(pos) = 1; save_matrix(input_map, input_type, type_string, e_i); continue; } } } else { in >> nr_rows; } nr_columns = dim + type_nr_columns_correction(input_type); if(in.fail() || nr_rows < 0) { cerr << "Error while reading " << type_string << " (a "<<nr_rows<<"x"<<nr_columns<<" matrix) form the input!" << endl; throw BadInputException(); } vector< vector<Integer> > M(nr_rows,vector<Integer>(nr_columns)); for(i=0; i<nr_rows; i++){ for(j=0; j<nr_columns; j++) { in >> M[i][j]; } } save_matrix(input_map, input_type, type_string, M); }
void test_and_save(uint iter, configuration &conf, string &conffname, parameter<Tnet> &theparam, supervised_trainer<Tnet,Tdata,Tlabel> &thetrainer, labeled_datasource<Tnet,Tdata,Tlabel> &train_ds, labeled_datasource<Tnet,Tdata,Tlabel> &test_ds, classifier_meter &trainmeter, classifier_meter &testmeter, infer_param &infp, gd_param &gdp, string &shortname) { timer ttest; ostringstream wname, wfname; // // some code to average several random solutions // cout << "Testing..."; // if (original_tests > 1) cout << " (" << original_tests << " times)"; // cout << endl; // ttest.restart(); // for (uint i = 0; i < original_tests; ++i) { // if (test_only && original_tests > 1) { // // we obviously wanna test several random solutions // cout << "Initializing weights from random." << endl; // thenet.forget(fgp); // } // if (!no_training_test) // thetrainer.test(train_ds, trainmeter, infp); // thetrainer.test(test_ds, testmeter, infp); // cout << "testing_time="; ttest.pretty_elapsed(); cout << endl; // } // if (test_only && original_tests > 1) { // // display averages over all tests // testmeter.display_average(test_ds.name(), test_ds.lblstr, // test_ds.is_test()); // trainmeter.display_average(train_ds.name(), train_ds.lblstr, // train_ds.is_test()); // } cout << "Testing..." << endl; uint maxtest = conf.exists("max_testing") ? conf.get_uint("max_testing") :0; ttest.start(); if (!conf.exists_true("no_training_test")) thetrainer.test(train_ds, trainmeter, infp, maxtest); // test if (!conf.exists_true("no_testing_test")) thetrainer.test(test_ds, testmeter, infp, maxtest); // test cout << "testing_time="; ttest.pretty_elapsed(); cout << endl; // save samples picking statistics if (conf.exists_true("save_pickings")) { string fname; fname << "pickings_" << iter; train_ds.save_pickings(fname.c_str()); } // save weights and confusion matrix for test set wname.str(""); if (conf.exists("job_name")) wname << conf.get_string("job_name"); wname << "_net" << setfill('0') << setw(5) << iter; wfname.str(""); wfname << wname.str() << ".mat"; if (conf.exists_false("save_weights")) cout << "Not saving weights (save_weights set to 0)." << endl; else { cout << "saving net to " << wfname.str() << endl; theparam.save_x(wfname.str().c_str()); // save trained network cout << "saved=" << wfname.str() << endl; } // detection test if (conf.exists_true("detection_test")) { uint dt_nthreads = 1; if (conf.exists("detection_test_nthreads")) dt_nthreads = conf.get_uint("detection_test_nthreads"); timer dtest; dtest.start(); // copy config file and augment it and detect it string cmd, params; if (conf.exists("detection_params")) { params = conf.get_string("detection_params"); params = string_replaceall(params, "\\n", "\n"); } cmd << "cp " << conffname << " tmp.conf && echo \"silent=1\n" << "nthreads=" << dt_nthreads << "\nevaluate=1\nweights_file=" << wfname.str() << "\n" << params << "\" >> tmp.conf && detect tmp.conf"; if (std::system(cmd.c_str())) cerr << "warning: failed to execute: " << cmd << endl; cout << "detection_test_time="; dtest.pretty_elapsed(); cout << endl; } // set retrain to next iteration with current saved weights ostringstream progress; progress << "retrain_iteration = " << iter + 1 << endl << "retrain_weights = " << wfname.str() << endl; // save progress job::write_progress(iter + 1, conf.get_uint("iterations"), progress.str().c_str()); // save confusion if (conf.exists_true("save_confusion")) { string fname; fname << wname.str() << "_confusion_test.mat"; cout << "saving confusion to " << fname << endl; save_matrix(testmeter.get_confusion(), fname.c_str()); } #ifdef __GUI__ // display static supervised_trainer_gui<Tnet,Tdata,Tlabel> stgui(shortname.c_str()); static supervised_trainer_gui<Tnet,Tdata,Tlabel> stgui2(shortname.c_str()); bool display = conf.exists_true("show_train"); // enable/disable display uint ninternals = conf.exists("show_train_ninternals") ? conf.get_uint("show_train_ninternals") : 1; // # examples' to display bool show_train_errors = conf.exists_true("show_train_errors"); bool show_train_correct = conf.exists_true("show_train_correct"); bool show_val_errors = conf.exists_true("show_val_errors"); bool show_val_correct = conf.exists_true("show_val_correct"); bool show_raw_outputs = conf.exists_true("show_raw_outputs"); bool show_all_jitter = conf.exists_true("show_all_jitter"); uint hsample = conf.exists("show_hsample") ?conf.get_uint("show_hsample"):5; uint wsample = conf.exists("show_wsample") ?conf.get_uint("show_wsample"):5; if (display) { cout << "Displaying training..." << endl; if (show_train_errors) { stgui2.display_correctness(true, true, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui2.display_correctness(true, false, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_train_correct) { stgui2.display_correctness(false, true, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui2.display_correctness(false, false, thetrainer, train_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_val_errors) { stgui.display_correctness(true, true, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui.display_correctness(true, false, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } if (show_val_correct) { stgui.display_correctness(false, true, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); stgui.display_correctness(false, false, thetrainer, test_ds, infp, hsample, wsample, show_raw_outputs, show_all_jitter); } stgui.display_internals(thetrainer, test_ds, infp, gdp, ninternals); } #endif }
void main() { float smatrix[2][3]; /* for saving with save_vector, save_matrix, save_array */ float **dmatrix; /* for saving with save_vector, save_matrix2 */ float sloadmatrix[2][3]; /* for loading with load_in_vector, load_in_matrix, load_in_array */ float **dloadmatrix; /* for loading with load_vector, load_matrix */ register int i,j; int dim[2]; int save_dim[2]; save_dim[0] = 2; save_dim[1] = 3; dmatrix = (float **)malloc(save_dim[0]*sizeof(float*)); for(i=0;i<save_dim[0];i++) dmatrix[i] = (float*)malloc(save_dim[1]*sizeof(float)); printf("toy matrix:"); for(i=0; i<save_dim[0]; i++){ printf("\n"); for( j=0; j<save_dim[1]; j++){ dmatrix[i][j] = 1 + j - i + (i+0.6) * 0.12342346; smatrix[i][j] = 1 + j - i + (i+0.6) * 0.12342346; printf("%f ", dmatrix[i][j]); } } printf("\n\n"); save_matrix2 (dmatrix, "dbinary.mat", save_dim[0], save_dim[1]); save_packed_matrix2(dmatrix, "dpacked.mat", save_dim[0], save_dim[1]); save_ascii_matrix2 (dmatrix, "dascii.mat", save_dim[0], save_dim[1]); save_matrix ((float*)smatrix, "sbinary.mat", save_dim[0], save_dim[1]); save_packed_matrix((float*)smatrix, "spacked.mat", save_dim[0], save_dim[1]); save_ascii_matrix ((float*)smatrix, "sascii.mat", save_dim[0], save_dim[1]); printf("saved 6 matrices\n"); dloadmatrix = load_matrix("dbinary.mat", &dim[0], &dim[1]); printf("loaded binary dynamic matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", dloadmatrix[i][j]);} printf("\n\n"); dloadmatrix = load_matrix ("dpacked.mat" , &dim[0], &dim[1]); printf("loaded packed dynamic matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", dloadmatrix[i][j]);} printf("\n\n"); dloadmatrix = load_matrix ("dascii.mat", &dim[0], &dim[1]); printf("loaded ascii dynamic matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", dloadmatrix[i][j]);} printf("\n\n"); load_in_matrix((float *)sloadmatrix, "dbinary.mat", dim[0], dim[1]); printf("loaded binary static matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", sloadmatrix[i][j]);} printf("\n\n"); load_in_matrix ((float *)sloadmatrix, "dpacked.mat" , dim[0], dim[1]); printf("loaded packed static matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", sloadmatrix[i][j]);} printf("\n\n"); load_in_matrix ((float *)sloadmatrix, "dascii.mat", dim[0], dim[1]); printf("loaded ascii static matrix:"); for(i=0; i<dim[0]; i++){ printf("\n"); for( j=0; j<dim[1]; j++) printf("%f ", sloadmatrix[i][j]);} printf("\n"); }
int main(int argc, char ** argv) { int opt; char *out = NULL; char *in = NULL; char *inp = NULL; int amount = 0; int freq = 0; char *format; char *progname = argv[0]; while ((opt = getopt(argc,argv,"r:k:m:n:f:o:")) != -1) { switch(opt) { case 'r': in = optarg; break; case 'k': out = optarg; break; case 'm': inp = optarg; break; case 'n': amount = atoi(optarg); break; case 'f': freq = atoi(optarg); break; case 'o': format = optarg; break; default : printf("Bad parameters\n"); exit( EXIT_FAILURE ); } } if (optind < argc) { printf("Bad parameters\n"); printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n"); exit( EXIT_FAILURE ); } if(in == NULL) { printf("No input file name\n"); printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n"); exit( EXIT_FAILURE ); } if(inp == NULL) { printf("No image file name\n"); printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n"); exit( EXIT_FAILURE ); } if (format == NULL) { printf("No format name\n"); printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n"); exit( EXIT_FAILURE); } FILE *a = fopen(in,"r"); life_t main = malloc(sizeof*main); life_t pom = malloc(sizeof*pom); read_var(a,main); pom->rows = main->rows; pom->cols = main->cols; alloc_matrix(main); alloc_matrix(pom); read_matrix(a,main); int i,j,k; char name[100]; int n =freq; //FILE *b = fopen(out,"w"); char text[100]; for (i =0; i <= amount ; i++) { strcpy(name,inp); strcpy(text,out); if ( i == freq) { char number[10]; sprintf(number,"%d",i); strcat(name,number); strcat(name,format); strcat(text,number); freq += n; } game_life (main,pom,name); for (j = 0; j < main->rows; j++) { for ( k = 0 ; k< main->cols; k++) main->tab[j][k] = pom->tab[j][k]; } save_matrix(text,main); } return 0; }
int main(int arc, char**argv) { if (arc != 2) { print_trace(TRACE_ERROR, "Veuillez indiquer un fichier où stocker la matrice de calibration.\n"); return EXIT_FAILURE; } struct Matrix *matrice = create_matrix(NB_LIGNES,NB_COLONNES, NUM_CAPTORS); pthread_mutex_init(&mutexMatrice, NULL); for (uint8_t i = 0; i < NUM_CAPTORS; i++) { mesures[i] = calloc(200, sizeof(char)); } bdaddr_t controllerAdd, server1Mac, server2Mac, server3Mac, sensorMac; str2ba(btControllerAdd, &controllerAdd); str2ba(server1Add, &server1Mac); str2ba(server2Add, &server2Mac); str2ba(server3Add, &server3Mac); str2ba(sensorAdd, &sensorMac); hci_controller_t hci_controller = hci_open_controller(&controllerAdd, "MAIN_SERVER"); sensor = bt_device_create(sensorMac, PUBLIC_DEVICE_ADDRESS, NULL, "SENSOR_TAG"); server1 = bt_device_create(server1Mac, PUBLIC_DEVICE_ADDRESS, NULL, "SERVER_1"); server2 = bt_device_create(server2Mac, PUBLIC_DEVICE_ADDRESS, NULL, "SERVER_2"); server3 = bt_device_create(server3Mac, PUBLIC_DEVICE_ADDRESS, NULL, "SERVER_3"); hci_LE_clear_white_list(NULL, &hci_controller); hci_LE_add_white_list(NULL, &hci_controller, sensor); // Création des trois clients : l2cap_client_t clients[NUM_CAPTORS-1] = {0}; l2cap_client_create(&clients[0], &server1Mac, 0x1001, 500, NULL, &(send_req_func)); l2cap_client_create(&clients[1], &server2Mac, 0x1001, 500, NULL, &(send_req_func)); l2cap_client_create(&clients[2], &server3Mac, 0x1001, 500, NULL, &(send_req_func)); if (l2cap_client_connect(&clients[0]) != 0) { perror("client_connect : unable to connect client 1"); return EXIT_FAILURE; } if (l2cap_client_connect(&clients[1]) != 0) { perror("client_connect : unable to connect client 2"); return EXIT_FAILURE; } if (l2cap_client_connect(&clients[2]) != 0) { perror("client_connect : unable to connect client 3"); return EXIT_FAILURE; } fprintf(stderr, "\n-------------------\n"); fprintf(stderr, "----Calibration----\n"); fprintf(stderr, "-------------------\n"); pthread_t clients_threads[NUM_CAPTORS]; struct routine_data_t routine_data[NUM_CAPTORS]; for (uint8_t k = 0; k < NUM_CAPTORS; k++) { routine_data[k].timeout = 4500; routine_data[k].num_captor = k; routine_data[k].hci_controller = &hci_controller; routine_data[k].sensor = sensor; if (k < NUM_CAPTORS-1) { routine_data[k].client = &(clients[k]); } else { routine_data[k].client = NULL; } routine_data[k].matrice = matrice; } char command[20] = {0}; char *status; char retry = 0; for (uint8_t i = 0; i < NB_LIGNES; i++) { for (uint8_t j = 0; j < NB_COLONNES; j++) { scan: retry = 0; fprintf(stdout, "Position courante : %i, %i\n", i, j); scanf("%s", command); for (uint8_t k = 0; k < NUM_CAPTORS; k++) { routine_data[k].num_row = i; routine_data[k].num_col = j; pthread_create(&(clients_threads[k]), NULL, &(get_rssi_thread_routine), (void *)&routine_data[k]); } for (uint8_t k = 0; k < 4; k ++) { pthread_join(clients_threads[k], (void **)&status); retry = retry || *status; } if (retry) { print_trace(TRACE_WARNING, "Attention : impossible d'acquérir les mesures pour cette case, veuillez réessayer.\n"); goto scan; } } } // Fermeture des clients : // Envoie des demandes de fin de connexion : l2cap_client_send(&clients[0], 3000, CLIENT_CLOSE_CONNECTION); l2cap_client_send(&clients[1], 3000, CLIENT_CLOSE_CONNECTION); l2cap_client_send(&clients[2], 3000, CLIENT_CLOSE_CONNECTION); // Destruction des clients : l2cap_client_close(&clients[0]); l2cap_client_close(&clients[1]); l2cap_client_close(&clients[2]); display_matrix(matrice); save_matrix(argv[1], *matrice); pthread_mutex_destroy(&mutexMatrice); hci_close_controller(&hci_controller); display_hci_socket_list(hci_controller.sockets_list); bt_destroy_device_table(); }
void print_matrix(Matrix *matrix) { save_matrix(stdout, matrix); }