int main() { using fixed_size = gammatone::policy::channels::fixed_size < T, gammatone::policy::bandwidth::glasberg1990>; using fixed_overlap = gammatone::policy::channels::fixed_overlap < T, gammatone::policy::bandwidth::glasberg1990>; const auto cf1 = fixed_overlap::setup(fl,fh,step_factor).first; const auto cf2 = fixed_size::setup(fl,fh,cf1.size()).first; const auto cf3 = fixed_size::setup(fl,fh,30).first; const auto cf4 = fixed_overlap::setup(fl,fh,0.5).first; const auto cf5 = fixed_size::setup(fl,fh,50).first; Gnuplot gp; gp << ifstream(gpsetup).rdbuf() << endl << "set xlabel 'center frequency (Hz)'" << endl << "set ylabel '# channel'" << endl << "plot '-' u 1:2 w l ls 11 lw 2 t 'fixed overlap', " << " '-' u 1:2 w l ls 12 lw 1 t 'fixed size', " << " '-' u 1:2 w l ls 13 lw 1 t 'fixed size 30', " << " '-' u 1:2 w l ls 14 lw 1 t 'fixed overlap 0.5', " << " '-' u 1:2 w l ls 15 lw 1 t 'fixed size 50' " << endl; gp.send1d(make_pair(cf1,utils::range<int>(1,cf1.size()))); gp.send1d(make_pair(cf2,utils::range<int>(1,cf2.size()))); gp.send1d(make_pair(cf3,utils::range<int>(1,cf3.size()))); gp.send1d(make_pair(cf4,utils::range<int>(1,cf4.size()))); gp.send1d(make_pair(cf5,utils::range<int>(1,cf5.size()))); return 0; }
int main(int argc, char** argv) { using std::get; using std::cout; using std::endl; // init the chrono for repeating 1000 times chrono c(100); // setup test input signal // const std::vector<scalar> input = utils::pulse<scalar>(size); const std::vector<scalar> input = utils::random<scalar>(-1.0, 1.0, size); // estimate computing time for each core type std::vector<result_type> res; res.push_back(c.process(input,get<0>(cores))); res.push_back(c.process(input,get<1>(cores))); res.push_back(c.process(input,get<2>(cores))); // plot computing time in function of center frequency for all cores Gnuplot gp; gp << std::ifstream(gpsetup).rdbuf() << std::endl << "set xlabel 'center frequency (Hz)'" << std::endl << "set ylabel 'processing time (ms)'" << std::endl << "plot "; gp << "'-' u 1:2 w l ls 11 t '" << res[0].name << "', " << "'-' u 1:2 w l ls 12 t '" << res[1].name << "', " << "'-' u 1:2 w l ls 13 t '" << res[2].name << "'" << std::endl; gp.send1d(std::make_pair(fc,res[0].mean)); gp.send1d(std::make_pair(fc,res[1].mean)); gp.send1d(std::make_pair(fc,res[2].mean)); // // get faster core // std::vector<scalar> t(res.size()); // std::transform(res.begin(),res.end(),t.begin(),[&](const auto& x){return get<1>(x);}); // scalar min_time = *std::min_element(t.begin(),t.end()); // // compute relative results // std::vector<scalar> relative(res.size()); // std::transform(res.begin(),res.end(),relative.begin(),[&](const auto& x){return get<1>(x)/min_time;}); // display results std::size_t idx = nbc/2; cout << "duration = " << duration*1e3 << " ms, " << "center frequency = " << fc[idx] << ", repetitions = " << c.repeat() << endl; std::for_each(res.begin(),res.end(),[&](const result_type& x) {cout << x.name << ": " // core type << x.mean[idx] // computing time << " ms " << endl;}); // in microsecond return 0; }
void plot(const std::string& setup,const T& freq, const T& d1, const T& d2, const T& d3) { Gnuplot gp; gp << setup << "plot '-' u 1:2 w l ls 11 t'glasberg1990', " << " '-' u 1:2 w l ls 12 t'slaney1988', " << " '-' u 1:2 w l ls 13 t'greenwood1990'" << std::endl; gp.send1d(make_pair(freq,d1)); gp.send1d(make_pair(freq,d2)); gp.send1d(make_pair(freq,d3)); }
void population_plot_pareto_fronts(const pagmo::population &pop, double maxDeltaV) { std::vector<std::vector<pagmo::population::size_type> > p_list = pop.compute_pareto_fronts(); Gnuplot gp; std::vector<boost::tuple<double, double> > d; double min_x = DBL_MAX, max_x = 0; double min_y = DBL_MAX, max_y = 0; for (int i = 0; i < p_list.size(); ++i) { std::vector<pagmo::population::size_type> f = p_list[i]; for (int j = 0; j < p_list[i].size(); ++j) { double x = pop.get_individual(f[j]).cur_f[0]; double y = pop.get_individual(f[j]).cur_f[1]; d.push_back(boost::make_tuple(x, y)); if (maxDeltaV != -1 && x > maxDeltaV) continue; if (x < min_x) min_x = x; if (x > max_x) max_x = x; if (y < min_y) min_y = y; if (y > max_y) max_y = y; } } gp << "set xrange [" << (min_x * 0.9) << ":" << max_x * 1.1 << "]\nset yrange [" << min_y * 0.9 << ":" << max_y * 1.1 << "]\n"; gp << "plot '-' with points ps 1 title 'Pareto Fronts'\n"; gp.send1d(d); }
int main(int argc, char** argv) { // creation of Ma and Flax gammatone filters filter1 f1(sample_frequency,center_frequency); filter2 f2(sample_frequency,center_frequency); filter3 f3(sample_frequency,center_frequency); // impulse responses computation using ir = gammatone::detail::impulse_response; const auto t = ir::time(f1.sample_frequency(),duration); vector<pair<vector<T>,string> > ir_data; ir_data.push_back(make_pair(ir::theorical( f1,t.begin(),t.end()), "theorical")); ir_data.push_back(make_pair(ir::implemented(f1,t.begin(),t.end()), "ma")); ir_data.push_back(make_pair(ir::implemented(f2,t.begin(),t.end()), "flax")); ir_data.push_back(make_pair(ir::implemented(f3,t.begin(),t.end()), "convolution")); cout << " ma : " << tostring(f1, ir_data[1].first) << endl; cout << "flax : " << tostring(f2, ir_data[2].first) << endl; cout << "conv : " << tostring(f3, ir_data[3].first) << endl; cout << " " << "Theorical max = " << gammatone::detail::absmax(ir_data[0].first.begin(),ir_data[0].first.end()) << endl; // IR normalization bool norm = true; if(norm) for(auto& d:ir_data) gammatone::detail::normalize(d.first.begin(),d.first.end()); // Compute MSE on normalized data //const auto mse = compute_mse(ir_data, true); // generate gnuplot command stringstream cmd; cmd << std::ifstream(gpsetup).rdbuf() << std::endl << "set xlabel 'time (s)'" << std::endl << "set ylabel 'amplitude'" << std::endl << "set xrange [0:"<<duration<<"]" << std::endl << "plot "; size_t i = 0; for(const auto& d:ir_data) { cmd << "'-' u 1:2 with line ls "<< 11+i << " lw " << 3-i << " title '" << d.second << "', "; i++; } // send gnuplot data Gnuplot gp; gp << cmd.str().substr(0,cmd.str().size()-2) << std::endl; // rm the last 2 characters (= ' ,') for(const auto& d:ir_data) gp.send1d(make_pair(t,d.first)); return 0; }
int main() { Gnuplot gp; std::vector<double> x; std::vector<double> sinx; for(int i=0;i<360;i++) { double xTemp=i*3.14/180; x.push_back(xTemp); double sinxTemp = sin(xTemp); sinx.push_back(sinxTemp); } gp << "plot '-' with lines\n"; gp.send1d(sinx); }
void plot3D(std::vector<std::vector<std::vector<double> > > datas, std::vector<std::string> names, const std::string xlabel, const std::string ylabel, const std::string zlabel, const std::string style) { Gnuplot gp; gp << "reset\n"; gp << "set xlabel '" << xlabel << "'\n"; gp << "set ylabel '" << ylabel << "'\n"; gp << "set zlabel '" << zlabel << "'\n"; // z-Achsen Offset ausschalten gp << "set ticslevel 0\n"; gp << "set tics out nomirror\n"; gp << "set autoscale\n"; gp << "set view equal xyz\n"; gp << "set key noenhanced\n"; // Farben std::vector<std::string> colors = getColors(); // Plotstring bauen und an Gnuplot schicken std::stringstream plotstring; plotstring << "splot "; for (unsigned i = 0; i < datas.size(); i++) { plotstring << "'-' " << style << " lt rgb '" << colors[i] << "' t '" << names[i] << "'"; if (i != datas.size() - 1) { plotstring << ","; } } gp << plotstring.str() << "\n"; // Daten senden for (std::vector<std::vector<std::vector<double> > >::iterator data = datas.begin(); data != datas.end(); ++data) { gp.send1d(*data); } std::cout << "Continue with Enter." << std::endl; std::cin.get(); }
Chromosome<T>* EA<T>::evolveThreaded(unsigned int generations, unsigned int threads) { Gnuplot fitnessPlot; std::ofstream fitnessFile; fitnessFile.open("fitness_funtion.cvs", std::ios::trunc); fitnessFile << "Generation,Fitness value,"; for (unsigned int gen_number = 0; gen_number < population[0]->getChromosome().size(); ++gen_number) fitnessFile << "Gen " << gen_number << ","; fitnessFile << std::endl; fitnessValuesMax.clear(); for (unsigned int i = 0; i < generations; i++) { generation++; std::cout << "Generation " << generation; evaluateThreaded(threads); std::cout << " evaluated." << std::endl; select(); reproduce(); replace(); fitnessValuesMax.push_back(std::make_pair(generation, selected[0]->getFitness())); fitnessFile << generation << "," << selected[0]->getFitness(); for (auto gen : selected[0]->getChromosome()) fitnessFile << "," << gen; fitnessFile << std::endl; } evaluateThreaded(threads); fitnessFile.close(); int best_index = 0; double max = 0; for (unsigned int i = 0; i < population.size(); i++) { if (population[i]->getFitness() > max) { max = population[i]->getFitness(); best_index = i; } } //fitnessPlot << "set fitnessValuesMax [-2:2]\nset yrange [-2:2]\n"; fitnessPlot << "plot '-' with lines title 'Fitness values'\n"; fitnessPlot.send1d(fitnessValuesMax); return population[best_index]; }
void plot1D(std::vector<std::vector<std::vector<double> > > data, std::vector<std::string> names, const std::string xlabel, const std::string ylabel, const std::string style) { Gnuplot gp; gp << "reset\n"; gp << "set xlabel '" << xlabel << "'\n"; gp << "set ylabel '" << ylabel << "'\n"; gp << "set key noenhanced\n"; // Farben std::vector<std::string> colors = getColors(); // Plotstring bauen und an Gnuplot schicken std::stringstream plotstring; plotstring << "plot "; for (unsigned i = 0; i < data.size(); i++) { plotstring << "'-' " << style << " lt rgb '" << colors[i] << "' t '" << names[i] << "'"; if (i != data.size() - 1) { plotstring << ","; } } gp << plotstring.str() << "\n"; // Daten senden for (std::vector<std::vector<std::vector<double> > >::iterator dat = data.begin(); dat != data.end(); ++dat) { gp.send1d(*dat); // TODO: end points ge connected... why? } std::cout << "Continue with Enter." << std::endl; std::cin.get(); }
int main(int argc, char **argv) { bool sys = 0, plot = 0; int mode = 0; double duration = 5, republish = 2; std::string config_file, out_file; Argo a; a.addSwitch('s', "system", sys,"Act as system"); a.addSwitch('p',"plot",plot,"Plot results"); a.addSwitch('V', "Verbose", verbose,"Verbose"); a.addDouble('d', "duration", duration,5.0,"Duration of the simulation"); a.addDouble('T',"period", Ts,0.02,"Period"); a.addDouble('r', "republish",republish, 0.0,"Republish output after this number of periods"); a.addInt('m',"mode",mode, 0,"Connection mode (0:TCP, 1:NOD, 2:UDP)"); a.addString('f', "config", config_file,std::string(getenv("HOME")) + std::string("/.rospacket/controller.yaml"),"Specify config file"); a.addString('o', "out-file",out_file, "rlc.dat","Specify output file"); a.process(argc, argv); ros::init(argc, argv, "controller", ros::init_options::AnonymousName); ros::NodeHandle n; std::cerr << "Reading config file " << config_file << std::endl; try{ YAML::Node config = YAML::LoadFile(config_file); if (YAML::Node parameter = config["T"]){ Ts = parameter.as<double>(); } if (YAML::Node parameter = config["R"]){ R = parameter.as<double>(); } if (YAML::Node parameter = config["L"]){ L = parameter.as<double>(); } if (YAML::Node parameter = config["C"]){ C = parameter.as<double>(); } if (YAML::Node parameter = config["K"]){ K = parameter.as<double>(); } if (YAML::Node parameter = config["size"]){ size = parameter.as<int>(); } if (YAML::Node parameter = config["mode"]){ mode = parameter.as<int>(); } std::cerr << "Done." << std::endl; }catch(YAML::ParserException &e){ std::cerr << "Bad file..."<< std::endl; exit(0); }catch(std::exception){ std::cerr << "No configuration file...done." << std::endl; } ros::TransportHints ti; if (mode == 2){ ti = ros::TransportHints().udp(); std::cerr << "Using UDP" << std::endl; }else if(mode == 1){ ti = ros::TransportHints().tcpNoDelay(); std::cerr << "Using NOD" << std::endl; }else{ ti = ros::TransportHints().tcp(); std::cerr << "Using TCP" << std::endl; } if (sys){ std::cerr << "Acting as system" << std::endl; sub = n.subscribe("u", queue_size, command_callback, ti); pub = n.advertise<ros_profiling_msgs::Controller>("y", queue_size); fd = fopen(out_file.c_str(),"w+"); }else{ std::cerr << "Acting as controller" << std::endl; sub = n.subscribe("y", queue_size, output_callback, ti); pub = n.advertise<ros_profiling_msgs::Controller>("u", queue_size); } ros_profiling_msgs::Controller ctrl; ctrl.data.resize(size); ctrl.u = ctrl.y = 0; ctrl.serial = 1; double begin = now(); bool finished = false; while (ros::ok()){ if (sys){ if (feedback){ if (republish>1.0 && now() - last > republish*Ts){ std::cerr << "Got Stuck -> republishing 'y'" << std::endl; pub.publish(last_published); last = now(); // command_callback(last_ctrl); } }else{ if (now() - begin > 1.0){ pub.publish(ctrl); begin = now(); } } if (elapsed(begin) > duration) { finished = true; break; } } ros::spinOnce(); usleep(1000); } if (sys){ fclose(fd); } if (!plot || !finished){ exit(0); } std::cerr << "Simulating ("<< duration << " seconds)" << std::endl; simulate(duration); std::cerr << "Done." << std::endl; if (sys){ Gnuplot gp; gp << "plot '-' with lines title 'Raw','-' with lines title 'Adjusted','-' with lines title 'Local'\n"; gp.send1d(data1); gp.send1d(data2); gp.send1d(data3); } return 0; }
graphError::graphError(std::string _filename, int setGeneracion, int numberGeneration, int _nodos, int _noAnclas, double _max) { nodos = _nodos; filename = _filename; noAnclas = _noAnclas; int margen = 3; if (_max>25) margen=6; //Cargar posiciones cargar_unknow(); //Ejecucion de comandos en el shell std::string archivo2=filename+std::to_string(setGeneracion)+ext; std::string s="cp "+archivo2+" ContarLineas.sav"; char *comando = strdup(s.c_str()); system(comando); system("sed -i '1,2d' *.sav"); for(int k=setGeneracion;k<numberGeneration+1;k+=setGeneracion){ archivo=filename+std::to_string(k)+ext; //Define el nombre del archivo que guarda la poblacion filas = contador_filas(); //Se debe cambiar el nombre del archivo desde el cual se contaran las lineas cargar_poblacion(archivo); ordenar_matriz(); mejor_individuo(); //Graficar Gnuplot gp; std::vector<std::vector<std::pair<double, double> > > all_segments; std::vector<std::pair<double, double> > xy_pts_anclas; std::vector<std::pair<double, double> > xy_pts_unknow; //Grafica los segmentos (Error) int contador=0; //Contador para segmentos for(int j=0; j<nodos-noAnclas; j++) { std::vector<std::pair<double, double> > segment; for(int i=0; i<1; i++) { segment.push_back(std::make_pair(unknowX[contador], unknowY[contador])); segment.push_back(std::make_pair(individuoX[contador], individuoY[contador])); contador++; } all_segments.push_back(segment); } //Grafica los puntos for(int i=0; i<noAnclas; i++) xy_pts_anclas.push_back(std::make_pair(anclasX[i], anclasY[i])); for(int i=0; i<nodos-noAnclas; i++) xy_pts_unknow.push_back(std::make_pair(unknowX[i], unknowY[i])); gp << "set yrange [0:"<<_max+margen<<"]\n"; //gp << "set autoscale\n"; gp << "set title 'GeneraciĆ³n "<<std::to_string(k)<<"' font 'Bookman,20'\n"; gp << "set encoding iso_8859_1\n"; //Define los acentos para postscript gp << "set grid\n"; gp << "set xlabel 'metros'\n"; gp << "set ylabel 'metros'\n"; gp << "set key font 'Helvetica,18'\n";//Modifica la leyenda gp << "set terminal postscript enhanced color font 'Helvetica,15'\n";//Cambia de terminal gp << "set output '| ps2pdf - Generacion_"<<std::to_string(k)<<".pdf'\n";//guarda en pdf gp << "set style line 1 lc rgb '#00DD00' pt 7 ps 1.5 \n"; gp << "set style line 2 lc rgb 'blue' pt 6 ps 1.5 \n"; gp << "plot '-' with line title 'Error', '-' with points ls 1 title 'Nodos Anclas'," << "'-' with points ls 2 title 'PosiciĆ³n Real'\n"; //<< "'-' with vectors title 'pts_B'\n"; gp.send2d(all_segments); gp.send1d(xy_pts_anclas); gp.send1d(xy_pts_unknow); } }